1 /* 2 ** Copyright (C) 2007-2020 by Carnegie Mellon University. 3 ** 4 ** @OPENSOURCE_LICENSE_START@ 5 ** See license information in ../../LICENSE.txt 6 ** @OPENSOURCE_LICENSE_END@ 7 */ 8 9 /* 10 ** Create a version of sklog that works well in a multi-threaded 11 ** environment by creating a mutex and using it when logging. 12 ** 13 */ 14 15 16 #include <silk/silk.h> 17 18 RCSIDENT("$SiLK: sklog-thrd.c ef14e54179be 2020-04-14 21:57:45Z mthomas $"); 19 20 #include <silk/sklog.h> 21 22 23 /* Mutex for the log in the non-syslog case. */ 24 static pthread_mutex_t logmutex = PTHREAD_MUTEX_INITIALIZER; 25 26 27 int sklogEnableThreadedLogging(void)28sklogEnableThreadedLogging( 29 void) 30 { 31 /* Set the lock/unlock function pointers on the log and the mutex 32 * on which they operate. */ 33 return sklogSetLocking((sklog_lock_fn_t)&pthread_mutex_lock, 34 (sklog_lock_fn_t)&pthread_mutex_unlock, 35 (sklog_lock_fn_t)&pthread_mutex_trylock, 36 &logmutex); 37 } 38 39 40 /* 41 ** Local Variables: 42 ** mode:c 43 ** indent-tabs-mode:nil 44 ** c-basic-offset:4 45 ** End: 46 */ 47