Commit cb2810e6 authored by Cedric Roux's avatar Cedric Roux

- Fix EFD_SEMAPHORE build issues

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4642 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 6e209dcd
......@@ -83,7 +83,7 @@ const int itti_debug_poll = 0;
/* Global message size */
#define MESSAGE_SIZE(mESSAGEiD) (sizeof(MessageHeader) + itti_desc.messages_info[mESSAGEiD].size)
#if !defined(EFD_SEMAPHORE)
#ifndef EFD_SEMAPHORE
# define KERNEL_VERSION_PRE_2_6_30 1
#endif
......@@ -116,7 +116,7 @@ typedef struct thread_desc_s {
uint16_t nb_events;
#if defined(KERNEL_VERSION_PRE_2_6_30)
uint64_t sem_counter;
eventfd_t sem_counter;
#endif
/* Array of events monitored by the task.
......@@ -392,7 +392,7 @@ int itti_send_msg_to_task(task_id_t destination_task_id, instance_t instance, Me
if (TASK_GET_PARENT_TASK_ID(destination_task_id) == TASK_UNKNOWN)
{
ssize_t write_ret;
uint64_t sem_counter = 1;
eventfd_t sem_counter = 1;
/* Call to write for an event fd must be of 8 bytes */
write_ret = write (itti_desc.threads[destination_thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
......@@ -534,8 +534,8 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
(itti_desc.threads[thread_id].events[i].data.fd == itti_desc.threads[thread_id].task_event_fd))
{
struct message_list_s *message = NULL;
uint64_t sem_counter;
ssize_t read_ret;
eventfd_t sem_counter;
ssize_t read_ret;
/* Read will always return 1 */
read_ret = read (itti_desc.threads[thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
......@@ -543,7 +543,7 @@ static inline void itti_receive_msg_internal_event_fd(task_id_t task_id, uint8_t
#if defined(KERNEL_VERSION_PRE_2_6_30)
/* Store the value of the semaphore counter */
itti_desc.tasks[task_id].sem_counter = sem_counter - 1;
itti_desc.threads[task_id].sem_counter = sem_counter - 1;
#endif
if (lfds611_queue_dequeue (itti_desc.tasks[task_id].message_queue, (void **) &message) == 0) {
......@@ -567,16 +567,18 @@ void itti_receive_msg(task_id_t task_id, MessageDef **received_msg)
#if defined(KERNEL_VERSION_PRE_2_6_30)
/* Store the value of the semaphore counter */
if (itti_desc.tasks[task_id].sem_counter > 0) {
if (itti_desc.threads[task_id].sem_counter > 0) {
struct message_list_s *message = NULL;
if (lfds611_queue_dequeue (itti_desc.tasks[task_id].message_queue, (void **) &message) == 0) {
/* No element in list -> this should not happen */
DevParam(task_id, itti_desc.tasks[task_id].sem_counter, 0);
DevParam(task_id, itti_desc.threads[task_id].sem_counter, 0);
}
DevAssert(message != NULL);
*received_msg = message->msg;
free (message);
itti_desc.tasks[task_id].sem_counter--;
itti_desc.threads[task_id].sem_counter--;
} else
#endif
itti_receive_msg_internal_event_fd(task_id, 0, received_msg);
......@@ -720,7 +722,7 @@ static void *itti_rt_relay_thread(void *arg)
if (pending_messages > 0)
{
ssize_t write_ret;
uint64_t sem_counter = pending_messages;
eventfd_t sem_counter = pending_messages;
/* Call to write for an event fd must be of 8 bytes */
write_ret = write (itti_desc.threads[thread_id].task_event_fd, &sem_counter, sizeof(sem_counter));
......
......@@ -78,6 +78,10 @@ static const int itti_dump_debug = 0;
while(0)
#endif
#ifndef EFD_SEMAPHORE
# define KERNEL_VERSION_PRE_2_6_30 1
#endif
/* Message sent is an intertask dump type */
#define ITTI_DUMP_MESSAGE_TYPE 0x1
#define ITTI_STATISTIC_MESSAGE_TYPE 0x2
......@@ -146,7 +150,7 @@ typedef struct {
} itti_statistic_message_t;
static itti_desc_t itti_dump_queue;
static FILE *dump_file;
static FILE *dump_file = NULL;
static int itti_dump_running = 1;
static int itti_dump_send_message(int sd, itti_dump_queue_item_t *message);
......@@ -283,8 +287,8 @@ static int itti_dump_enqueue_message(itti_dump_queue_item_t *new, uint32_t messa
__sync_fetch_and_add (&itti_dump_queue.messages_in_queue, 1);
#else
{
ssize_t write_ret;
uint64_t sem_counter = 1;
ssize_t write_ret;
eventfd_t sem_counter = 1;
/* Call to write for an event fd must be of 8 bytes */
write_ret = write(itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
......@@ -523,19 +527,21 @@ static void *itti_dump_socket(void *arg_p)
#ifndef RTAI
if (i == itti_dump_queue.event_fd) {
/* Notification of new element to dump from other tasks */
uint64_t sem_counter;
ssize_t read_ret;
eventfd_t sem_counter;
ssize_t read_ret;
/* Read will always return 1 */
/* Read will always return 1 for kernel versions > 2.6.30 */
read_ret = read (itti_dump_queue.event_fd, &sem_counter, sizeof(sem_counter));
if (read_ret < 0) {
ITTI_DUMP_ERROR("Failed read for semaphore: %s\n", strerror(errno));
pthread_exit(NULL);
}
DevCheck(read_ret == sizeof(sem_counter), read_ret, sizeof(sem_counter), 0);
#if defined(KERNEL_VERSION_PRE_2_6_30)
itti_dump_flush_ring_buffer(1);
#else
itti_dump_flush_ring_buffer(0);
#endif
ITTI_DUMP_DEBUG("Write element to file\n");
} else
#endif
......@@ -705,7 +711,11 @@ int itti_dump_init(const char * const messages_definition_xml, const char * cons
#ifdef RTAI
itti_dump_queue.messages_in_queue = 0;
#else
# if defined(KERNEL_VERSION_PRE_2_6_30)
itti_dump_queue.event_fd = eventfd(0, 0);
# else
itti_dump_queue.event_fd = eventfd(0, EFD_SEMAPHORE);
# endif
if (itti_dump_queue.event_fd == -1)
{
ITTI_DUMP_ERROR("eventfd failed: %s\n", strerror(errno));
......
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