]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blobdiff - src/forb/src/executor.c
forb: Update documentation of forb_executor_run()
[frescor/frsh-forb.git] / src / forb / src / executor.c
index 55c240f4be65ba3ff7f63c77883fc87e047ca4bb..c480b53df3a1423116006b9bbe86ca0a1bc1fc99 100644 (file)
@@ -88,6 +88,9 @@ int forb_executor_init(forb_executor_t *executor)
        forb_exec_req_nolock_init_head(executor);
        
        forb_syncobj_init(&executor->reply_processed, 0);
+
+       executor->finish = false;
+       fosa_cond_init(&executor->finished);
        return 0;
 }
 
@@ -96,6 +99,21 @@ void forb_executor_destroy(forb_executor_t *executor)
        /* TODO: */
 }
 
+/** 
+ * Waits for the executor to finish processing requests.
+ * 
+ * @param executor 
+ */
+void forb_executor_synchronize(forb_executor_t *executor)
+{
+       fosa_mutex_lock(&executor->mutex);
+       executor->finish = true;
+       fosa_cond_signal(&executor->new_request_in_empty_list);
+       fosa_cond_wait(&executor->finished, &executor->mutex);
+       fosa_mutex_unlock(&executor->mutex);
+
+}
+
 /** 
  * Setup the object @a obj so that requests to it are executed within
  * the thread of the @a executor.
@@ -133,7 +151,8 @@ void forb_executor_unregister_object(forb_executor_t *executor, forb_object obj)
  *
  * 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()).
+ * ports (forb_iop_receiver_thread()) or directly by
+ * forb_iop_send_request().
  * 
  * @param executor 
  * 
@@ -150,8 +169,6 @@ int forb_executor_run(forb_executor_t *executor)
        
        fosa_mutex_lock(&executor->mutex);
        while (1) {
-               fosa_cond_wait(&executor->new_request_in_empty_list,
-                              &executor->mutex);
                while (!forb_exec_req_nolock_is_empty(executor)) {
                        forb_exec_req_t *exec_req;
                        exec_req = forb_exec_req_nolock_cut_first(executor);
@@ -161,6 +178,14 @@ int forb_executor_run(forb_executor_t *executor)
 
                        fosa_mutex_lock(&executor->mutex);
                }
+               if (executor->finish) {
+                       fosa_cond_broadcast(&executor->finished);
+                       executor->finish = false;
+               }
+
+                       
+               fosa_cond_wait(&executor->new_request_in_empty_list,
+                              &executor->mutex);
        }
        fosa_mutex_unlock(&executor->mutex);
 ret: