瀏覽代碼

pass pthread_key_* through macros

Samuel Thibault 12 年之前
父節點
當前提交
7d2a5bd434
共有 4 個文件被更改,包括 47 次插入13 次删除
  1. 34 0
      src/common/utils.h
  2. 4 4
      src/core/task.c
  3. 4 4
      src/core/workers.c
  4. 5 5
      src/datawizard/memory_nodes.c

+ 34 - 0
src/common/utils.h

@@ -79,6 +79,40 @@ const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
 } while (0)
 } while (0)
 
 
 /*
 /*
+ * Encapsulation of the pthread_key_* functions.
+ */
+typedef pthread_key_t _starpu_pthread_key_t;
+#define _STARPU_PTHREAD_KEY_CREATE(key, destr) do {                            \
+	int p_ret = pthread_key_create((key), (destr));	                       \
+	if (STARPU_UNLIKELY(p_ret != 0)) {                                     \
+		fprintf(stderr,                                                \
+			"%s:%d pthread_key_create: %s\n",                      \
+			__FILE__, __LINE__, strerror(p_ret));                  \
+	}                                                                      \
+} while (0)
+
+#define _STARPU_PTHREAD_KEY_DELETE(key) do {                                   \
+	int p_ret = pthread_key_delete((key));	                               \
+	if (STARPU_UNLIKELY(p_ret != 0)) {                                     \
+		fprintf(stderr,                                                \
+			"%s:%d pthread_key_delete: %s\n",                      \
+			__FILE__, __LINE__, strerror(p_ret));                  \
+	}                                                                      \
+} while (0)
+
+#define _STARPU_PTHREAD_SETSPECIFIC(key, ptr) do {                             \
+	int p_ret = pthread_setspecific((key), (ptr));	                       \
+	if (STARPU_UNLIKELY(p_ret != 0)) {                                     \
+		fprintf(stderr,                                                \
+			"%s:%d pthread_setspecific: %s\n",                     \
+			__FILE__, __LINE__, strerror(p_ret));                  \
+	};                                                                     \
+	p_ret;                                                                 \
+} while (0)
+
+#define _STARPU_PTHREAD_GETSPECIFIC(key) pthread_getspecific((key))
+
+/*
  * Encapsulation of the pthread_mutex_* functions.
  * Encapsulation of the pthread_mutex_* functions.
  */
  */
 #define _STARPU_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
 #define _STARPU_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER

+ 4 - 4
src/core/task.c

@@ -42,7 +42,7 @@ static void _starpu_increment_nsubmitted_tasks(void);
  * cannot use the worker structure to store that information because it is
  * cannot use the worker structure to store that information because it is
  * possible that we have a task with a NULL codelet, which means its callback
  * possible that we have a task with a NULL codelet, which means its callback
  * could be executed by a user thread as well. */
  * could be executed by a user thread as well. */
