Commit f505546d authored by jdelange's avatar jdelange

* src/po_hi_main.c

   src/po_hi_gqueue.c
   - Adapt init and gqueues mechanisms so that
     all local examples can run on WIN32



git-svn-id: https://tecsw.estec.esa.int/svn/taste/trunk/po-hi-c@4637 129961e7-ef38-4bb5-a8f7-c9a525a55882
parent 9274df75
......@@ -5,7 +5,7 @@
*
* For more informations, please visit http://ocarina.enst.fr
*
* Copyright (C) 2010-2011, European Space Agency (ESA).
* Copyright (C) 2010-2012, European Space Agency (ESA).
*/
#include <po_hi_config.h>
......@@ -74,6 +74,9 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
#elif defined (XENO_NATIVE)
RT_MUTEX __po_hi_gqueues_mutexes[__PO_HI_NB_TASKS];
RT_COND __po_hi_gqueues_conds[__PO_HI_NB_TASKS];
#elif defined (_WIN32)
HANDLE __po_hi_gqueues_events[__PO_HI_NB_TASKS];
CRITICAL_SECTION __po_hi_gqueues_cs[__PO_HI_NB_TASKS];
#endif
void __po_hi_gqueue_init (__po_hi_task_id id,
......@@ -117,10 +120,10 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
__po_hi_gqueues_first[id] = first;
__po_hi_gqueues_used_size[id] = used_size;
__po_hi_gqueues_offsets[id] = offsets;
__po_hi_gqueues_n_destinations[id] = n_dest;
__po_hi_gqueues_destinations[id] = destinations;
__po_hi_gqueues_total_fifo_size[id] = total_fifo_size;
__po_hi_gqueues_offsets[id] = offsets;
__po_hi_gqueues_n_destinations[id] = n_dest;
__po_hi_gqueues_destinations[id] = destinations;
__po_hi_gqueues_total_fifo_size[id] = total_fifo_size;
__po_hi_gqueues_queue_is_empty[id] = 1;
......@@ -166,6 +169,18 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
}
#endif
#ifdef _WIN32
__po_hi_gqueues_events[id] = CreateEvent (NULL, FALSE, FALSE, NULL);
if (__po_hi_gqueues_events[id] == NULL)
{
__PO_HI_DEBUG_WARNING("CreateEvent failed (%d)\n", GetLastError());
return;
}
InitializeCriticalSection (&__po_hi_gqueues_cs[id]);
#endif
off = 0;
for (tmp=0;tmp<nb_ports;tmp++)
......@@ -238,12 +253,6 @@ __po_hi_uint8_t __po_hi_gqueue_store_in (__po_hi_task_id id,
#elif defined (XENO_NATIVE)
rt_mutex_acquire (&__po_hi_gqueues_mutexes[id], TM_INFINITE);
#elif defined (RTEMS_PURE)
/*
ret = rtems_barrier_wait (__po_hi_gqueues_barriers[id], RTEMS_WAIT);
rtems_id __po_hi_gqueues_semaphores[__PO_HI_NB_TASKS];
rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
*/
__DEBUGMSG ("[GQUEUE] Try to obtain semaphore for queue of task %d\n", id);
ret = rtems_semaphore_obtain (__po_hi_gqueues_semaphores[id], RTEMS_WAIT, RTEMS_NO_TIMEOUT);
if (ret != RTEMS_SUCCESSFUL)
......@@ -252,6 +261,10 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
}
__DEBUGMSG ("[GQUEUE] Semaphore got (id=%d)\n", id);
#elif defined (_WIN32)
printf ("%s:%d enter critical section 1\n", __FILE__, __LINE__);
EnterCriticalSection(&__po_hi_gqueues_cs[id]);
printf ("%s:%d enter critical section 2\n", __FILE__, __LINE__);
#endif
if (__po_hi_gqueues_sizes[id][port] == __PO_HI_GQUEUE_FIFO_INDATA)
{
......@@ -274,6 +287,10 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
{
__PO_HI_DEBUG_CRITICAL ("[GQUEUE] Cannot release semaphore in __po_hi_gqueue_store_in()\n");
}
#elif defined (_WIN32)
printf ("%s:%d leave critical section\n", __FILE__, __LINE__);
LeaveCriticalSection(&__po_hi_gqueues_cs[id]);
printf ("%s:%d leave critical section\n", __FILE__, __LINE__);
#endif
__PO_HI_DEBUG_CRITICAL ("[GQUEUE] QUEUE FULL, task-id=%d, port=%d\n", id, port);
......@@ -310,6 +327,14 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
#elif defined (XENO_NATIVE)
rt_mutex_release (&__po_hi_gqueues_mutexes[id]);
rt_cond_broadcast (&__po_hi_gqueues_conds[id]);
#elif defined (_WIN32)
printf ("%s:%d leave critical section\n", __FILE__, __LINE__);
LeaveCriticalSection(&__po_hi_gqueues_cs[id]);
if (! SetEvent(__po_hi_gqueues_events[id]) )
{
__DEBUGMSG("SetEvent failed (%d)\n", GetLastError());
}
printf ("%s:%d leave critical section\n", __FILE__, __LINE__);
#elif defined (RTEMS_PURE)
ret = rtems_semaphore_release (__po_hi_gqueues_semaphores[id]);
if (ret != RTEMS_SUCCESSFUL)
......@@ -329,23 +354,24 @@ void __po_hi_gqueue_wait_for_incoming_event (__po_hi_task_id id,
rtems_status_code ret;
#endif
#ifdef _WIN32
DWORD ret;
#endif
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_mutex_lock (&__po_hi_gqueues_mutexes[id]);
#elif defined (XENO_NATIVE)
rt_mutex_acquire (&__po_hi_gqueues_mutexes[id], TM_INFINITE);
#elif defined (RTEMS_PURE)
/*
ret = rtems_barrier_wait (__po_hi_gqueues_barriers[id], RTEMS_WAIT);
rtems_id __po_hi_gqueues_semaphores[__PO_HI_NB_TASKS];
rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
*/
ret = rtems_semaphore_obtain (__po_hi_gqueues_semaphores[id], RTEMS_WAIT, RTEMS_NO_TIMEOUT);
if (ret != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("[GQUEUE] Cannot obtain semaphore in __po_hi_gqueue_store_in()\n");
}
#elif defined (_WIN32)
EnterCriticalSection(&__po_hi_gqueues_cs[id]);
#endif
while(__po_hi_gqueues_queue_is_empty[id] == 1)
......@@ -374,15 +400,28 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
{
__PO_HI_DEBUG_CRITICAL ("[GQUEUE] semaphore %d obtained\n", id);
}
#elif defined (_WIN32)
LeaveCriticalSection(&__po_hi_gqueues_cs[id]);
ret = WaitForSingleObject (__po_hi_gqueues_events[id], INFINITE);
if (ret == WAIT_FAILED)
{
__PO_HI_DEBUG_DEBUG ("[GQUEUE] Wait failed\n");
}
EnterCriticalSection(&__po_hi_gqueues_cs[id]);
#endif
__PO_HI_INSTRUMENTATION_VCD_WRITE("1t%d\n", id);
}
*port = __po_hi_gqueues_global_history[id][__po_hi_gqueues_global_history_offset[id]];
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_mutex_unlock (&__po_hi_gqueues_mutexes[id]);
#elif defined (XENO_NATIVE)
rt_mutex_release (&__po_hi_gqueues_mutexes[id]);
#elif defined (_WIN32)
LeaveCriticalSection(&__po_hi_gqueues_cs[id]);
#elif defined (RTEMS_PURE)
ret = rtems_semaphore_release (__po_hi_gqueues_semaphores[id]);
if (ret != RTEMS_SUCCESSFUL)
......@@ -416,6 +455,10 @@ int __po_hi_gqueue_get_value (__po_hi_task_id id,
rtems_status_code ret;
#endif
#ifdef _WIN32
DWORD ret;
#endif
ptr = &__po_hi_gqueues_most_recent_values[id][port];
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
......@@ -423,17 +466,13 @@ int __po_hi_gqueue_get_value (__po_hi_task_id id,
#elif defined (XENO_NATIVE)
rt_mutex_acquire (&__po_hi_gqueues_mutexes[id], TM_INFINITE);
#elif defined (RTEMS_PURE)
/*
ret = rtems_barrier_wait (__po_hi_gqueues_barriers[id], RTEMS_WAIT);
rtems_id __po_hi_gqueues_semaphores[__PO_HI_NB_TASKS];
rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
*/
ret = rtems_semaphore_obtain (__po_hi_gqueues_semaphores[id], RTEMS_WAIT, RTEMS_NO_TIMEOUT);
if (ret != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("[GQUEUE] Cannot obtain semaphore in __po_hi_gqueue_store_in()\n");
}
if (ret != RTEMS_SUCCESSFUL)
{
__DEBUGMSG ("[GQUEUE] Cannot obtain semaphore in __po_hi_gqueue_store_in()\n");
}
#elif defined (_WIN32)
EnterCriticalSection(&__po_hi_gqueues_cs[id]);
#endif
......@@ -452,6 +491,15 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
rt_cond_wait (&__po_hi_gqueues_conds[id], &__po_hi_gqueues_mutexes[id], TM_INFINITE);
#elif defined (RTEMS_PURE)
rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
#elif defined (_WIN32)
LeaveCriticalSection(&__po_hi_gqueues_cs[id]);
ret = WaitForSingleObject (__po_hi_gqueues_events[id], INFINITE);
if (ret == WAIT_FAILED)
{
__PO_HI_DEBUG_DEBUG ("[GQUEUE] Wait failed\n");
}
EnterCriticalSection(&__po_hi_gqueues_cs[id]);
#endif
}
}
......@@ -501,6 +549,8 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
{
__DEBUGMSG ("[GQUEUE] Cannot release semaphore in __po_hi_gqueue_store_in()\n");
}
#elif defined (_WIN32)
LeaveCriticalSection(&__po_hi_gqueues_cs[id]);
#endif
return 0;
......@@ -526,13 +576,9 @@ int __po_hi_gqueue_next_value (__po_hi_task_id id, __po_hi_local_port_t port)
pthread_mutex_lock (&__po_hi_gqueues_mutexes[id]);
#elif defined (XENO_NATIVE)
rt_mutex_acquire (&__po_hi_gqueues_mutexes[id], TM_INFINITE);
#elif defined (_WIN32)
EnterCriticalSection(&__po_hi_gqueues_cs[id]);
#elif defined (RTEMS_PURE)
/*
ret = rtems_barrier_wait (__po_hi_gqueues_barriers[id], RTEMS_WAIT);
rtems_id __po_hi_gqueues_semaphores[__PO_HI_NB_TASKS];
rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
*/
ret = rtems_semaphore_obtain (__po_hi_gqueues_semaphores[id], RTEMS_WAIT, RTEMS_NO_TIMEOUT);
if (ret != RTEMS_SUCCESSFUL)
{
......@@ -574,6 +620,8 @@ rtems_id __po_hi_gqueues_barriers[__PO_HI_NB_TASKS];
{
__DEBUGMSG ("[GQUEUE] Cannot release semaphore in __po_hi_gqueue_store_in()\n");
}
#elif defined (_WIN32)
LeaveCriticalSection(&__po_hi_gqueues_cs[id]);
#endif
return __PO_HI_SUCCESS;
......
......@@ -39,6 +39,11 @@ pthread_mutex_t mutex_init;
rtems_id __po_hi_main_initialization_barrier;
#endif
#ifdef _WIN32
CRITICAL_SECTION __po_hi_main_initialization_critical_section;
HANDLE __po_hi_main_initialization_event;
#endif
#if defined (XENO_NATIVE)
#include <native/cond.h>
#include <native/mutex.h>
......@@ -189,6 +194,11 @@ int __po_hi_initialize_early ()
}
#endif
#ifdef _WIN32
__po_hi_main_initialization_event = CreateEvent (NULL, FALSE, FALSE, NULL);
InitializeCriticalSection (&__po_hi_main_initialization_critical_section);
#endif
__po_hi_initialize_tasking ();
/* Initialize protected objects */
......@@ -311,6 +321,24 @@ int __po_hi_wait_initialization ()
__PO_HI_INSTRUMENTATION_VCD_INIT
return (__PO_HI_SUCCESS);
#elif defined (_WIN32)
EnterCriticalSection (&__po_hi_main_initialization_critical_section);
__po_hi_initialized_tasks++;
__DEBUGMSG ("[MAIN] %d task(s) initialized (total to init =%d)\n", __po_hi_initialized_tasks, __po_hi_nb_tasks_to_init);
while (__po_hi_initialized_tasks < __po_hi_nb_tasks_to_init)
{
LeaveCriticalSection (&__po_hi_main_initialization_critical_section);
WaitForSingleObject (__po_hi_main_initialization_event, INFINITE);
EnterCriticalSection (&__po_hi_main_initialization_critical_section);
}
SetEvent (__po_hi_main_initialization_event);
LeaveCriticalSection (&__po_hi_main_initialization_critical_section);
return (__PO_HI_SUCCESS);
#elif defined (RTEMS_PURE)
rtems_status_code ret;
......
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