#include "dautil.h"
#include "dahelper.h"
#include "dacollection.h"
+#include "da_sync.h"
#include "binproto.h"
probeBlockStart();
log->type = msgType;
- pthread_mutex_lock(&(gTraceInfo.socket.sockMutex));
+ real_pthread_mutex_lock(&(gTraceInfo.socket.sockMutex));
res = send(gTraceInfo.socket.daemonSock, log, sizeof(log->type) + sizeof(log->length) + log->length, 0);
- pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex));
+ real_pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex));
probeBlockEnd();
return true;
log.length = 0;
}
- pthread_mutex_lock(&(gTraceInfo.socket.sockMutex));
+ real_pthread_mutex_lock(&(gTraceInfo.socket.sockMutex));
res = send(gTraceInfo.socket.daemonSock, &log, sizeof(log.type) + sizeof(log.length) + log.length, MSG_DONTWAIT);
- pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex));
+ real_pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex));
probeBlockEnd();
probeBlockStart();
// atomic operaion(gcc builtin) is more expensive then pthread_mutex
- pthread_mutex_lock(&(gTraceInfo.index.eventMutex));
+ real_pthread_mutex_lock(&(gTraceInfo.index.eventMutex));
iProbe->eventIndex = gTraceInfo.index.eventIndex++;
- pthread_mutex_unlock(&(gTraceInfo.index.eventMutex));
+ real_pthread_mutex_unlock(&(gTraceInfo.index.eventMutex));
iProbe->currentTime = getCurrentTime();
iProbe->pID = getpid();
probeInfo_t probeInfo;
+ // unlock socket mutex to prevent deadlock
+ // in case of cancellation happened while log sending
+ real_pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex));
+
PRE_UNCONDITIONAL_BLOCK_BEGIN();
pSelf = pthread_self();
thread_routine_call *ptrc;
ptrc = (thread_routine_call *) params;
pthread_t pSelf;
+ int old_state;
+ int new_state = PTHREAD_CANCEL_DISABLE;
probeInfo_t probeInfo;
+ // disable cancellation to prevent deadlock
+ real_pthread_setcancelstate(new_state, &old_state);
+
PRE_UNCONDITIONAL_BLOCK_BEGIN();
pSelf = pthread_self();
PRE_UNCONDITIONAL_BLOCK_END();
+ // restore cancellation state
+ real_pthread_setcancelstate(old_state, NULL);
+
pthread_cleanup_push(_da_cleanup_handler, NULL);
// call user-defined thread routine
ret = ptrc->thread_routine(ptrc->argument);
pthread_cleanup_pop(0);
+ // disable cancellation to prevent deadlock
+ real_pthread_setcancelstate(new_state, &old_state);
+
PRE_UNCONDITIONAL_BLOCK_BEGIN();
pSelf = pthread_self();
return ret;
}
+int real_pthread_setcancelstate(int state, int *oldstate)
+{
+ static int (*pthread_setcancelstatep)(int state, int *oldstate);
+
+ GET_REAL_FUNC(pthread_setcancelstate, LIBPTHREAD);
+
+ return pthread_setcancelstatep(state, oldstate);
+}
+
int pthread_setcancelstate(int state, int *oldstate)
{
pthread_t pSelf;