summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@intel.com>2016-04-21 18:57:18 +0800
committerJunyan He <junyan.he@intel.com>2016-04-21 18:57:18 +0800
commit677de86125364d11d012d6124108640d42d9266f (patch)
tree7fc6fd554e07c0585df07d9250ec4b55fb6209e5
parent2c2b38fa0cb61cdafe490129fe12938485af08ef (diff)
mutex check
-rw-r--r--libclapi/CMakeLists.txt2
-rw-r--r--libclapi/cl_mutex.c24
2 files changed, 23 insertions, 3 deletions
diff --git a/libclapi/CMakeLists.txt b/libclapi/CMakeLists.txt
index 4ec11279..79da0248 100644
--- a/libclapi/CMakeLists.txt
+++ b/libclapi/CMakeLists.txt
@@ -19,5 +19,5 @@ set(LIBCLAPI_SRC
)
add_library(clapi SHARED ${LIBCLAPI_SRC})
-target_link_libraries(clapi dl rt)
+target_link_libraries(clapi dl rt pthread)
install (TARGETS clapi LIBRARY DESTINATION ${BEIGNET_INSTALL_DIR})
diff --git a/libclapi/cl_mutex.c b/libclapi/cl_mutex.c
index b18990c2..f7540b5d 100644
--- a/libclapi/cl_mutex.c
+++ b/libclapi/cl_mutex.c
@@ -119,7 +119,7 @@ static void after_get_the_mutex(pthread_mutex_t* mutex, char* file, int line, in
pthread_mutex_unlock(&cl_mutex_log_lock);
}
-static void after_release_the_mutex(pthread_mutex_t* mutex)
+static void after_release_the_mutex(pthread_mutex_t* mutex, char* file, int line)
{
int i, j;
cl_mutex_log_item item = NULL;
@@ -133,7 +133,20 @@ static void after_release_the_mutex(pthread_mutex_t* mutex)
}
}
- assert(item);
+ if (item == NULL) {
+ printf("At unlock point file: %s, line: %d, we can not find the locked mutex:%p item, fatal\n",
+ file, line, mutex);
+ assert(0);
+ return;
+ }
+
+ if (item->holder.file == NULL) {
+ printf("At unlock point file: %s, line: %d, we can not find the locked mutex:%p info, fatal\n",
+ file, line, mutex);
+ assert(0);
+ return;
+ }
+
item->holder.file = NULL;
item->holder.line = 0;
@@ -177,3 +190,10 @@ LOCAL void cl_mutex_lock(pthread_mutex_t* mutex, char* file, int line)
after_get_the_mutex(mutex, file, line, nth);
}
+LOCAL void cl_mutex_unlock(pthread_mutex_t* mutex, char* file, int line)
+{
+ assert(mutex);
+ pthread_mutex_unlock(mutex);
+ after_release_the_mutex(mutex, file, line);
+}
+