]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - src/executor.c
Fixed synchronization for codec buffer.
[frescor/forb.git] / src / executor.c
index d7ea4ac3d2516b3d6d8a8f40f2ba827792d6c82c..7e75eb8b33d8a0fe8b76faccfd13109343a106c3 100644 (file)
 #include "object.h"
 #include <ul_log.h>
 #include <stdio.h>
+#include <pthread.h>
 
 extern UL_LOG_CUST(ulogd_forb_executor);
 
-int forb_executor_key = -1;
+static pthread_key_t forb_executor_key = -1;
+
+int forb_executor_prepare()
+{
+       return pthread_key_create(&forb_executor_key, NULL);
+}
 
 /** 
  * Initializes executor.
@@ -80,6 +86,8 @@ int forb_executor_init(forb_executor_t *executor)
        if (ret) return ret;
 
        forb_exec_req_nolock_init_head(executor);
+       
+       forb_syncobj_init(&executor->reply_processed, 0);
        return 0;
 }
 
@@ -135,27 +143,11 @@ 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)))         
+       if ((ret = pthread_setspecific(forb_executor_key, 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,
@@ -210,11 +202,10 @@ error:
  */
 int forb_get_current_executor(forb_executor_t **executor)
 {
-       int ret;
-       ret = fosa_thread_get_specific_data(forb_executor_key, 
-                                           fosa_thread_self(), ((void *) executor));
+       int ret = 0;
+       *executor = (void *) pthread_getspecific(forb_executor_key);
                                            
-       if (ret)
-               *executor = NULL;
+       if (!(*executor))
+               ret = 1;
        return ret;
 }