]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
forb: Add support for synchronized initialization of multiple servers
authorMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 15 Feb 2011 15:24:32 +0000 (16:24 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 15 Feb 2011 16:17:34 +0000 (17:17 +0100)
This is needed in forbrun (future commit) to start multiple servers in a
single address space.

src/executor.c
src/forb-internal.h
src/forb.c
src/forb.h

index 7af1923975a17d4e479a24ddbbb21c66ae4f1816..55c240f4be65ba3ff7f63c77883fc87e047ca4bb 100644 (file)
@@ -169,6 +169,8 @@ ret:
 
 /** 
  * Convenience function for executing only one object in one executor.
+ * This function calls forb_signal_server_ready() at the appropriate
+ * place.
  * 
  * @param obj The object to execute.
  * 
@@ -183,6 +185,9 @@ int forb_execute_object(forb_object obj)
        if (ret) goto error;
        ret = forb_executor_register_object(&executor, obj);
        if (ret) goto destroy_and_error;
+
+       ret = forb_signal_server_ready(obj->orb);
+       if (ret) goto destroy_and_error;
        
        ret = forb_executor_run(&executor);
 
index 77f3f50028b3361bfe8b8c74e7f4428b066e5da8..a513d93b38b421dd87648d3a9a4a89256dcdb74e 100644 (file)
@@ -66,7 +66,7 @@
 #include <forb.h>
 #include <string.h>
 #include <forb/server_id.h>
-
+#include <semaphore.h>
 
 /**
  * Temporary directory for FORB's housekeeping.
@@ -89,6 +89,8 @@ typedef struct forb {
 
        forb_init_attr_t attr;  /**< Initialization attributes */
 
+       sem_t server_ready;     /**< Synchronize starting of multiple servers in a single address space. */
+
        fosa_mutex_t request_id_mutex;  /**< Mutex for request_id */
        CORBA_long request_id;  /**< Value of next sent request_id */
 
@@ -123,4 +125,7 @@ typedef void (*forb_skel_func)(FORB_CDR_Codec *cin,
 int
 forb_init_tmp_dir(void);
 
+int
+forb_wait_for_server_ready(forb_orb orb);
+
 #endif
index bd7c9a81f64b51163e90d943f8c918f8d21b3a97..63e51eb72979063cfb3fb02a4001d9dc6a97cee7 100644 (file)
@@ -194,6 +194,8 @@ forb_init(int *argc, char **argv[], const struct forb_init_attr *attr)
                memset(&forb->attr, 0, sizeof(forb->attr));
        }
 
+       sem_init(&forb->server_ready, 0, 0);
+
        if (forb_server_id_empty(&forb->attr.fixed_server_id)) {
                forb_server_id_init(&forb->server_id);
        } else {
@@ -567,3 +569,39 @@ static int init_ul_log(void)
 
        return 0;
 }
+
+/** 
+ * Wait for the server to be ready. Internal function intended forb
+ * forbrun.
+ * 
+ * @param orb ORB.
+ * 
+ * @return Zero on success; on error -1 is returned, and errno is set
+ * to indicate the error.
+ */
+int forb_wait_for_server_ready(forb_orb orb)
+{
+       forb_t *forb = forb_object_to_forb(orb);
+       return sem_wait(&forb->server_ready);
+}
+
+/** 
+ * Signal the the FORB core that the server is ready for accepting
+ * requests.
+ *
+ * This function should be called at the initialization of server
+ * implementation at the time when all objects are registered with
+ * executors. All other servers in the same address space are
+ * initialized after this function is called which allows the other
+ * servers to use the services provided by the calling server.
+ * 
+ * @param orb ORB object.
+ * 
+ * @return Zero on success; on error -1 is returned, and errno is set
+ * to indicate the error.
+ */
+int forb_signal_server_ready(forb_orb orb)
+{
+       forb_t *forb = forb_object_to_forb(orb);
+       return sem_post(&forb->server_ready);
+}
index f742d50e96451e2ef23943ec46fe7eb7a1eedb06..2e4a2c4623a79e0ee51cdf2cb98bdf7baa0bdcc4 100644 (file)
@@ -234,6 +234,8 @@ forb_daemon_prepare(const char *pid);
 void
 forb_daemon_ready();
 
+int
+forb_signal_server_ready();    
 
 #ifdef __cplusplus
 } /* extern "C"*/