Commit f00c0363 authored by winckel's avatar winckel

added "itti_exit_task" to terminate current task when a MESSAGE_TERMINATE is received.

Modified "itti_wait_tasks_end" to exit when some threads are not terminated after a 1 second time-out.
modified "SIGINT" handling, exit is done after tring to join all threads like for "SIGUSR1".
Added message reception for TASK_L2L1 and handling of TEST and TERMINATE messages in oaisim.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4269 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 6570f9ef
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
*******************************************************************************/ *******************************************************************************/
#define _GNU_SOURCE
#include <pthread.h> #include <pthread.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -394,6 +395,10 @@ void itti_mark_task_ready(task_id_t task_id) { ...@@ -394,6 +395,10 @@ void itti_mark_task_ready(task_id_t task_id) {
pthread_mutex_unlock (&itti_desc.tasks[thread_id].message_queue_mutex); pthread_mutex_unlock (&itti_desc.tasks[thread_id].message_queue_mutex);
} }
void itti_exit_task(void) {
pthread_exit (NULL);
}
void itti_terminate_tasks(task_id_t task_id) { void itti_terminate_tasks(task_id_t task_id) {
// Sends Terminate signals to all tasks. // Sends Terminate signals to all tasks.
itti_send_terminate_message (task_id); itti_send_terminate_message (task_id);
...@@ -442,6 +447,9 @@ int itti_init(thread_id_t thread_max, MessagesIds messages_id_max, const char * ...@@ -442,6 +447,9 @@ int itti_init(thread_id_t thread_max, MessagesIds messages_id_max, const char *
void itti_wait_tasks_end(void) { void itti_wait_tasks_end(void) {
int end = 0; int end = 0;
int i; int i;
int ready_tasks;
int result;
int retries = 10;
itti_desc.thread_handling_signals = pthread_self (); itti_desc.thread_handling_signals = pthread_self ();
...@@ -450,14 +458,35 @@ void itti_wait_tasks_end(void) { ...@@ -450,14 +458,35 @@ void itti_wait_tasks_end(void) {
signal_handle (&end); signal_handle (&end);
} }
for (i = THREAD_FIRST; i < itti_desc.thread_max; i++) { do {
/* Skip tasks which are not running */ ready_tasks = 0;
if (itti_desc.tasks[i].task_state == TASK_STATE_READY) {
ITTI_DEBUG("Waiting end of thread %s\n", itti_desc.threads_name[i]); for (i = THREAD_FIRST; i < itti_desc.thread_max; i++) {
/* Skip tasks which are not running */
if (itti_desc.tasks[i].task_state == TASK_STATE_READY) {
pthread_join (itti_desc.tasks[i].task_thread, NULL); result = pthread_tryjoin_np (itti_desc.tasks[i].task_thread, NULL);
itti_desc.tasks[i].task_state = TASK_STATE_ENDED;
ITTI_DEBUG("Thread %s join status %d\n", itti_desc.threads_name[i], result);
if (result == 0) {
/* Thread has terminated */
itti_desc.tasks[i].task_state = TASK_STATE_ENDED;
}
else {
/* Thread is still running, count it */
ready_tasks++;
}
}
}
if (ready_tasks > 0) {
usleep (100 * 1000);
} }
} while ((ready_tasks > 0) && (retries--));
if (ready_tasks > 0) {
ITTI_DEBUG("Some threads are still running, force exit\n");
exit (0);
} }
} }
......
...@@ -120,6 +120,10 @@ int itti_create_task(task_id_t task_id, ...@@ -120,6 +120,10 @@ int itti_create_task(task_id_t task_id,
**/ **/
void itti_mark_task_ready(task_id_t task_id); void itti_mark_task_ready(task_id_t task_id);
/** \brief Exit the current task.
**/
void itti_exit_task(void);
/** \brief Indicate that the task is completed and initiate termination of all tasks. /** \brief Indicate that the task is completed and initiate termination of all tasks.
* \param task_id task that is completed * \param task_id task that is completed
**/ **/
......
...@@ -60,6 +60,7 @@ int signal_init(void) ...@@ -60,6 +60,7 @@ int signal_init(void)
sigemptyset(&set); sigemptyset(&set);
sigaddset (&set, SIGTIMER); sigaddset (&set, SIGTIMER);
sigaddset (&set, SIGUSR1);
sigaddset (&set, SIGABRT); sigaddset (&set, SIGABRT);
sigaddset (&set, SIGSEGV); sigaddset (&set, SIGSEGV);
sigaddset (&set, SIGINT); sigaddset (&set, SIGINT);
...@@ -115,18 +116,19 @@ int signal_handle(int *end) ...@@ -115,18 +116,19 @@ int signal_handle(int *end)
printf("Received SIGUSR1\n"); printf("Received SIGUSR1\n");
*end = 1; *end = 1;
break; break;
case SIGSEGV: /* Fall through */ case SIGSEGV: /* Fall through */
case SIGABRT: case SIGABRT:
printf("Received SIGABORT\n"); printf("Received SIGABORT\n");
backtrace_handle_signal(&info); backtrace_handle_signal(&info);
break; break;
case SIGQUIT:
case SIGINT: case SIGINT:
printf("Received SIGINT\n"); printf("Received SIGINT\n");
itti_send_terminate_message(TASK_UNKNOWN); itti_send_terminate_message(TASK_UNKNOWN);
printf("All tasks terminated -> exiting '"PACKAGE_NAME"'\n"); *end = 1;
exit(0);
break; break;
default: default:
printf("Received unknown signal %d\n", info.si_signo); printf("Received unknown signal %d\n", info.si_signo);
break; break;
......
...@@ -376,14 +376,13 @@ void *l2l1_task(void *args_p) { ...@@ -376,14 +376,13 @@ void *l2l1_task(void *args_p) {
char fname[64], vname[64]; char fname[64], vname[64];
#if defined(ENABLE_ITTI) #if defined(ENABLE_ITTI)
MessageDef *message_p;
long timer_id; long timer_id;
itti_mark_task_ready(TASK_L2L1); itti_mark_task_ready(TASK_L2L1);
/* Test code */ /* Test code */
{ {
MessageDef *message_p;
message_p = itti_alloc_new_message(TASK_L2L1, MESSAGE_TEST); message_p = itti_alloc_new_message(TASK_L2L1, MESSAGE_TEST);
itti_send_msg_to_task(TASK_L2L1, INSTANCE_DEFAULT, message_p); itti_send_msg_to_task(TASK_L2L1, INSTANCE_DEFAULT, message_p);
...@@ -400,6 +399,31 @@ void *l2l1_task(void *args_p) { ...@@ -400,6 +399,31 @@ void *l2l1_task(void *args_p) {
#endif #endif
for (frame = 0; frame < oai_emulation.info.n_frames; frame++) { for (frame = 0; frame < oai_emulation.info.n_frames; frame++) {
#if defined(ENABLE_ITTI)
// Checks if a message has been sent to L2L1 task
itti_poll_msg(TASK_L2L1, INSTANCE_ALL, &message_p);
if(message_p != NULL)
{
switch(message_p->header.messageId)
{
case TERMINATE_MESSAGE:
itti_exit_task();
break;
case MESSAGE_TEST:
LOG_D(EMU, "Received %s\n", itti_get_message_name(message_p->header.messageId));
break;
default:
LOG_E(EMU, "Received unexpected message %s\n", itti_get_message_name(message_p->header.messageId));
break;
}
free(message_p);
}
#endif
/* /*
// Handling the cooperation Flag // Handling the cooperation Flag
if (cooperation_flag == 2) if (cooperation_flag == 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment