]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Added thread specific data to executor
authorPetr Beneš <petr@petr-nb.(none)>
Sun, 17 Oct 2010 23:48:07 +0000 (01:48 +0200)
committerPetr Beneš <petr@petr-nb.(none)>
Sun, 17 Oct 2010 23:48:07 +0000 (01:48 +0200)
Edited executor.h and executor.c
Requires a testcase

src/executor.c
src/executor.h

index da1a4d70304f6df240c50c8f7b3e69ebe57bfeae..8c9229a3f78dc4473aefb8b98fb8cb30864dd980 100644 (file)
@@ -60,6 +60,8 @@
 
 extern UL_LOG_CUST(ulogd_forb_executor);
 
+int forb_executor_key = -1;
+
 /** 
  * Initializes executor.
  * 
@@ -131,6 +133,18 @@ void forb_executor_unregister_object(forb_executor_t *executor, forb_object obj)
  */
 int forb_executor_run(forb_executor_t *executor)
 {
+       int ret;
+       
+       // 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(), (void *) executor))         
+               goto ret;
+       
        fosa_mutex_lock(&executor->mutex);
        while (1) {
                fosa_cond_wait(&executor->new_request_in_empty_list,
@@ -146,7 +160,8 @@ int forb_executor_run(forb_executor_t *executor)
                }
        }
        fosa_mutex_unlock(&executor->mutex);
-       return 0;
+ret:   
+       return ret;
 }
 
 /** 
@@ -173,3 +188,19 @@ destroy_and_error:
 error:
        return ret;
 }
+
+
+/**
+ * Determines the executor we are currently in.
+ *
+ * @param executor Current executor.
+ *
+ * @return Zero in case of success.
+ */
+int forb_get_current_executor(forb_executor_t *executor)
+{
+       int ret;
+       ret = fosa_thread_get_specific_data(forb_executor_key, 
+                                           fosa_thread_self(), &executor);
+       return ret;
+}
index 0d08f4f4ff5455390e727bf3c27875ac297bc0ec..135d24e9d43d54e9078b961c98572bd5474de11a 100644 (file)
@@ -76,6 +76,7 @@ typedef struct forb_executor {
        ul_list_head_t requests; /**< List of pending requests for this executor. */
 } forb_executor_t;
 
+
 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);
@@ -83,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);
 
 #endif