summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunyan He <junyan.he@intel.com>2016-04-21 14:58:03 +0800
committerJunyan He <junyan.he@intel.com>2016-04-21 14:58:03 +0800
commit322ffb40ce887305f1a629464608f8542051eec0 (patch)
tree2e6e473972d321223226b9398ff991739ace28b0
parent2ec027d8188befaee3b37109afd20d5be5a2529e (diff)
mutex
-rw-r--r--libclapi/CMakeLists.txt1
-rw-r--r--libclapi/cl_mem.c2
-rw-r--r--libclapi/cl_mutex.c55
-rw-r--r--libclapi/cl_mutex.h50
4 files changed, 106 insertions, 2 deletions
diff --git a/libclapi/CMakeLists.txt b/libclapi/CMakeLists.txt
index cf37040a..4f644e7c 100644
--- a/libclapi/CMakeLists.txt
+++ b/libclapi/CMakeLists.txt
@@ -15,6 +15,7 @@ set(LIBCLAPI_SRC
cl_kernel.c
cl_extension.c
cl_event.c
+ cl_mutex.c
)
add_library(clapi SHARED ${LIBCLAPI_SRC})
diff --git a/libclapi/cl_mem.c b/libclapi/cl_mem.c
index 31a75f1a..14f20da7 100644
--- a/libclapi/cl_mem.c
+++ b/libclapi/cl_mem.c
@@ -629,10 +629,8 @@ static cl_int cl_enqueue_unmap_mem(cl_command_queue queue, cl_mem memobj, void *
CL_FREE(memobj->mapped_ptr);
memobj->mapped_ptr = new_ptr;
}
- pthread_mutex_unlock(&memobj->lock);
index = cl_context_get_device_index(queue->ctx, queue->device);
- pthread_mutex_lock(&memobj->lock);
memobj->enqueued_devices[index] = CL_TRUE;
pthread_mutex_unlock(&memobj->lock);
diff --git a/libclapi/cl_mutex.c b/libclapi/cl_mutex.c
new file mode 100644
index 00000000..e9502c7f
--- /dev/null
+++ b/libclapi/cl_mutex.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include <stdlib.h>
+#include <assert.h>
+#include <malloc.h>
+#include <pthread.h>
+#include <string.h>
+#include "cl_mutex.h"
+#include "cl_internals.h"
+
+static pthread_mutex_t cl_mutex_log_lock;
+static unsigned int cl_mutex_log_num;
+
+typedef struct _cl_mutex_log_item {
+ pthread_mutex_t* mutex;
+ char* file;
+ int line;
+} _cl_mutex_log_item;
+typedef struct _cl_mutex_log_item* cl_mutex_log_item;
+
+
+static int try_to_get_the_lock(pthread_mutex_t* mutex)
+{
+ struct timespec abs_time;
+ clock_gettime(CLOCK_REALTIME , &abs_time);
+ // so many seconds, still not get, we think deadlock happened.
+ abs_time.tv_sec += 25;
+ if (pthread_mutex_timedlock(mutex, &abs_time) != 0) {
+ return 0;
+ }
+ return 1;
+}
+
+LOCAL void cl_mutex_lock(pthread_mutex_t* mutex)
+{
+ assert(mutex);
+
+
+}
+
diff --git a/libclapi/cl_mutex.h b/libclapi/cl_mutex.h
new file mode 100644
index 00000000..fde52f30
--- /dev/null
+++ b/libclapi/cl_mutex.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia@intel.com>
+ */
+
+#ifndef __CL_ALLOC_H__
+#define __CL_ALLOC_H__
+
+#include <stdlib.h>
+
+/* Return a valid pointer for the requested memory block size */
+extern void* cl_malloc(size_t sz, char* file, int line);
+#define CL_MALLOC(SZ) cl_malloc(SZ, __FILE__, __LINE__)
+
+/* Aligned malloc */
+extern void* cl_aligned_malloc(size_t sz, size_t align, char* file, int line);
+#define CL_ALIGNED_MALLOC(SZ, ALIGN) cl_aligned_malloc(SZ, ALIGN, __FILE__, __LINE__)
+
+/* malloc + memzero */
+extern void* cl_calloc(size_t n, size_t elem_size, char* file, int line);
+#define CL_CALLOC(N, ELEM_SIZE) cl_calloc(N, ELEM_SIZE, __FILE__, __LINE__)
+
+/* Regular realloc */
+extern void* cl_realloc(void *ptr, size_t sz, char* file, int line);
+#define CL_REALLOC(PTR, SZ) cl_realloc(PTR, SZ, __FILE__, __LINE__)
+
+/* Free a pointer allocated with cl_*alloc */
+extern void cl_free(void *ptr, char* file, int line);
+#define CL_FREE(PTR) cl_free(PTR, __FILE__, __LINE__)
+
+/* We count the number of allocation. This function report the number of
+ * allocation still unfreed
+ */
+extern void cl_alloc_report_unfreed(void);
+extern void cl_alloc_debug_init(void);
+#endif /* __CL_ALLOC_H__ */