]> rtime.felk.cvut.cz Git - frescor/forb.git/blobdiff - src/executor.c
Fixed synchronization for codec buffer.
[frescor/forb.git] / src / executor.c
index d096e01396f81bebea76272ea1898a9b96df5281..7e75eb8b33d8a0fe8b76faccfd13109343a106c3 100644 (file)
 /* covered by the GNU Public License.                                    */
 /**************************************************************************/
 
+/**
+ * @file   executor.c
+ * @author Michal Sojka <sojkam1@fel.cvut.cz>
+ * @date   Sun Oct 12 16:18:04 2008
+ * 
+ * @brief  Implementation of executors.
+ */
+
+
 #include "executor.h"
 #include "exec_req.h"
 #include "object.h"
+#include <ul_log.h>
+#include <stdio.h>
+#include <pthread.h>
+
+extern UL_LOG_CUST(ulogd_forb_executor);
+
+static pthread_key_t forb_executor_key = -1;
+
+int forb_executor_prepare()
+{
+       return pthread_key_create(&forb_executor_key, NULL);
+}
 
+/** 
+ * Initializes executor.
+ * 
+ * @param executor 
+ * 
+ * @return Zero on success, FOSA error code on error.
+ */
 int forb_executor_init(forb_executor_t *executor)
 {
        int ret;
@@ -58,8 +86,11 @@ 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;
 }
+
 void forb_executor_destroy(forb_executor_t *executor)
 {
        /* TODO: */
@@ -84,14 +115,39 @@ int forb_executor_register_object(forb_executor_t *executor, forb_object obj)
 }
 
 /** 
- * Executor's main loop which processes requests.
+ * Unregisteres the object @a obj from @a executor.
+ * 
+ * @param executor
+ * @param obj 
+ */
+void forb_executor_unregister_object(forb_executor_t *executor, forb_object obj)
+{
+       if (obj) {
+               obj->executor = NULL;
+       }
+}
+
+/** 
+ * Executor's main loop which executes object implementation methods
+ * upon request.
+ *
+ * The requests are represented by ::forb_exec_req_t and are enqueued
+ * to the executor's request queue by receiver threads of individual
+ * ports (forb_iop_receiver_thread()).
  * 
  * @param executor 
  * 
- * @return Will be defined later.
+ * @return Zero on normal termination, non-zero error codes will be
+ * defined later.
  */
 int forb_executor_run(forb_executor_t *executor)
 {
+       int ret;
+
+       // setting pointer to executor as thread specific data
+       if ((ret = pthread_setspecific(forb_executor_key, executor)))           
+               goto ret;
+       
        fosa_mutex_lock(&executor->mutex);
        while (1) {
                fosa_cond_wait(&executor->new_request_in_empty_list,
@@ -107,7 +163,8 @@ int forb_executor_run(forb_executor_t *executor)
                }
        }
        fosa_mutex_unlock(&executor->mutex);
-       return 0;
+ret:   
+       return ret;
 }
 
 /** 
@@ -134,3 +191,21 @@ destroy_and_error:
 error:
        return ret;
 }
+
+
+/**
+ * Determines the executor we are currently in.
+ *
+ * @param executor Current executor pointer.
+ *
+ * @return Zero in case of success.
+ */
+int forb_get_current_executor(forb_executor_t **executor)
+{
+       int ret = 0;
+       *executor = (void *) pthread_getspecific(forb_executor_key);
+                                           
+       if (!(*executor))
+               ret = 1;
+       return ret;
+}