From 5cd886f484f6ced74a33fa1d8e17bbd73462195b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20Bene=C5=A1?= Date: Tue, 25 Jan 2011 17:08:54 +0100 Subject: [PATCH] Added a function forb_get_current_executor() --- src/executor.c | 28 +++++++++++++++++++++------- src/executor.h | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/executor.c b/src/executor.c index 8c9229a..d7ea4ac 100644 --- a/src/executor.c +++ b/src/executor.c @@ -57,6 +57,7 @@ #include "exec_req.h" #include "object.h" #include +#include extern UL_LOG_CUST(ulogd_forb_executor); @@ -134,17 +135,27 @@ 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)) + 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(), (void *) executor)) + if ((ret = fosa_thread_set_specific_data(forb_executor_key, + 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, @@ -193,14 +204,17 @@ error: /** * Determines the executor we are currently in. * - * @param executor Current executor. + * @param executor Current executor pointer. * * @return Zero in case of success. */ -int forb_get_current_executor(forb_executor_t *executor) +int forb_get_current_executor(forb_executor_t **executor) { int ret; ret = fosa_thread_get_specific_data(forb_executor_key, - fosa_thread_self(), &executor); + fosa_thread_self(), ((void *) executor)); + + if (ret) + *executor = NULL; return ret; } diff --git a/src/executor.h b/src/executor.h index 135d24e..7007c7f 100644 --- a/src/executor.h +++ b/src/executor.h @@ -84,6 +84,6 @@ void forb_executor_unregister_object(forb_executor_t *executor, forb_object obj) int forb_executor_run(forb_executor_t *executor); int forb_execute_object(forb_object obj); -int forb_get_current_executor(forb_executor_t *executor); +int forb_get_current_executor(forb_executor_t **executor); #endif -- 2.39.2