-static pthread_key_t current_task_key;
+static _starpu_pthread_key_t current_task_key;
 
 
 void starpu_task_init(struct starpu_task *task)
 void starpu_task_init(struct starpu_task *task)
 {
 {
@@ -705,7 +705,7 @@ void _starpu_decrement_nready_tasks(void)
 
 
 void _starpu_initialize_current_task_key(void)
 void _starpu_initialize_current_task_key(void)
 {
 {
-	pthread_key_create(&current_task_key, NULL);
+	_STARPU_PTHREAD_KEY_CREATE(&current_task_key, NULL);
 }
 }
 
 
 /* Return the task currently executed by the worker, or NULL if this is called
 /* Return the task currently executed by the worker, or NULL if this is called
@@ -713,12 +713,12 @@ void _starpu_initialize_current_task_key(void)
  * being executed at the moment. */
  * being executed at the moment. */
 struct starpu_task *starpu_task_get_current(void)
 struct starpu_task *starpu_task_get_current(void)
 {
 {
-	return (struct starpu_task *) pthread_getspecific(current_task_key);
+	return (struct starpu_task *) _STARPU_PTHREAD_GETSPECIFIC(current_task_key);
 }
 }
 
 
 void _starpu_set_current_task(struct starpu_task *task)
 void _starpu_set_current_task(struct starpu_task *task)
 {
 {
-	pthread_setspecific(current_task_key, task);
+	_STARPU_PTHREAD_SETSPECIFIC(current_task_key, task);
 }
 }
 
 
 /*
 /*

+ 4 - 4
src/core/workers.c

@@ -42,7 +42,7 @@ static _starpu_pthread_cond_t init_cond = _STARPU_PTHREAD_COND_INITIALIZER;
 static int init_count = 0;
 static int init_count = 0;
 static enum { UNINITIALIZED, CHANGING, INITIALIZED } initialized = UNINITIALIZED;
 static enum { UNINITIALIZED, CHANGING, INITIALIZED } initialized = UNINITIALIZED;
 
 
-static pthread_key_t worker_key;
+static _starpu_pthread_key_t worker_key;
 
 
 static struct _starpu_machine_config config;
 static struct _starpu_machine_config config;
 
 
@@ -330,7 +330,7 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 	config->running = 1;
 	config->running = 1;
 	config->submitting = 1;
 	config->submitting = 1;
 
 
-	pthread_key_create(&worker_key, NULL);
+	_STARPU_PTHREAD_KEY_CREATE(&worker_key, NULL);
 
 
 	unsigned nworkers = config->topology.nworkers;
 	unsigned nworkers = config->topology.nworkers;
 
 
@@ -532,12 +532,12 @@ static void _starpu_launch_drivers(struct _starpu_machine_config *config)
 
 
 void _starpu_set_local_worker_key(struct _starpu_worker *worker)
 void _starpu_set_local_worker_key(struct _starpu_worker *worker)
 {
 {
-	pthread_setspecific(worker_key, worker);
+	_STARPU_PTHREAD_SETSPECIFIC(worker_key, worker);
 }
 }
 
 
 struct _starpu_worker *_starpu_get_local_worker_key(void)
 struct _starpu_worker *_starpu_get_local_worker_key(void)
 {
 {
-	return (struct _starpu_worker *) pthread_getspecific(worker_key);
+	return (struct _starpu_worker *) _STARPU_PTHREAD_GETSPECIFIC(worker_key);
 }
 }
 
 
 /* Initialize the starpu_conf with default values */
 /* Initialize the starpu_conf with default values */

+ 5 - 5
src/datawizard/memory_nodes.c

@@ -24,7 +24,7 @@
 #include "memalloc.h"
 #include "memalloc.h"
 
 
 static struct _starpu_mem_node_descr descr;
 static struct _starpu_mem_node_descr descr;
-static pthread_key_t memory_node_key;
+static _starpu_pthread_key_t memory_node_key;
 
 
 void _starpu_init_memory_nodes(void)
 void _starpu_init_memory_nodes(void)
 {
 {
@@ -32,7 +32,7 @@ void _starpu_init_memory_nodes(void)
 	 * added using _starpu_register_memory_node */
 	 * added using _starpu_register_memory_node */
 	descr.nnodes = 0;
 	descr.nnodes = 0;
 
 
-	pthread_key_create(&memory_node_key, NULL);
+	_STARPU_PTHREAD_KEY_CREATE(&memory_node_key, NULL);
 
 
 	unsigned i;
 	unsigned i;
 	for (i = 0; i < STARPU_MAXNODES; i++)
 	for (i = 0; i < STARPU_MAXNODES; i++)
@@ -53,18 +53,18 @@ void _starpu_deinit_memory_nodes(void)
 	_starpu_deinit_data_request_lists();
 	_starpu_deinit_data_request_lists();
 	_starpu_deinit_mem_chunk_lists();
 	_starpu_deinit_mem_chunk_lists();
 
 
-	pthread_key_delete(memory_node_key);
+	_STARPU_PTHREAD_KEY_DELETE(memory_node_key);
 }
 }
 
 
 void _starpu_set_local_memory_node_key(unsigned *node)
 void _starpu_set_local_memory_node_key(unsigned *node)
 {
 {
-	pthread_setspecific(memory_node_key, node);
+	_STARPU_PTHREAD_SETSPECIFIC(memory_node_key, node);
 }
 }
 
 
 unsigned _starpu_get_local_memory_node(void)
 unsigned _starpu_get_local_memory_node(void)
 {
 {
 	unsigned *memory_node;
 	unsigned *memory_node;
-	memory_node = (unsigned *) pthread_getspecific(memory_node_key);
+	memory_node = (unsigned *) _STARPU_PTHREAD_GETSPECIFIC(memory_node_key);
 
 
 	/* in case this is called by the programmer, we assume the RAM node
 	/* in case this is called by the programmer, we assume the RAM node
 	   is the appropriate memory node ... so we return 0 XXX */
 	   is the appropriate memory node ... so we return 0 XXX */