summaryrefslogtreecommitdiffstats
path: root/srUtils.h
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-21 13:26:33 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-21 13:26:33 +0000
commit760dada7ebf216f2c326a8b25d31c5c8cf26f1f9 (patch)
tree26628c34d48991c0b11001eb99bdeae6af84ed37 /srUtils.h
parentc876b04da21a40e9cfe6588d89c15c226504d26e (diff)
downloadrsyslog-760dada7ebf216f2c326a8b25d31c5c8cf26f1f9.tar.gz
rsyslog-760dada7ebf216f2c326a8b25d31c5c8cf26f1f9.tar.xz
rsyslog-760dada7ebf216f2c326a8b25d31c5c8cf26f1f9.zip
added some mutex-support to srUtils
Diffstat (limited to 'srUtils.h')
-rwxr-xr-xsrUtils.h37
1 files changed, 36 insertions, 1 deletions
diff --git a/srUtils.h b/srUtils.h
index ec18e1a5..66af63d1 100755
--- a/srUtils.h
+++ b/srUtils.h
@@ -61,10 +61,45 @@ unsigned char *srUtilStrDup(unsigned char *pOld, size_t len);
* added 2007-07-17 by rgerhards
*/
int makeFileParentDirs(uchar *szFile, size_t lenFile, mode_t mode, uid_t uid, gid_t gid, int bFailOnChown);
-
int execProg(uchar *program, int wait, uchar *arg);
void skipWhiteSpace(uchar **pp);
rsRetVal genFileName(uchar **ppName, uchar *pDirName, size_t lenDirName, uchar *pFName,
size_t lenFName, long lNum, int lNumDigits);
int getNumberDigits(long lNum);
+rsRetVal timeoutComp(struct timespec *pt, int iTimeout);
+void mutexCancelCleanup(void *arg);
+
+/* mutex operations */
+/* some macros to cancel-safe lock a mutex (it will automatically be released
+ * when the thread is cancelled. This needs to be done as macros because
+ * pthread_cleanup_push sometimes is a macro that can not be used inside a function.
+ * It's a bit ugly, but works well... rgerhards, 2008-01-20
+ */
+#define DEFVARS_mutex_cancelsafeLock int iCancelStateSave
+#define mutex_cancelsafe_lock(mut) \
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &iCancelStateSave); \
+ d_pthread_mutex_lock(mut); \
+ pthread_cleanup_push(mutexCancelCleanup, mut); \
+ pthread_setcancelstate(iCancelStateSave, NULL);
+#define mutex_cancelsafe_unlock(mut) pthread_cleanup_pop(1)
+
+/* some useful constants */
+#define MUTEX_ALREADY_LOCKED 0
+#define LOCK_MUTEX 1
+#define DEFVARS_mutexProtection\
+ int iCancelStateSave; \
+ int bLockedOpIsLocked
+#define BEGIN_MTX_PROTECTED_OPERATIONS(mut, bMustLock) \
+ if(bMustLock == LOCK_MUTEX) { \
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &iCancelStateSave); \
+ d_pthread_mutex_lock(mut); \
+ bLockedOpIsLocked = 1; \
+ } else { \
+ bLockedOpIsLocked = 0; \
+ }
+#define END_MTX_PROTECTED_OPERATIONS(mut) \
+ if(bLockedOpIsLocked) { \
+ d_pthread_mutex_unlock(mut); \
+ pthread_setcancelstate(iCancelStateSave, NULL); \
+ }
#endif