parent
484b4ff024
commit
8fdb177c04
|
@ -7,10 +7,12 @@
|
|||
typedef struct _proc_t {
|
||||
pid_t proc;
|
||||
void *data;
|
||||
proc_start_t func;
|
||||
proc_func_t start_func;
|
||||
proc_func_t stop_func;
|
||||
status_t exitval;
|
||||
|
||||
semaphore_id semaphore;
|
||||
semaphore_id sem1;
|
||||
semaphore_id sem2;
|
||||
} proc_t;
|
||||
|
||||
#endif /* __CORE_ARCH_PROC_H__ */
|
||||
|
|
|
@ -11,12 +11,7 @@ extern "C" {
|
|||
/** Opaque Thread structure. */
|
||||
typedef c_uintptr_t proc_id;
|
||||
|
||||
typedef void *(PROC_FUNC *proc_start_t)(proc_id id, void*);
|
||||
|
||||
/**
|
||||
* Check if Thread Should Stop
|
||||
*/
|
||||
CORE_DECLARE(int) proc_should_stop(void);
|
||||
typedef void *(PROC_FUNC *proc_func_t)(proc_id id, void*);
|
||||
|
||||
/**
|
||||
* Initialize Thread
|
||||
|
@ -30,12 +25,10 @@ CORE_DECLARE(status_t) proc_final(void);
|
|||
|
||||
/**
|
||||
* Create a new proc of execution
|
||||
* @param id The newly created proc handle.
|
||||
* @param attr The procattr to use to determine how to create the proc
|
||||
* @param func The function to start the new proc in
|
||||
* @param data Any data to be passed to the starting function
|
||||
*/
|
||||
CORE_DECLARE(status_t) proc_create(proc_id *id, proc_start_t func, void *data);
|
||||
CORE_DECLARE(status_t) proc_create(proc_id *id,
|
||||
proc_func_t start_func, proc_func_t stop_func,
|
||||
void *data);
|
||||
|
||||
/**
|
||||
* Delete a new proc of execution
|
||||
|
|
|
@ -27,24 +27,9 @@ status_t proc_final(void)
|
|||
return CORE_OK;
|
||||
}
|
||||
|
||||
static void *dummy_worker(void *opaque)
|
||||
{
|
||||
void *func = NULL;
|
||||
proc_t *proc = (proc_t *)opaque;
|
||||
|
||||
proc->proc = getpid();
|
||||
semaphore_post(proc->semaphore);
|
||||
d_trace(3, "[%d] dummy_worker post semaphore for creating\n", proc->proc);
|
||||
|
||||
func = proc->func((proc_id)proc, proc->data);
|
||||
|
||||
semaphore_post(proc->semaphore);
|
||||
d_trace(3, "[%d] dummy_worker post semaphore for deleting\n", proc->proc);
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
status_t proc_create(proc_id *id, proc_start_t func, void *data)
|
||||
status_t proc_create(proc_id *id,
|
||||
proc_func_t start_func, proc_func_t stop_func,
|
||||
void *data)
|
||||
{
|
||||
proc_t *new = NULL;
|
||||
|
||||
|
@ -54,22 +39,42 @@ status_t proc_create(proc_id *id, proc_start_t func, void *data)
|
|||
memset(new, 0, sizeof(proc_id));
|
||||
|
||||
new->data = data;
|
||||
new->func = func;
|
||||
new->start_func = start_func;
|
||||
new->stop_func = stop_func;
|
||||
|
||||
semaphore_create(&new->semaphore, 0);
|
||||
semaphore_create(&new->sem1, 0);
|
||||
semaphore_create(&new->sem2, 0);
|
||||
|
||||
new->proc = fork();
|
||||
d_assert(new->proc >= 0, _exit(EXIT_FAILURE), "fork() failed");
|
||||
|
||||
if (new->proc == 0)
|
||||
{
|
||||
dummy_worker(new);
|
||||
new->proc = getpid();
|
||||
semaphore_post(new->sem1);
|
||||
d_trace(3, "[%d] post semaphore for starting\n", new->proc);
|
||||
|
||||
d_trace(3, "start func wait\n");
|
||||
new->start_func((proc_id)new, new->data);
|
||||
d_trace(3, "start func done\n");
|
||||
|
||||
d_trace(3, "deleting semaphore wait\n");
|
||||
semaphore_wait(new->sem2);
|
||||
semaphore_delete(new->sem2);
|
||||
d_trace(3, "deleting semaphore done\n");
|
||||
|
||||
d_trace(3, "stop func wait\n");
|
||||
new->stop_func(new->proc, new->data);
|
||||
d_trace(3, "stop func done\n");
|
||||
|
||||
semaphore_post(new->sem1);
|
||||
d_trace(3, "[%d] post semaphore to finish deleting\n", new->proc);
|
||||
|
||||
_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
d_trace(3, "proc_create wait\n");
|
||||
semaphore_wait(new->semaphore);
|
||||
semaphore_wait(new->sem1);
|
||||
d_trace(3, "proc_create done\n");
|
||||
|
||||
*id = (proc_id)new;
|
||||
|
@ -81,15 +86,18 @@ status_t proc_delete(proc_id id)
|
|||
{
|
||||
proc_t *proc = (proc_t *)id;
|
||||
|
||||
semaphore_post(proc->sem2);
|
||||
d_trace(3, "[%d] post semaphore to start deleting\n", proc->proc);
|
||||
|
||||
d_trace(3, "core_kill for %d\n", proc->proc);
|
||||
core_kill(proc->proc, SIGTERM);
|
||||
d_trace(3, "core_kill done for %d\n", proc->proc);
|
||||
|
||||
d_trace(3, "proc_delete wait\n");
|
||||
semaphore_wait(proc->semaphore);
|
||||
semaphore_wait(proc->sem1);
|
||||
d_trace(3, "proc_delete done\n");
|
||||
|
||||
semaphore_delete(proc->semaphore);
|
||||
semaphore_delete(proc->sem1);
|
||||
pool_free_node(&proc_pool, proc);
|
||||
d_trace(3, "delete proc-related memory\n");
|
||||
|
||||
|
|
62
src/epc.c
62
src/epc.c
|
@ -9,16 +9,16 @@
|
|||
#include "app.h"
|
||||
|
||||
static proc_id pgw_proc;
|
||||
static semaphore_id pgw_sem;
|
||||
static void *PROC_FUNC pgw_main(proc_id id, void *data);
|
||||
static void *PROC_FUNC pgw_start_func(proc_id id, void *data);
|
||||
static void *PROC_FUNC pgw_stop_func(proc_id id, void *data);
|
||||
|
||||
static proc_id sgw_proc;
|
||||
static semaphore_id sgw_sem;
|
||||
static void *PROC_FUNC sgw_main(proc_id id, void *data);
|
||||
static void *PROC_FUNC sgw_start_func(proc_id id, void *data);
|
||||
static void *PROC_FUNC sgw_stop_func(proc_id id, void *data);
|
||||
|
||||
static proc_id hss_proc;
|
||||
static semaphore_id hss_sem;
|
||||
static void *PROC_FUNC hss_main(proc_id id, void *data);
|
||||
static void *PROC_FUNC hss_start_func(proc_id id, void *data);
|
||||
static void *PROC_FUNC hss_stop_func(proc_id id, void *data);
|
||||
|
||||
status_t app_initialize(char *config_path, char *log_path)
|
||||
{
|
||||
|
@ -34,19 +34,13 @@ status_t app_initialize(char *config_path, char *log_path)
|
|||
d_trace_level(&_epc_main, others);
|
||||
}
|
||||
|
||||
d_assert(semaphore_create(&pgw_sem, 0) == CORE_OK,
|
||||
return CORE_ERROR, "semaphore_create() failed");
|
||||
rv = proc_create(&pgw_proc, pgw_main, NULL);
|
||||
rv = proc_create(&pgw_proc, pgw_start_func, pgw_stop_func, NULL);
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
d_assert(semaphore_create(&sgw_sem, 0) == CORE_OK,
|
||||
return CORE_ERROR, "semaphore_create() failed");
|
||||
rv = proc_create(&sgw_proc, sgw_main, NULL);
|
||||
rv = proc_create(&sgw_proc, sgw_start_func, sgw_stop_func, NULL);
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
d_assert(semaphore_create(&hss_sem, 0) == CORE_OK,
|
||||
return CORE_ERROR, "semaphore_create() failed");
|
||||
rv = proc_create(&hss_proc, hss_main, NULL);
|
||||
rv = proc_create(&hss_proc, hss_start_func, hss_stop_func, NULL);
|
||||
if (rv != CORE_OK) return rv;
|
||||
|
||||
d_trace(1, "MME try to initialize\n");
|
||||
|
@ -67,22 +61,14 @@ void app_terminate(void)
|
|||
mme_terminate();
|
||||
d_trace(1, "MME terminate...done\n");
|
||||
|
||||
d_assert(semaphore_post(hss_sem) == CORE_OK,,
|
||||
"semaphore_post() failed");
|
||||
proc_delete(hss_proc);
|
||||
|
||||
d_assert(semaphore_post(sgw_sem) == CORE_OK,,
|
||||
"semaphore_post() failed");
|
||||
proc_delete(sgw_proc);
|
||||
|
||||
d_assert(semaphore_post(pgw_sem) == CORE_OK,,
|
||||
"semaphore_post() failed");
|
||||
proc_delete(pgw_proc);
|
||||
|
||||
app_did_terminate();
|
||||
}
|
||||
|
||||
static void *PROC_FUNC pgw_main(proc_id id, void *data)
|
||||
static void *PROC_FUNC pgw_start_func(proc_id id, void *data)
|
||||
{
|
||||
status_t rv;
|
||||
|
||||
|
@ -91,11 +77,11 @@ static void *PROC_FUNC pgw_main(proc_id id, void *data)
|
|||
if (rv != CORE_OK) return NULL;
|
||||
d_trace(1, "PGW initialize...done\n");
|
||||
|
||||
d_assert(semaphore_wait(pgw_sem) == CORE_OK, return NULL,
|
||||
"semaphore_wait() failed");
|
||||
d_assert(semaphore_delete(pgw_sem) == CORE_OK, return NULL,
|
||||
"semaphore_delete() failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PROC_FUNC pgw_stop_func(proc_id id, void *data)
|
||||
{
|
||||
d_trace(1, "PGW try to terminate\n");
|
||||
pgw_terminate();
|
||||
d_trace(1, "PGW terminate...done\n");
|
||||
|
@ -103,7 +89,7 @@ static void *PROC_FUNC pgw_main(proc_id id, void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *PROC_FUNC sgw_main(proc_id id, void *data)
|
||||
static void *PROC_FUNC sgw_start_func(proc_id id, void *data)
|
||||
{
|
||||
status_t rv;
|
||||
|
||||
|
@ -112,11 +98,11 @@ static void *PROC_FUNC sgw_main(proc_id id, void *data)
|
|||
if (rv != CORE_OK) return NULL;
|
||||
d_trace(1, "SGW initialize...done\n");
|
||||
|
||||
d_assert(semaphore_wait(sgw_sem) == CORE_OK, return NULL,
|
||||
"semaphore_wait() failed");
|
||||
d_assert(semaphore_delete(sgw_sem) == CORE_OK, return NULL,
|
||||
"semaphore_delete() failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PROC_FUNC sgw_stop_func(proc_id id, void *data)
|
||||
{
|
||||
d_trace(1, "SGW try to terminate\n");
|
||||
sgw_terminate();
|
||||
d_trace(1, "SGW terminate...done\n");
|
||||
|
@ -124,7 +110,7 @@ static void *PROC_FUNC sgw_main(proc_id id, void *data)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void *PROC_FUNC hss_main(proc_id id, void *data)
|
||||
static void *PROC_FUNC hss_start_func(proc_id id, void *data)
|
||||
{
|
||||
status_t rv;
|
||||
|
||||
|
@ -133,11 +119,11 @@ static void *PROC_FUNC hss_main(proc_id id, void *data)
|
|||
if (rv != CORE_OK) return NULL;
|
||||
d_trace(1, "HSS initialize...done\n");
|
||||
|
||||
d_assert(semaphore_wait(hss_sem) == CORE_OK, return NULL,
|
||||
"semaphore_wait() failed");
|
||||
d_assert(semaphore_delete(hss_sem) == CORE_OK, return NULL,
|
||||
"semaphore_delete() failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PROC_FUNC hss_stop_func(proc_id id, void *data)
|
||||
{
|
||||
d_trace(1, "HSS try to terminate\n");
|
||||
hss_terminate();
|
||||
d_trace(1, "HSS terminate...done\n");
|
||||
|
|
21
src/init.c
21
src/init.c
|
@ -13,8 +13,8 @@
|
|||
#include "app.h"
|
||||
|
||||
static proc_id logger_proc;
|
||||
static semaphore_id logger_sem;
|
||||
static void *PROC_FUNC logger_main(proc_id id, void *data);
|
||||
static void *PROC_FUNC logger_start_func(proc_id id, void *data);
|
||||
static void *PROC_FUNC logger_stop_func(proc_id id, void *data);
|
||||
static void check_signal(int signum);
|
||||
|
||||
status_t app_will_initialize(char *config_path, char *log_path)
|
||||
|
@ -41,9 +41,8 @@ status_t app_will_initialize(char *config_path, char *log_path)
|
|||
|
||||
if (context_self()->log_path)
|
||||
{
|
||||
d_assert(semaphore_create(&logger_sem, 0) == CORE_OK,
|
||||
return CORE_ERROR, "semaphore_create() failed");
|
||||
rv = proc_create(&logger_proc, logger_main, context_self()->log_path);
|
||||
rv = proc_create(&logger_proc,
|
||||
logger_start_func, logger_stop_func, context_self()->log_path);
|
||||
if (rv != CORE_OK) return rv;
|
||||
}
|
||||
|
||||
|
@ -69,15 +68,13 @@ void app_did_terminate(void)
|
|||
{
|
||||
if (context_self()->log_path)
|
||||
{
|
||||
d_assert(semaphore_post(logger_sem) == CORE_OK,,
|
||||
"semaphore_post() failed");
|
||||
proc_delete(logger_proc);
|
||||
}
|
||||
|
||||
context_final();
|
||||
}
|
||||
|
||||
static void *PROC_FUNC logger_main(proc_id id, void *data)
|
||||
static void *PROC_FUNC logger_start_func(proc_id id, void *data)
|
||||
{
|
||||
status_t rv;
|
||||
char *path = data;
|
||||
|
@ -93,11 +90,11 @@ static void *PROC_FUNC logger_main(proc_id id, void *data)
|
|||
rv = logger_start(path);
|
||||
if (rv != CORE_OK) return NULL;
|
||||
|
||||
d_assert(semaphore_wait(logger_sem) == CORE_OK, return NULL,
|
||||
"semaphore_wait() failed");
|
||||
d_assert(semaphore_delete(logger_sem) == CORE_OK, return NULL,
|
||||
"semaphore_delete() failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void *PROC_FUNC logger_stop_func(proc_id id, void *data)
|
||||
{
|
||||
d_trace(1, "LOGGER terminate...done\n");
|
||||
|
||||
return NULL;
|
||||
|
|
Loading…
Reference in New Issue