Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
PolyORB-HI-C
Commits
59c8fac4
Commit
59c8fac4
authored
May 24, 2018
by
yoogx
Browse files
* Separate concurrency constructs from GQueue processing logic
For openaadl/ocarina#159
parent
74d5d911
Changes
9
Hide whitespace changes
Inline
Side-by-side
include/Makefile.am
View file @
59c8fac4
...
...
@@ -3,24 +3,16 @@ include $(top_srcdir)/Makefile.common
AUTOMAKE_OPTIONS
=
no-dependencies
SUBDIRS
=
drivers monitoring simulator
EXTRA_DIST
=
$(srcdir)
/po_hi_common.h
\
$(srcdir)
/po_hi_debug.h
\
$(srcdir)
/po_hi_marshallers.h
\
$(srcdir)
/po_hi_messages.h
\
$(srcdir)
/po_hi_protected.h
\
$(srcdir)
/po_hi_returns.h
\
$(srcdir)
/po_hi_gqueue.h
\
$(srcdir)
/po_hi_monitor.h
\
$(srcdir)
/po_hi_lua.h
\
$(srcdir)
/po_hi_storage.h
\
$(srcdir)
/po_hi_giop.h
\
$(srcdir)
/po_hi_utils.h
\
$(srcdir)
/po_hi_task.h
\
$(srcdir)
/po_hi_time.h
\
$(srcdir)
/po_hi_types.h
\
$(srcdir)
/po_hi_main.h
\
$(srcdir)
/po_hi_simulink.h
\
$(srcdir)
/po_hi_transport.h
EXTRA_DIST
=
$(srcdir)
/po_hi_common.h
$(srcdir)
/po_hi_debug.h
\
$(srcdir)
/po_hi_marshallers.h
$(srcdir)
/po_hi_messages.h
\
$(srcdir)
/po_hi_protected.h
$(srcdir)
/po_hi_returns.h
\
$(srcdir)
/po_hi_gqueue.h
$(srcdir)
/po_hi_monitor.h
\
$(srcdir)
/po_hi_lua.h
$(srcdir)
/po_hi_storage.h
\
$(srcdir)
/po_hi_giop.h
$(srcdir)
/po_hi_utils.h
\
$(srcdir)
/po_hi_task.h
$(srcdir)
/po_hi_time.h
\
$(srcdir)
/po_hi_types.h
$(srcdir)
/po_hi_main.h
\
$(srcdir)
/po_hi_simulink.h
$(srcdir)
/po_hi_transport.h
\
$(srcdir)
/po_hi_semaphore.h
CLEANFILES
=
*
~
...
...
include/po_hi_protected.h
View file @
59c8fac4
...
...
@@ -5,12 +5,13 @@
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-201
4
ESA & ISAE.
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-201
8
ESA & ISAE.
*/
#ifndef __PO_HI_PROTECTED_H__
#define __PO_HI_PROTECTED_H__
#include
<stdint.h>
#include
<deployment.h>
...
...
include/po_hi_returns.h
View file @
59c8fac4
...
...
@@ -5,7 +5,7 @@
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-201
4
ESA & ISAE.
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-201
8
ESA & ISAE.
*/
#ifndef __PO_HI_RETURNS_H__
...
...
@@ -38,6 +38,7 @@
#define __PO_HI_ERROR_TRANSPORT_SEND -55
#define __PO_HI_ERROR_PTHREAD_BARRIER -56
/* Errors related to the protected and semaphore API */
#define __PO_HI_ERROR_PROTECTED_LOCK -60
#define __PO_HI_ERROR_PROTECTED_UNLOCK -61
#define __PO_HI_ERROR_PROTECTED_CREATE -62
...
...
@@ -46,6 +47,10 @@
#define __PO_HI_ERROR_MUTEX_UNLOCK -61
#define __PO_HI_ERROR_MUTEX_CREATE -62
#define __PO_HI_ERROR_SEM_WAIT -60
#define __PO_HI_ERROR_SEM_RELEASE -61
#define __PO_HI_ERROR_SEM_CREATE -62
/* GIOP error code */
#define __PO_HI_GIOP_INVALID_SIZE -100
#define __PO_HI_GIOP_INVALID_VERSION -120
...
...
include/po_hi_semaphore.h
0 → 100644
View file @
59c8fac4
/*
* This is a part of PolyORB-HI-C distribution, a minimal
* middleware written for generated code from AADL models.
* You should use it with the Ocarina toolsuite.
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2018 ESA & ISAE.
*/
#ifndef __PO_HI_SEMAPHORE_H__
#define __PO_HI_SEMAPHORE_H__
#include
<po_hi_protected.h>
#include
<stdint.h>
#include
<deployment.h>
#include
<po_hi_gqueue.h>
//#define __PO_HI_PROTECTED_TYPE_REGULAR 0
//#define __PO_HI_PROTECTED_TYPE_PIP 1
//#define __PO_HI_PROTECTED_TYPE_PCP 2
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
#include
<stdlib.h>
#include
<stdint.h>
#include
<time.h>
#include
<pthread.h>
#include
<semaphore.h>
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
#include
<rtems.h>
#elif defined (XENO_NATIVE)
#include
<native/mutex.h>
#elif defined (_WIN32)
#include
<windows.h>
#endif
typedef
struct
{
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
//protocol and priority to add
__po_hi_mutex_t
mutex
;
pthread_cond_t
posix_condvar
;
pthread_condattr_t
posix_condattr
;
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
rtems_id
rtems_sem
;
rtems_id
rtems_barrier
;
#elif defined (XENO_NATIVE)
__po_hi_mutex_t
mutex
;
RT_COND
xeno_condvar
;
#elif defined (_WIN32)
HANDLE
win32_event
;
CRITICAL_SECTION
win32_criticalsection
;
#endif
}
__po_hi_sem_t
;
/** Basics functions on semaphores */
int
__po_hi_sem_init
(
__po_hi_sem_t
*
sem
,
const
__po_hi_mutex_protocol_t
protocol
,
const
int
priority
,
int
nb
);
int
__po_hi_sem_wait
(
__po_hi_sem_t
*
sem
);
int
__po_hi_sem_mutex_wait
(
__po_hi_sem_t
*
sem
);
int
__po_hi_sem_release
(
__po_hi_sem_t
*
sem
);
int
__po_hi_sem_mutex_release
(
__po_hi_sem_t
*
sem
);
/** Functions used to fill the __po_hi_gqueues_semaphores array */
int
__po_hi_sem_init_gqueue
(
__po_hi_sem_t
array
[
__PO_HI_NB_TASKS
],
__po_hi_task_id
id
);
int
__po_hi_sem_wait_gqueue
(
__po_hi_sem_t
array
[
__PO_HI_NB_TASKS
],
__po_hi_task_id
id
);
int
__po_hi_sem_mutex_wait_gqueue
(
__po_hi_sem_t
array
[
__PO_HI_NB_TASKS
],
__po_hi_task_id
id
);
int
__po_hi_sem_release_gqueue
(
__po_hi_sem_t
array
[
__PO_HI_NB_TASKS
],
__po_hi_task_id
id
);
int
__po_hi_sem_mutex_release_gqueue
(
__po_hi_sem_t
array
[
__PO_HI_NB_TASKS
],
__po_hi_task_id
id
);
#endif
/* __PO_HI_SEMAPHORE_H__ */
share/make/Makefile.common.in
View file @
59c8fac4
...
...
@@ -92,23 +92,17 @@ ifeq ($(NEED_TRANSPORT), yes)
PO_HI_OBJS
=
po_hi_task.o po_hi_time.o po_hi_protected.o
\
po_hi_main.o po_hi_messages.o po_hi_marshallers.o
\
po_hi_giop.o po_hi_utils.o po_hi_types.o po_hi_monitor.o
\
po_hi_storage.o po_hi_gqueue.o po_hi_driver_exarm.o
\
po_hi_driver_keyboard.o
\
po_hi_driver_exarm_ni_6071e_analog.o
\
po_hi_driver_exarm_ni_6071e_digital.o
\
po_hi_driver_usbbrick_spacewire.o
\
po_hi_driver_linux_serial.o
\
po_hi_driver_leon_serial.o
\
po_hi_driver_leon_eth.o
\
po_hi_driver_serial_common.o
\
po_hi_driver_sockets.o
\
po_hi_driver_rtems_ne2000.o
\
po_hi_driver_rasta_serial.o
\
po_hi_driver_rasta_common.o
\
po_hi_driver_rasta_1553.o
\
po_hi_driver_xc4v_fpga.o
\
po_hi_driver_rasta_1553_brmlib.o
\
po_hi_driver_rasta_spacewire.o
$(ACTUAL_TRANSPORT)
\
po_hi_semaphore.o po_hi_storage.o po_hi_gqueue.o
\
po_hi_driver_exarm.o po_hi_driver_keyboard.o
\
po_hi_driver_exarm_ni_6071e_analog.o
\
po_hi_driver_exarm_ni_6071e_digital.o
\
po_hi_driver_usbbrick_spacewire.o po_hi_driver_linux_serial.o
\
po_hi_driver_leon_serial.o po_hi_driver_leon_eth.o
\
po_hi_driver_serial_common.o po_hi_driver_sockets.o
\
po_hi_driver_rtems_ne2000.o po_hi_driver_rasta_serial.o
\
po_hi_driver_rasta_common.o po_hi_driver_rasta_1553.o
\
po_hi_driver_xc4v_fpga.o po_hi_driver_rasta_1553_brmlib.o
\
po_hi_driver_rasta_spacewire.o
$(ACTUAL_TRANSPORT)
\
po_hi_transport.o
$(TARGET_TRANSPORT_SOURCES)
GENERATED_OBJS
=
activity.o subprograms.o types.o request.o
\
...
...
src/Makefile.am
View file @
59c8fac4
...
...
@@ -9,7 +9,7 @@ C_FILES = $(srcdir)/po_hi_task.c $(srcdir)/po_hi_main.c \
$(srcdir)
/po_hi_storage.c
$(srcdir)
/po_hi_types.c
\
$(srcdir)
/po_hi_utils.c
$(srcdir)
/po_hi_simulink.c
\
$(srcdir)
/po_hi_gprof_rtems_leon.c
\
$(srcdir)
/po_hi_time.c
$(srcdir)
/po_hi_time.c
$(srcdir)
/po_hi_semaphore.c
csrc
=
${
shell
$(CYGPATH_U)
'
$(OCARINA_RUNTIME)
/polyorb-hi-c/src'
}
...
...
src/po_hi_gqueue.c
View file @
59c8fac4
...
...
@@ -15,6 +15,9 @@
#include
<po_hi_transport.h>
#include
<po_hi_debug.h>
#include
<po_hi_gqueue.h>
#include
<po_hi_protected.h>
#include
<po_hi_semaphore.h>
#include
<po_hi_utils.h>
/* Headers from PolyORB-HI-C */
...
...
@@ -67,21 +70,10 @@ __po_hi_port_id_t* __po_hi_gqueues_port_is_empty[__PO_HI_NB_TASKS];
__po_hi_port_id_t
__po_hi_gqueues_queue_is_empty
[
__PO_HI_NB_TASKS
];
__po_hi_port_id_t
__po_hi_gqueues_n_empty
[
__PO_HI_NB_TASKS
];
#if defined (RTEMS_POSIX) || defined (POSIX) || defined (XENO_POSIX)
pthread_mutex_t
__po_hi_gqueues_mutexes
[
__PO_HI_NB_TASKS
];
pthread_cond_t
__po_hi_gqueues_conds
[
__PO_HI_NB_TASKS
];
pthread_mutexattr_t
__po_hi_gqueues_mutexes_attr
[
__PO_HI_NB_TASKS
];
pthread_condattr_t
__po_hi_gqueues_conds_attr
[
__PO_HI_NB_TASKS
];
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
rtems_id
__po_hi_gqueues_semaphores
[
__PO_HI_NB_TASKS
];
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
__po_hi_sem_t
__po_hi_gqueues_semaphores
[
__PO_HI_NB_TASKS
];
void
__po_hi_gqueue_init
(
__po_hi_task_id
id
,
__po_hi_port_id_t
nb_ports
,
...
...
@@ -100,13 +92,6 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
{
__po_hi_port_id_t
tmp
;
__po_hi_uint32_t
off
;
/* XXX May overflow for large value .. */
int
err
;
#if defined (__PO_HI_RTEMS_CLASSIC_API)
rtems_status_code
ret
;
#elif defined (XENO_NATIVE)
int
ret
;
#endif
__po_hi_gqueues_global_history_woffset
[
id
]
=
0
;
__po_hi_gqueues_global_history_offset
[
id
]
=
0
;
...
...
@@ -131,77 +116,15 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
__po_hi_gqueues_queue_is_empty
[
id
]
=
1
;
#if defined (RTEMS_POSIX) || defined (POSIX) || defined (XENO_POSIX)
err
=
pthread_mutexattr_init
(
&
__po_hi_gqueues_mutexes_attr
[
id
]);
__DEBUGMSG
(
"MUTEX_INIT %d %d
\n
"
,
id
,
err
);
assert
(
err
==
0
);
err
=
pthread_condattr_init
(
&
__po_hi_gqueues_conds_attr
[
id
]);
__DEBUGMSG
(
"MUTEX_INIT %d %d
\n
"
,
id
,
err
);
assert
(
err
==
0
);
#if defined (POSIX) || defined (XENO_POSIX)
// XXX disabled for OS X
#ifndef __MACH__ // OS X bugs on this attribute
err
=
pthread_mutexattr_setpshared
(
&
__po_hi_gqueues_mutexes_attr
[
id
],
PTHREAD_PROCESS_SHARED
);
assert
(
err
==
0
);
#endif
__DEBUGMSG
(
"MUTEX_INIT %d
\n
"
,
err
);
#endif
err
=
pthread_mutex_init
(
&
__po_hi_gqueues_mutexes
[
id
],
&
__po_hi_gqueues_mutexes_attr
[
id
]);
__DEBUGMSG
(
"MUTEX_INIT %d %d
\n
"
,
id
,
err
);
assert
(
err
==
0
);
err
=
pthread_cond_init
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_conds_attr
[
id
]);
__DEBUGMSG
(
"COND_INIT %d %d
\n
"
,
id
,
err
);
assert
(
err
==
0
);
#endif
#ifdef __PO_HI_RTEMS_CLASSIC_API
__PO_HI_DEBUG_INFO
(
"[GQUEUE] Create semaphore for queue of task %d
\n
"
,
id
);
ret
=
rtems_semaphore_create
(
rtems_build_name
(
'G'
,
'S'
,
'E'
,
'A'
+
(
char
)
id
),
1
,
RTEMS_BINARY_SEMAPHORE
,
__PO_HI_DEFAULT_PRIORITY
,
&
(
__po_hi_gqueues_semaphores
[
id
]));
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] Cannot create semaphore, error code=%d
\n
"
,
ret
);
}
__PO_HI_DEBUG_INFO
(
"[GQUEUE] Create barrier for queue of task %d
\n
"
,
id
);
ret
=
rtems_barrier_create
(
rtems_build_name
(
'G'
,
'S'
,
'I'
,
'A'
+
(
char
)
id
),
RTEMS_BARRIER_AUTOMATIC_RELEASE
,
10
,
&
(
__po_hi_gqueues_barriers
[
id
]));
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] Cannot create barrier, error code=%d
\n
"
,
ret
);
}
#endif
#ifdef XENO_NATIVE
ret
=
rt_mutex_create
(
&
__po_hi_gqueues_mutexes
[
id
],
NULL
);
/** Using the semaphore API to initialize the semaphore_gqueue array */
int
res
=
__po_hi_sem_init_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
//printf("res dans gqueeu = %d\n", res);
__DEBUGMSG
(
"GQUEUE_SEM_INIT %d %d
\n
"
,
id
,
res
);
assert
(
res
==
__PO_HI_SUCCESS
);
if
(
ret
!=
0
)
{
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] Cannot create mutex code=%d
\n
"
,
ret
);
}
ret
=
rt_cond_create
(
&
__po_hi_gqueues_conds
[
id
],
NULL
);
if
(
ret
!=
0
)
{
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] Cannot create cond code=%d
\n
"
,
ret
);
}
#endif
#ifdef _WIN32
__po_hi_gqueues_events
[
id
]
=
CreateEvent
(
NULL
,
FALSE
,
FALSE
,
NULL
);
if
(
__po_hi_gqueues_events
[
id
]
==
NULL
)
{
__PO_HI_DEBUG_CRITICAL
(
"CreateEvent failed (%d)
\n
"
,
GetLastError
());
return
;
}
InitializeCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#endif
off
=
0
;
for
(
tmp
=
0
;
tmp
<
nb_ports
;
tmp
++
)
{
__po_hi_gqueues_used_size
[
id
][
tmp
]
=
0
;
...
...
@@ -234,6 +157,7 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
#endif
}
void
__po_hi_gqueue_store_out
(
__po_hi_task_id
id
,
__po_hi_local_port_t
port
,
__po_hi_request_t
*
request
)
...
...
@@ -253,9 +177,7 @@ __po_hi_port_id_t __po_hi_gqueue_store_in (__po_hi_task_id id,
__po_hi_request_t
*
ptr
;
__po_hi_request_t
*
tmp
;
#ifdef __PO_HI_RTEMS_CLASSIC_API
rtems_status_code
ret
;
#endif
ptr
=
&
__po_hi_gqueues_most_recent_values
[
id
][
port
];
#ifdef __PO_HI_DEBUG
if
(
ptr
==
NULL
)
...
...
@@ -264,22 +186,10 @@ __po_hi_port_id_t __po_hi_gqueue_store_in (__po_hi_task_id id,
}
#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 (__PO_HI_RTEMS_CLASSIC_API)
__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
)
{
__DEBUGMSG
(
"[GQUEUE] Cannot obtain semaphore in __po_hi_gqueue_store_in()
\n
"
);
}
__DEBUGMSG
(
"[GQUEUE] Semaphore got (id=%d)
\n
"
,
id
);
#elif defined (_WIN32)
EnterCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#endif
/** Locking only a mutex */
int
result
=
__po_hi_sem_mutex_wait_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_MUTEX_WAIT %d %d
\n
"
,
id
,
result
);
assert
(
result
==
__PO_HI_SUCCESS
);
if
(
__po_hi_gqueues_sizes
[
id
][
port
]
==
__PO_HI_GQUEUE_FIFO_INDATA
)
{
...
...
@@ -291,20 +201,11 @@ __po_hi_port_id_t __po_hi_gqueue_store_in (__po_hi_task_id id,
if
(
__po_hi_gqueues_used_size
[
id
][
port
]
==
__po_hi_gqueues_sizes
[
id
][
port
])
{
/** Releasing only a mutex */
int
res
=
__po_hi_sem_mutex_release_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_MTUEX_RELEASE %d %d
\n
"
,
id
,
res
);
assert
(
res
==
__PO_HI_SUCCESS
);
#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 (__PO_HI_RTEMS_CLASSIC_API)
ret
=
rtems_semaphore_release
(
__po_hi_gqueues_semaphores
[
id
]);
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] Cannot release semaphore in __po_hi_gqueue_store_in()
\n
"
);
}
#elif defined (_WIN32)
LeaveCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#endif
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] QUEUE FULL, task-id=%d, port=%d
\n
"
,
id
,
port
);
__DEBUGMSG
(
"[GQUEUE] Semaphore released (id=%d)
\n
"
,
id
);
...
...
@@ -334,121 +235,41 @@ __po_hi_port_id_t __po_hi_gqueue_store_in (__po_hi_task_id id,
}
__po_hi_gqueues_queue_is_empty
[
id
]
=
0
;
}
/** Releasing a semaphore */
int
rel
=
__po_hi_sem_release_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_RELEASE %d %d
\n
"
,
id
,
rel
);
assert
(
rel
==
__PO_HI_SUCCESS
);
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_mutex_unlock
(
&
__po_hi_gqueues_mutexes
[
id
]);
int
err
=
pthread_cond_signal
(
&
__po_hi_gqueues_conds
[
id
]);
assert
(
err
==
0
);
__DEBUGMSG
(
"*** Releasing (%d) %d
\n
"
,
id
,
err
);
#elif defined (XENO_NATIVE)
rt_mutex_release
(
&
__po_hi_gqueues_mutexes
[
id
]);
rt_cond_broadcast
(
&
__po_hi_gqueues_conds
[
id
]);
#elif defined (_WIN32)
LeaveCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
if
(
!
SetEvent
(
__po_hi_gqueues_events
[
id
])
)
{
__DEBUGMSG
(
"SetEvent failed (%d)
\n
"
,
GetLastError
());
}
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
ret
=
rtems_semaphore_release
(
__po_hi_gqueues_semaphores
[
id
]);
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] Cannot release semaphore in __po_hi_gqueue_store_in()
\n
"
);
}
__DEBUGMSG
(
"[GQUEUE] Semaphore released (id=%d)
\n
"
,
id
);
#endif
__DEBUGMSG
(
"[GQUEUE] store_in completed
\n
"
);
return
__PO_HI_SUCCESS
;
__DEBUGMSG
(
"[GQUEUE] store_in completed
\n
"
);
return
__PO_HI_SUCCESS
;
}
void
__po_hi_gqueue_wait_for_incoming_event
(
__po_hi_task_id
id
,
__po_hi_local_port_t
*
port
)
{
#ifdef __PO_HI_RTEMS_CLASSIC_API
rtems_status_code
ret
;
#endif
#ifdef _WIN32
DWORD
ret
;
#endif
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
int
error
=
pthread_mutex_lock
(
&
__po_hi_gqueues_mutexes
[
id
]);
assert
(
error
==
0
);
__DEBUGMSG
(
"*** Locking (%d) %d
\n
"
,
id
,
error
);
#elif defined (XENO_NATIVE)
rt_mutex_acquire
(
&
__po_hi_gqueues_mutexes
[
id
],
TM_INFINITE
);
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
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
/** Locking only the mutex of the semaphore */
int
result
=
__po_hi_sem_mutex_wait_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_MUTEX_WAIT %d %d
\n
"
,
id
,
result
);
assert
(
result
==
__PO_HI_SUCCESS
);
while
(
__po_hi_gqueues_queue_is_empty
[
id
]
==
1
)
{
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"0t%d
\n
"
,
id
);
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
__DEBUGMSG
(
"*** Waiting (%d)
\n
"
,
id
);
int
error
=
pthread_cond_wait
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_mutexes
[
id
]);
assert
(
error
==
0
);
__DEBUGMSG
(
"*** Done Waiting (%d) %d
\n
"
,
id
,
error
);
#elif defined (XENO_NATIVE)
rt_cond_wait
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_mutexes
[
id
],
TM_INFINITE
);
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
ret
=
rtems_semaphore_release
(
__po_hi_gqueues_semaphores
[
id
]);
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
__DEBUGMSG
(
"[GQUEUE] Cannot obtain semaphore in __po_hi_gqueue_store_in()
\n
"
);
}
rtems_task_wake_after
(
1
);
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
"
);
}
else
{
__PO_HI_DEBUG_DEBUG
(
"[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_CRITICAL
(
"[GQUEUE] Wait failed
\n
"
);
}
EnterCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#endif
/** Telling the semaphore to wait */
int
res_sem
=
__po_hi_sem_wait_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_WAIT %d %d
\n
"
,
id
,
result
);
assert
(
res_sem
==
__PO_HI_SUCCESS
);
__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 (__PO_HI_RTEMS_CLASSIC_API)
ret
=
rtems_semaphore_release
(
__po_hi_gqueues_semaphores
[
id
]);
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
__DEBUGMSG
(
"[GQUEUE] Cannot release semaphore in __po_hi_gqueue_store_in()
\n
"
);
}
__PO_HI_DEBUG_DEBUG
(
"[GQUEUE] semaphore %d released
\n
"
,
id
);
#endif
/** Releasing only the mutex of the semaphore*/
int
res
=
__po_hi_sem_mutex_release_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_MTUEX_RELEASE %d %d
\n
"
,
id
,
res
);
assert
(
res
==
__PO_HI_SUCCESS
);
}
...
...
@@ -479,21 +300,12 @@ int __po_hi_gqueue_get_value (__po_hi_task_id id,
DWORD
ret
;
#endif
ptr
=
&
__po_hi_gqueues_most_recent_values
[
id
][
port
];
#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 (__PO_HI_RTEMS_CLASSIC_API)
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
/** Locking only the mutex of the semaphore */
int
result
=
__po_hi_sem_mutex_wait_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_MUTEX_WAIT %d %d
\n
"
,
id
,
result
);
assert
(
result
==
__PO_HI_SUCCESS
);
/*
* If the port is an event port, with no value queued, then we block
...
...
@@ -503,24 +315,10 @@ int __po_hi_gqueue_get_value (__po_hi_task_id id,
{
while
(
__po_hi_gqueues_port_is_empty
[
id
][
port
]
==
1
)
{
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_cond_wait
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_mutexes
[
id
]);
#elif defined (XENO_NATIVE)
rt_cond_wait
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_mutexes
[
id
],
TM_INFINITE
);
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
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_CRITICAL
(
"[GQUEUE] Wait failed
\n
"
);
}
EnterCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#endif
/** Telling the semaphore to wait */
int
res_sem
=
__po_hi_sem_wait_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_WAIT %d %d
\n
"
,
id
,
result
);
assert
(
res_sem
==
__PO_HI_SUCCESS
);
}
}
...
...
@@ -541,19 +339,10 @@ int __po_hi_gqueue_get_value (__po_hi_task_id id,
__PO_HI_DEBUG_INFO
(
"[GQUEUE] Task %d get a value on port %d
\n
"
,
id
,
port
);
#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 (__PO_HI_RTEMS_CLASSIC_API)
ret
=
rtems_semaphore_release
(
__po_hi_gqueues_semaphores
[
id
]);
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
__DEBUGMSG
(
"[GQUEUE] Cannot release semaphore in __po_hi_gqueue_store_in()
\n
"
);
}
#elif defined (_WIN32)
LeaveCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#endif
/** Releasing only the mutex of the semaphore*/
int
res
=
__po_hi_sem_mutex_release_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_MUTEX_RELEASE %d %d
\n
"
,
id
,
res
);
assert
(
res
==
__PO_HI_SUCCESS
);
return
0
;
}
...
...
@@ -573,20 +362,10 @@ int __po_hi_gqueue_next_value (__po_hi_task_id id, __po_hi_local_port_t port)
return
1
;
}
#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 (_WIN32)
EnterCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
ret
=
rtems_semaphore_obtain
(
__po_hi_gqueues_semaphores
[
id
],
RTEMS_WAIT
,
RTEMS_NO_TIMEOUT
);
if
(
ret
!=
RTEMS_SUCCESSFUL
)