]> rtime.felk.cvut.cz Git - frescor/frsh.git/blobdiff - frsh_api/frsh_core.c
Destroy forb in the correct order
[frescor/frsh.git] / frsh_api / frsh_core.c
index f7199ddb4bd1767365151fae107eec3c7818d7ec..1e17525f152f9aced0f34833df4e2e46ece28f82 100644 (file)
@@ -62,7 +62,7 @@
 #include "frsh_forb.h"
 #include <frsh_resources.h>
 
-#ifdef FRSH_DISTRIBUTED_MODULE_SUPPORTED
+#if FRSH_DISTRIBUTED_MODULE_SUPPORTED
 #include <frsh_distributed.h>
 #endif
 
@@ -90,18 +90,21 @@ struct frsh_forb frsh_forb_global;
 
 static void *alloc_executor_thread(void *arg)
 {
-       return (void*)forb_executor_run(&frsh_forb_global.alloc_executor);
+       return (void*)(uintptr_t)forb_executor_run(&frsh_forb_global.alloc_executor);
 }
 
 
 int frsh_init()
 {
        int ret;
+       struct forb_init_attr attr = {
+               .orb_id = "org.frescor.frsh_app"
+       };
        
-       frsh_forb_global.orb = forb_init(NULL, NULL, "frsh");
+       frsh_forb_global.orb = forb_init(NULL, NULL, &attr);
        if (!frsh_forb_global.orb) {
-               if (errno) return errno;
-               else return -1;
+               ret = errno;
+               goto err;
        }
 
        frsh_forb_global.fcb = forb_resolve_reference(frsh_forb_global.orb,
@@ -115,8 +118,9 @@ int frsh_init()
        ret = forb_executor_init(&frsh_forb_global.alloc_executor);
        if (ret) goto err;
 
-       fra_registry_init(frsh_forb_global.orb, frsh_forb_global.fcb,
-                         &frsh_forb_global.alloc_executor);
+       ret = fra_registry_init(frsh_forb_global.orb, frsh_forb_global.fcb,
+                               &frsh_forb_global.alloc_executor);
+       if (ret) goto err;
        
 #ifdef CONFIG_AQUOSA
        ret = aqcpu_fra_init();
@@ -136,7 +140,7 @@ int frsh_init()
        if (ret) goto err;
 #endif
 
-#ifdef FRSH_DISTRIBUTED_MODULE_SUPPORTED
+#if FRSH_DISTRIBUTED_MODULE_SUPPORTED
        ret = frsh_distributed_init();
        if (ret) goto err;
 #endif
@@ -151,11 +155,35 @@ int frsh_init()
        
        return 0;
 err:
+       if (ret == -1) ret = errno;
        return ret;
 }
 
+void frsh_destroy()
+{
+       forb_destroy(frsh_forb_global.orb);
+       
+       pthread_cancel(frsh_forb_global.alloc_executor_thread.pthread_id);
+       pthread_join(frsh_forb_global.alloc_executor_thread.pthread_id, NULL);
+
+       /* TODO: Destroy all FRAs etc. */
+}
+
+
+
 bool frsh_config_is_admission_test_enabled()
 {
        return true;
 }
 
+frsh_resource_id_t frsh_get_local_cpu_id(void)
+{
+       long int ret =  FRSH_CPU_ID_DEFAULT;
+       if (getenv("FRSH_CPU_ID")) {
+               errno = 0;      /* See strtol(1) */
+               ret = strtol(getenv("FRSH_CPU_ID"), NULL, 10);
+               if (errno != 0)
+                       ret = FRSH_CPU_ID_DEFAULT;
+       }
+       return ret;
+}