summaryrefslogtreecommitdiff
path: root/libclapi/cl_mutex.c
diff options
context:
space:
mode:
Diffstat (limited to 'libclapi/cl_mutex.c')
-rw-r--r--libclapi/cl_mutex.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/libclapi/cl_mutex.c b/libclapi/cl_mutex.c
index e25022ba..adffacbc 100644
--- a/libclapi/cl_mutex.c
+++ b/libclapi/cl_mutex.c
@@ -184,6 +184,7 @@ static void before_release_the_mutex(pthread_mutex_t* mutex, char* file, int li
printf("At unlock point file: %s, line: %d, we can not find the locked mutex:%p item, fatal\n",
file, line, mutex);
assert(0);
+ pthread_mutex_unlock(&cl_mutex_log_lock);
return;
}
@@ -191,6 +192,7 @@ static void before_release_the_mutex(pthread_mutex_t* mutex, char* file, int li
printf("At unlock point file: %s, line: %d, we can not find the locked mutex:%p info, fatal\n",
file, line, mutex);
assert(0);
+ pthread_mutex_unlock(&cl_mutex_log_lock);
return;
}
@@ -219,6 +221,65 @@ static void before_release_the_mutex(pthread_mutex_t* mutex, char* file, int li
pthread_mutex_unlock(&cl_mutex_log_lock);
}
+static void before_destroy_mutex(pthread_mutex_t* mutex, char* file, int line)
+{
+ cl_mutex_log_item item = NULL;
+ int i;
+ int print_others;
+ pthread_t tid = pthread_self();
+
+ pthread_mutex_lock(&cl_mutex_log_lock);
+ for (i = 0; i < cl_mutex_log_map_size; i++) {
+ if (cl_mutex_log_map[i]->mutex == mutex) {
+ item = cl_mutex_log_map[i];
+ break;
+ }
+ }
+
+ if (item == NULL) {
+ pthread_mutex_unlock(&cl_mutex_log_lock);
+ return;
+ }
+
+ print_others = 1;
+ printf("When we destroy a mutex:%p at file: %s, line: %d, thread id is %d.\n",
+ mutex, file, line, (int)tid);
+
+ if (item->holder.file) {
+ printf(" The mutex is still held by: file: %s, line: %d, thread id is %d\n",
+ item->holder.file, item->holder.line, (int)item->holder.tid);
+ }
+
+ for (i = 0; i < 8; i++) {
+ if (item->waiter[i].file) {
+ if (print_others) {
+ print_others = 0;
+ printf(" There are other waiters:\n");
+ }
+
+ printf(" file: %s, line: %d, thread id: %d\n",
+ item->waiter[i].file, item->waiter[i].line, (int)item->waiter[i].tid);
+ }
+ }
+
+ print_others = 0;
+ for (i = 0; i < 8; i++) {
+ if (item->sleeper[i].file) {
+ if (print_others) {
+ print_others = 0;
+ printf(" There are other sleepers:\n");
+ }
+
+ printf(" file: %s, line: %d, thread id: %d, cond: %p\n",
+ item->sleeper[i].file, item->sleeper[i].line,
+ (int)item->sleeper[i].tid, item->sleeper[i].cond);
+ }
+ }
+
+ assert(0);
+ pthread_mutex_unlock(&cl_mutex_log_lock);
+}
+
static int before_sleep_on_the_mutex(pthread_cond_t* cond, pthread_mutex_t* mutex, char* file, int line)
{
int i;
@@ -238,6 +299,7 @@ static int before_sleep_on_the_mutex(pthread_cond_t* cond, pthread_mutex_t* mute
printf("At unlock point file: %s, line: %d, we can not find the locked mutex:%p item, fatal\n",
file, line, mutex);
assert(0);
+ pthread_mutex_unlock(&cl_mutex_log_lock);
return -1;
}
@@ -245,6 +307,7 @@ static int before_sleep_on_the_mutex(pthread_cond_t* cond, pthread_mutex_t* mute
printf("At unlock point file: %s, line: %d, we can not find the locked mutex:%p info, fatal\n",
file, line, mutex);
assert(0);
+ pthread_mutex_unlock(&cl_mutex_log_lock);
return -1;
}
@@ -350,6 +413,12 @@ static void handle_deadlock(pthread_mutex_t* mutex, char* file, int line)
pthread_mutex_unlock(&cl_mutex_log_lock);
}
+LOCAL void cl_mutex_destory(pthread_mutex_t* mutex, char* file, int line)
+{
+ before_destroy_mutex(mutex, file, line);
+ pthread_mutex_destroy(mutex);
+}
+
LOCAL void cl_mutex_lock(pthread_mutex_t* mutex, char* file, int line)
{
assert(mutex);