42 #ifdef NCBI_CXX_TOOLKIT
43 # if defined(NCBI_POSIX_THREADS)
45 # elif defined(NCBI_WIN32_THREADS)
46 # define WIN32_LEAN_AND_MEAN
70 && kStatusStr[status]);
81 #define kMT_LOCK_magic 0x7A96283F
84 #define MT_LOCK_VALID(lk) assert((lk)->count && (lk)->magic == kMT_LOCK_magic)
97 #if defined(NCBI_CXX_TOOLKIT) && defined(NCBI_THREADS)
99 # if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
100 # define NCBI_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER
101 # elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
102 # define NCBI_RECURSIVE_MUTEX_INIT PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
110 # if defined(NCBI_POSIX_THREADS)
112 static pthread_mutex_t sx_Mutex
113 # ifdef NCBI_RECURSIVE_MUTEX_INIT
114 = NCBI_RECURSIVE_MUTEX_INIT
118 # ifndef NCBI_RECURSIVE_MUTEX_INIT
119 static void* sx_Init = 0;
120 static int sx_Inited = 0;
122 pthread_mutexattr_t attr;
123 pthread_mutexattr_init(&attr);
124 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
125 pthread_mutex_init(&sx_Mutex, &attr);
126 pthread_mutexattr_destroy(&attr);
128 }
else while (!sx_Inited)
135 return pthread_mutex_lock (&sx_Mutex) == 0 ? 1 : 0;
137 return pthread_mutex_unlock (&sx_Mutex) == 0 ? 1 : 0;
140 return pthread_mutex_trylock(&sx_Mutex) == 0 ? 1 : 0;
144 # elif defined(NCBI_WIN32_THREADS)
146 static CRITICAL_SECTION sx_Crit;
147 static LONG sx_Init = 0;
148 static int sx_Inited = 0;
150 if (!InterlockedCompareExchange(&sx_Init, 1, 0)) {
151 InitializeCriticalSection(&sx_Crit);
153 }
else while (!sx_Inited)
159 EnterCriticalSection(&sx_Crit);
162 LeaveCriticalSection(&sx_Crit);
166 return TryEnterCriticalSection(&sx_Crit) ? 1 : 0;
173 static void* sx_Once = 0;
188 #if defined(NCBI_CXX_TOOLKIT) && defined(NCBI_THREADS)
272 #define kLOG_magic 0x3FB97156
275 #define LOG_VALID(lg) assert((lg)->count && (lg)->magic == kLOG_magic)
278 #define LOG_LOCK_WRITE(lg) verify(MT_LOCK_Do((lg)->lock, eMT_Lock) != 0)
279 #define LOG_LOCK_READ(lg) verify(MT_LOCK_Do((lg)->lock, eMT_LockRead) != 0)
280 #define LOG_UNLOCK(lg) verify(MT_LOCK_Do((lg)->lock, eMT_Unlock) != 0)
296 static const char* kPostSeverityStr[
eLOG_Fatal + 1] = {
307 ? kPostSeverityStr[level]
342 lg->cleanup(
lg->data);
403 lg->handler(
lg->data, mess);
433 const void* raw_data,
460 #define kREG_magic 0xA921BC08
463 #define REG_VALID(rg) assert((rg)->count && (rg)->magic == kREG_magic)
466 #define REG_LOCK_WRITE(rg) verify(MT_LOCK_Do((rg)->lock, eMT_Lock) != 0)
467 #define REG_LOCK_READ(rg) verify(MT_LOCK_Do((rg)->lock, eMT_LockRead) != 0)
468 #define REG_UNLOCK(rg) verify(MT_LOCK_Do((rg)->lock, eMT_Unlock) != 0)
572 const char* def_value)
575 if (!
value || value_size <= 0)
591 if ((rv < 0 || !*
value) && def_value && *def_value) {
592 size_t len = strlen(def_value);
593 if (
len >= value_size) {
594 len = value_size - 1;
600 return rv ?
value : 0;
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
static void cleanup(void)
int(* FREG_Set)(void *data, const char *section, const char *name, const char *value, EREG_Storage storage)
Registry setter callback.
ELOG_Level
Log severity level.
int MT_LOCK_DoInternal(MT_LOCK lk, EMT_Lock how)
MT_LOCK MT_LOCK_AddRef(MT_LOCK lk)
Increment internal reference count by 1, then return "lk".
EMT_Lock
Set the lock/unlock callback function and its data for MT critical section.
void(* FLOG_Handler)(void *data, const SLOG_Message *mess)
Log post callback.
const char * REG_Get(REG rg, const char *section, const char *name, char *value, size_t value_size, const char *def_value)
Copy the registry value stored in "section" under name "name" to buffer "value"; if the entry is foun...
REG REG_Delete(REG rg)
Decrement internal reference count by 1, and if it reaches 0, then call "rg->cleanup(rg->data)",...
EREG_Storage
Transient/Persistent storage.
REG REG_Create(void *data, FREG_Get get, FREG_Set set, FREG_Cleanup cleanup, MT_LOCK lock)
Create a new registry (with an internal reference count set to 1).
int(* FMT_LOCK_Handler)(void *data, EMT_Lock how)
MT locking callback (operates like a [recursive] mutex or RW-lock).
void REG_Reset(REG rg, void *data, FREG_Get get, FREG_Set set, FREG_Cleanup cleanup, int do_cleanup)
Reset the registry handle to use the new "data", "set", "get", and "cleanup".
LOG LOG_AddRef(LOG lg)
Increment internal reference count by 1, then return "lg".
void LOG_WriteInternal(LOG lg, const SLOG_Message *mess)
Write message (perhaps with raw data attached) to the log by calling "lg->handler(lg->data,...
const char * IO_StatusStr(EIO_Status status)
Get the text form of an enum status value.
LOG LOG_Create(void *data, FLOG_Handler handler, FLOG_Cleanup cleanup, MT_LOCK lock)
Create a new LOG (with an internal reference count set to 1).
void LOG_Write(LOG lg, int code, int subcode, ELOG_Level level, const char *module, const char *func, const char *file, int line, const char *message, const void *raw_data, size_t raw_size)
Upon having filled SLOG_Message data from parameters, write a message (perhaps with raw data attached...
MT_LOCK MT_LOCK_Delete(MT_LOCK lk)
Decrement internal reference count by 1, and if it reaches 0, then destroy the handle,...
void CORE_Msdelay(unsigned long ms)
Delay execution of the current thread by the specified number of milliseconds.
int(* FREG_Get)(void *data, const char *section, const char *name, char *value, size_t value_size)
Registry getter callback.
MT_LOCK MT_LOCK_Create(void *data, FMT_LOCK_Handler handler, FMT_LOCK_Cleanup cleanup)
Create a new MT lock (with an internal reference count set to 1).
#define EIO_N_STATUS
connection is / has been closed, EOF condition
LOG LOG_Reset(LOG lg, void *data, FLOG_Handler handler, FLOG_Cleanup cleanup)
Reset the "lg" to use the new "data", "handler" and "cleanup".
const char * LOG_LevelStr(ELOG_Level level)
Obtain verbal representation of an enum level value.
void(* FREG_Cleanup)(void *data)
Registry cleanup callback.
#define MT_LOCK_Do(lk, how)
Call "lk->handler(lk->data, how)".
REG REG_AddRef(REG rg)
Increment internal reference count by 1, then return "rg".
LOG LOG_Delete(LOG lg)
Decrement internal reference count by 1, and if it reaches 0, then call "lg->cleanup(lg->data)",...
void(* FMT_LOCK_Cleanup)(void *data)
MT lock cleanup callback.
void(* FLOG_Cleanup)(void *data)
Log cleanup callback.
int REG_Set(REG rg, const char *section, const char *name, const char *value, EREG_Storage storage)
Store the "value" into the registry section "section" under the key "name", and according to "storage...
@ eMT_Unlock
unlock critical section
@ eMT_Lock
lock critical section
@ eMT_LockRead
lock critical section for reading
@ eMT_TryLock
try to lock, return immediately
@ eMT_TryLockRead
try to lock for reading, return immediately
@ eIO_Success
everything is fine, no error occurred
unsigned int
A callback function used to compare two keys in a database.
static const CS_INT unused
const GenericPointer< typename T::ValueType > T2 value
char * strncpy0(char *s1, const char *s2, size_t n)
Copy not more than "n" characters from string "s2" into "s1", and return the result,...
#define MT_LOCK_VALID(lk)
#define LOG_LOCK_WRITE(lg)
#define REG_LOCK_READ(rg)
#define REG_LOCK_WRITE(rg)
static int s_CORE_MT_Lock_default_handler(void *unused, EMT_Lock action)
#define LOG_LOCK_READ(lg)
struct MT_LOCK_tag g_CORE_MT_Lock_default
#define CORE_Once(once)
Return non-zero (true) if "*once" had a value of NULL, and set the value to non-NULL regardless (best...
#define CORE_LOG(level, message)
static SLJIT_INLINE sljit_ins lg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
volatile unsigned int count
Message and miscellaneous data to pass to log post callback FLOG_Handler.