From a48b0f59d291ef740f68e1087e051668c1c8beab Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Fri, 28 Jan 2011 17:04:37 +0100 Subject: [PATCH 1/1] Initialize thread specific data in forb_init() This was done to avoid race conditions which causes errors in code. Unfortunately this change does not help since FOSA is broken and we will better use plain POSIX here. --- src/executor.c | 28 +++++++++------------------- src/executor.h | 1 + src/forb.c | 2 ++ 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/executor.c b/src/executor.c index d7ea4ac..14977b6 100644 --- a/src/executor.c +++ b/src/executor.c @@ -61,7 +61,12 @@ extern UL_LOG_CUST(ulogd_forb_executor); -int forb_executor_key = -1; +static int forb_executor_key = -1; + +int forb_executor_prepare() +{ + return fosa_key_create(&forb_executor_key); +} /** * Initializes executor. @@ -135,27 +140,12 @@ void forb_executor_unregister_object(forb_executor_t *executor, forb_object obj) int forb_executor_run(forb_executor_t *executor) { int ret; - // for thread specific data testing -#ifdef DEBUG_EXECUTOR - forb_executor_t *executor_test; -#endif - - // initializing thread specific data (FIXME: maybe should be somewhere else) - if (forb_executor_key == -1) { - if ((ret = fosa_key_create(&forb_executor_key))) - goto ret; - } + // setting pointer to executor as thread specific data if ((ret = fosa_thread_set_specific_data(forb_executor_key, - fosa_thread_self(), executor))) + fosa_thread_self(), executor))) goto ret; - -#ifdef DEBUG_EXECUTOR - printf("Executor: current executor saved: %p\n", executor); - forb_get_current_executor(&executor_test); - printf("Executor: current executor loaded: %p\n", executor_test); -#endif - + fosa_mutex_lock(&executor->mutex); while (1) { fosa_cond_wait(&executor->new_request_in_empty_list, diff --git a/src/executor.h b/src/executor.h index 7007c7f..06dddcd 100644 --- a/src/executor.h +++ b/src/executor.h @@ -77,6 +77,7 @@ typedef struct forb_executor { } forb_executor_t; +int forb_executor_prepare(void); int forb_executor_init(forb_executor_t *executor); void forb_executor_destroy(forb_executor_t *executor); int forb_executor_register_object(forb_executor_t *executor, forb_object obj); diff --git a/src/forb.c b/src/forb.c index 2b31722..bd7c9a8 100644 --- a/src/forb.c +++ b/src/forb.c @@ -221,6 +221,8 @@ forb_init(int *argc, char **argv[], const struct forb_init_attr *attr) return NULL; } + forb_executor_prepare(); + orb = forb_forb_orb_new(NULL, &forb_implementation, forb); if (!orb) goto err2; /* Server ID must be assigned manualy */ -- 2.39.2