1 #ifndef OBJTOOLS__PUBSEQ_GATEWAY__CLIENT__IMPL__MISC__HPP
2 #define OBJTOOLS__PUBSEQ_GATEWAY__CLIENT__IMPL__MISC__HPP
35 #include <condition_variable>
55 template <
typename TType =
void>
62 template <
class... TArgs>
71 using clock = chrono::system_clock;
81 template <
typename T =
bool>
84 constexpr
auto kWait = chrono::milliseconds(100);
88 const auto max = clock::now() + kWait;
106 unsigned int nanoseconds;
109 const auto ns = chrono::duration_cast<clock::duration>(chrono::nanoseconds(nanoseconds));
110 return clock::from_time_t(seconds) + ns;
113 template <
class... TArgs>
118 if (!
x_CvWait(lock, forward<TArgs>(args)...))
return false;
153 template <
class TValue>
169 if (
auto locked = this->
GetLock()) {
170 if (!locked->empty()) {
171 value = move(locked->front());
197 template <
class TParam>
200 using TValue =
typename TParam::TValueType;
212 template <
typename T>
227 template <
typename T>
230 bool sourcing_complete;
231 typename TParam::EParamSource param_source;
232 TParam::GetDefault();
233 TParam::GetState(&sourcing_complete, ¶m_source);
235 if (sourcing_complete && (param_source == TParam::eSource_Default)) {
245 template <
class TDescription>
259 #define PSG_PARAM_VALUE_TYPE(section, name) SPSG_ParamValue<NCBI_PARAM_TYPE(section, name)>
261 #define PSG_PARAM_VALUE_DEF_ADJUST(type, section, name, default_value) \
262 NCBI_PARAM_DEF(type, section, name, default_value); \
264 typename SPSG_ParamValue<NCBI_PARAM_TYPE(section, name)>::TValue \
265 SPSG_ParamValue<NCBI_PARAM_TYPE(section, name)>::sm_Adjust(SPSG_ParamValue<NCBI_PARAM_TYPE(section, name)>::TValue value)
267 #define PSG_PARAM_VALUE_DEF_MIN(type, section, name, default_value, min_value) \
268 PSG_PARAM_VALUE_DEF_ADJUST(type, section, name, default_value) \
270 if (value >= min_value) return value; \
272 ERR_POST(Warning << "[" #section "] " #name " ('" << value << "')" \
273 " was increased to the minimum allowed value ('" #min_value "')"); \
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
bool IsInfinite(void) const
Check if the deadline is infinite.
void GetExpirationTime(time_t *sec, unsigned int *nanosec) const
Get the number of seconds and nanoseconds (since 1/1/1970).
@ eInfinite
Infinite deadline.
NCBI_PARAM_TYPE(PSG, throttle_by_connection_error_rate) TPSG_ThrottleThreshold
NCBI_PARAM_ENUM_DECL(EPSG_DebugPrintout, PSG, debug_printout)
typedef NCBI_PARAM_TYPE(PSG, rd_buf_size) TPSG_RdBufSize
NCBI_PARAM_DECL(unsigned, PSG, rd_buf_size)
NCBI_PARAM_TYPE(PSG, service) TPSG_Service
#define PSG_PARAM_VALUE_TYPE(section, name)
NCBI_PARAM_TYPE(PSG, throttle_relaxation_period) TPSG_ThrottlePeriod
chrono::system_clock::time_point time_point
Defines: CTimeFormat - storage class for time format.
const atomic_bool & Stopped() const
bool Pop(TValue &value, const CDeadline &deadline=CDeadline::eInfinite)
bool x_CvWait(unique_lock< mutex > &l)
void NotifyOne() volatile
bool x_WaitUntil(const volatile atomic< T > &a, const CDeadline &deadline, T v=false, bool rv=false)
SPSG_CV & GetThis() volatile
chrono::system_clock clock
bool x_Wait(TArgs &&... args)
static clock::time_point x_GetTP(const CDeadline &d)
void NotifyAll() volatile
bool x_CvWait(unique_lock< mutex > &l, const clock::time_point &t)
bool WaitUntil(TArgs &&... args) volatile
bool x_WaitUntil(const CDeadline &deadline)
static void SetDefault(const T &value)
SPSG_ParamValue(TValue value)
SPSG_ParamValue(function< TValue(TValue)> adjust)
SPSG_ParamValue(EGetDefault)
static TValue sm_Adjust(TValue value)
static TValue GetDefault()
static void SetDefault(const string &value)
static void SetDefaultImpl(const CParam< TDescription > &, const string &value)
typename TParam::TValueType TValue
static void SetImplicitDefault(const T &value)
SLock< deque< TValue > > GetLock()