Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PolyORB-HI-C
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TASTE
PolyORB-HI-C
Commits
cd543519
Commit
cd543519
authored
Jul 04, 2020
by
Maxime Perrotin
Browse files
Options
Browse Files
Download
Plain Diff
Merge
https://github.com/openaadl/polyorb-hi-c
parents
10933b7e
88e48c5d
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1073 additions
and
159 deletions
+1073
-159
include/po_hi_protected.h
include/po_hi_protected.h
+4
-2
include/po_hi_semaphore.h
include/po_hi_semaphore.h
+24
-19
include/po_hi_time.h
include/po_hi_time.h
+3
-3
include/simulator/um_threads.h
include/simulator/um_threads.h
+126
-27
src/po_hi_gqueue.c
src/po_hi_gqueue.c
+46
-39
src/po_hi_main.c
src/po_hi_main.c
+9
-0
src/po_hi_protected.c
src/po_hi_protected.c
+17
-1
src/po_hi_semaphore.c
src/po_hi_semaphore.c
+33
-5
src/po_hi_task.c
src/po_hi_task.c
+34
-2
src/po_hi_time.c
src/po_hi_time.c
+4
-2
src/simulator/um_threads.c
src/simulator/um_threads.c
+773
-59
No files found.
include/po_hi_protected.h
View file @
cd543519
...
...
@@ -5,13 +5,12 @@
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-20
18
ESA & ISAE.
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-20
20
ESA & ISAE.
*/
#ifndef __PO_HI_PROTECTED_H__
#define __PO_HI_PROTECTED_H__
#include <stdint.h>
#include <deployment.h>
...
...
@@ -70,6 +69,9 @@ typedef struct
#if defined (_WIN32)
HANDLE
win32_mutex
;
#endif
#if defined (SIMULATOR)
int
previous_priority
;
#endif
}
__po_hi_mutex_t
;
typedef
uint8_t
__po_hi_protected_t
;
...
...
include/po_hi_semaphore.h
View file @
cd543519
...
...
@@ -5,7 +5,7 @@
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2018 ESA & ISAE.
* Copyright (C) 2018
-2020
ESA & ISAE.
*/
#ifndef __PO_HI_SEMAPHORE_H__
...
...
@@ -31,6 +31,9 @@
#elif defined (_WIN32)
#include <windows.h>
#elif defined (SIMULATOR)
#include <um_threads.h>
#endif
/**
...
...
@@ -38,21 +41,23 @@
* \brief Structure defining a semaphore.
*/
typedef
struct
__po_hi_sem_t
__po_hi_sem_t
;
struct
__po_hi_sem_t
{
struct
__po_hi_sem_t
{
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
__po_hi_mutex_t
mutex
;
pthread_cond_t
posix_condvar
;
pthread_condattr_t
posix_condattr
;
__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
;
rtems_id
rtems_sem
;
rtems_id
rtems_barrier
;
#elif defined (XENO_NATIVE)
__po_hi_mutex_t
mutex
;
RT_COND
xeno_condvar
;
__po_hi_mutex_t
mutex
;
RT_COND
xeno_condvar
;
#elif defined (_WIN32)
HANDLE
win32_event
;
CRITICAL_SECTION
win32_criticalsection
;
HANDLE
win32_event
;
CRITICAL_SECTION
win32_criticalsection
;
#elif defined (SIMULATOR)
semaphore
*
um_mutex
;
semaphore
*
um_barrier
;
#endif
};
...
...
@@ -102,7 +107,7 @@ int __po_hi_sem_mutex_wait(__po_hi_sem_t* sem);
/**
* \brief The semaphore is released.
*
*
* The semaphore is COMPLETELY RELEASED. (both condvar and mutex).
* \param sem Semaphore structure to be worked on.
* \return __PO_HI_SUCCESS if successful.
...
...
@@ -112,7 +117,7 @@ int __po_hi_sem_release(__po_hi_sem_t* sem);
/**
* \brief The mutex attribute of a semaphore is released.
*
*
* This function is used when you don't want to do a condvar_signal, and
* want to let it stay on a wait mode.
* This function is also used when only a mutex is needed in the gqueue.
...
...
@@ -127,7 +132,7 @@ int __po_hi_sem_mutex_release(__po_hi_sem_t* sem);
/**
* \brief Used to do the po_hi_sem_init function on a semaphore contained in the semaphore array.
*
*
* \param array The array of semaphores used in the gqueue.
* \param id Identifier of the task.
* \return __PO_HI_SUCCESS if successful.
...
...
@@ -137,7 +142,7 @@ int __po_hi_sem_init_gqueue(__po_hi_sem_t array[__PO_HI_NB_TASKS], __po_hi_task_
/**
* \brief Used to do the po_hi_sem_wait function on a semaphore contained in the semaphore array.
*
*
* \param array The array of semaphores used in the gqueue.
* \param id Identifier of the task.
* \return __PO_HI_SUCCESS if successful.
...
...
@@ -147,7 +152,7 @@ int __po_hi_sem_wait_gqueue(__po_hi_sem_t array[__PO_HI_NB_TASKS], __po_hi_task_
/**
* \brief Used to do the po_hi_sem_mutex_wait function on a semaphore contained in the semaphore array.
*
*
* \param array The array of semaphores used in the gqueue.
* \param id Identifier of the task.
* \return __PO_HI_SUCCESS if successful.
...
...
@@ -157,7 +162,7 @@ int __po_hi_sem_mutex_wait_gqueue(__po_hi_sem_t array[__PO_HI_NB_TASKS], __po_hi
/**
* \brief Used to do the po_hi_sem_release function on a semaphore contained in the semaphore array.
*
*
* \param array The array of semaphores used in the gqueue.
* \param id Identifier of the task.
* \return __PO_HI_SUCCESS if successful.
...
...
@@ -167,7 +172,7 @@ int __po_hi_sem_release_gqueue(__po_hi_sem_t array[__PO_HI_NB_TASKS], __po_hi_ta
/**
* \brief Used to do the po_hi_sem_mutex_release function on a semaphore contained in the semaphore array.
*
*
* \param array The array of semaphores used in the gqueue.
* \param id Identifier of the task.
* \return __PO_HI_SUCCESS if successful.
...
...
include/po_hi_time.h
View file @
cd543519
...
...
@@ -5,7 +5,7 @@
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-20
19
ESA & ISAE.
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-20
20
ESA & ISAE.
*/
#ifndef __PO_HI_TIME_H__
...
...
@@ -38,8 +38,8 @@ LARGE_INTEGER __po_hi_unix_seconds_to_windows_tick(unsigned sec, unsigned nsec);
typedef
struct
{
__po_hi_
u
int32_t
sec
;
/* amount of second */
__po_hi_
u
int32_t
nsec
;
/* amount of nanosecond */
__po_hi_int32_t
sec
;
/* amount of second */
__po_hi_int32_t
nsec
;
/* amount of nanosecond */
}
__po_hi_time_t
;
/*
* Represent the time in PolyORB-HI.
...
...
include/simulator/um_threads.h
View file @
cd543519
...
...
@@ -9,23 +9,35 @@
#define __UM_THREADS_H__
#include<ucontext.h>
#include<deployment.h>
#include<po_hi_task.h>
#include<po_hi_time.h>
#include<stdint.h>
#include<time.h>
#include<stdbool.h>
#include<po_hi_time.h>
#include<po_hi_protected.h>
#define MAX(a,b) (((a)>(b))?(a):(b))
/*****************************************************************************/
/* CONSTANTS */
#define MAX_THREADS 10
/* Maximum number of threads */
#define STACKSIZE (1024 * 1024)
/* Default stack size */
#define INTERVAL 700
/* timer interval in microseconds */
#define MAX_CORE 1
#define STACKSIZE (128 * 1024)
/* Default stack size */
#define INTERVAL 700
/* timer interval in microseconds */
/*****************************************************************************/
typedef
struct
__po_hi_time_t
abs_time
;
//typedef struct timespec abs_time;
/******************************************************************************/
/* Thread entities */
/* Thread entities */
typedef
uint32_t
um_thread_id
;
/* id of a thread */
typedef
uint32_t
um_thread_id
;
/* id of a thread */
typedef
uint32_t
stack_size_t
;
/* stack size of a thread */
typedef
uint32_t
priority_t
;
/* priority */
typedef
enum
{
IDLE
,
READY
,
RUNNING
}
thread_state_t
;
typedef
enum
{
WAITING
,
READY
,
RUNNING
}
thread_state_t
;
typedef
struct
{
/* thread control block */
ucontext_t
um_context
;
...
...
@@ -33,8 +45,17 @@ typedef struct { /* thread control block */
stack_size_t
stack_size
;
priority_t
priority
;
thread_state_t
state
;
__po_hi_time_t
period
;
__po_hi_time_t
next_activation
;
/* the reactivation time of a task is
* relatif to the simulated clock */
}
um_thread_t
;
extern
um_thread_t
threads
[
MAX_THREADS
];
/* Array of threads currently configured in the program */
extern
uint32_t
um_thread_index
;
extern
uint32_t
nb_waiting_threads
;
um_thread_id
um_thread_create
(
void
(
*
function
)(
void
),
stack_size_t
stack_size
,
...
...
@@ -46,40 +67,118 @@ um_thread_id um_thread_create
* - function to execute
*/
/*
* Create a periodic task.
*
* The task created have the identifier given by the first
* parameter. It is created according to the period created
* with __po_hi_* functions (like __po_hi_milliseconds())
* and priority parameters (use the OS priority). The task execute
* periodically start_routine.
*
* This function returns SUCCESS if there is no error. Else,
* it returns the negative value ERROR_CREATE_TASK.
*/
int
um_thread_sim_create
(
void
*
(
*
function
)(
void
),
um_thread_id
um_thread_periodic_create
(
void
(
*
function
)(
void
),
stack_size_t
stack_size
,
priority_t
priority
,
const
__po_hi_task_id
po_hi_i
d
);
__po_hi_time_t
perio
d
);
void
um_thread_yield
(
void
);
/* um_thread_yield: relinquish CPU */
void
um_wait_all
(
void
);
/* block until all threads joined this function */
void
swap_to_scheduler_context
(
void
);
ucontext_t
*
get_context
(
um_thread_id
tid
);
ucontext_t
*
get_current_context
(
void
);
um_thread_id
get_current_context_id
(
void
);
um_thread_id
get_nb_waiting_threads
(
void
);
__po_hi_time_t
get_thread_period
(
um_thread_id
tid
);
/*****************************************************************************/
void
set_next_activation
(
um_thread_id
tid
,
__po_hi_time_t
next_activation
);
__po_hi_time_t
shift
(
__po_hi_uint32_t
second
,
__po_hi_uint32_t
nanosecond
);
/******************************************************************************/
/* Scheduler */
__po_hi_time_t
add_times
(
__po_hi_time_t
left
,
__po_hi_time_t
right
);
/* convert_seconds_to_abs_time converts the amount of time in seconds
* to an abs_time value.
*/
__po_hi_time_t
convert_seconds_to_abs_time
(
uint32_t
seconds
);
/*****************************************************************************/
/* Scheduler */
typedef
um_thread_id
(
*
scheduler_function
)
(
void
);
void
configure_scheduler
(
scheduler_function
s
);
void
start_scheduler
(
void
);
void
scheduler
(
void
);
void
control_scheduler
(
void
);
/* FIFO within priority scheduling policy. */
um_thread_id
scheduler_fifo
(
void
);
void
configure_fifo_scheduler
(
void
);
/* Configure the FIFO within priority scheduler, Only one thread by priority. */
/*****************************************************************************/
/* Waiting List */
typedef
struct
_waiting_list
{
__po_hi_time_t
t
;
/* deadline of the waiting thread */
um_thread_id
tid
;
struct
_waiting_list
*
next
;
}
waiting_list
;
extern
waiting_list
*
w_list
;
void
delay_until
(
um_thread_id
tid
,
__po_hi_time_t
n_time
);
void
delay_until_for_a_given_thread
(
um_thread_id
tid
,
__po_hi_time_t
n_time
);
void
do_awake_list
(
void
);
/*****************************************************************************/
/* Timer utilities */
void
setup_timer
(
uint32_t
period
,
bool
periodic
);
/* activate a periodic timer of "period" ms */
void
init_timer
();
void
stop_timer
();
void
set_timer_next
(
void
);
void
set_timer_after_resuming_execution
(
__po_hi_time_t
resume_execution_time
);
/*****************************************************************************/
/* Semaphore */
typedef
struct
_wait_list
{
um_thread_id
tid
;
struct
_wait_list
*
next
;
}
wait_list
;
typedef
struct
_semaphore
{
int
value
;
um_thread_id
tid
;
wait_list
*
h_list
;
wait_list
*
t_list
;
int
name
;
}
semaphore
;
void
semaphore_init
(
semaphore
*
s
,
int
value
,
int
name
);
void
semaphore_wait
(
semaphore
*
s
);
void
semaphore_post
(
semaphore
*
s
);
/*****************************************************************************/
/* Mutex */
typedef
struct
_mutex
{
int
priority
;
int
previous_priority
;
}
mutex
;
void
mutex_init
(
__po_hi_mutex_t
*
m
,
int
priority
);
void
mutex_lock
(
__po_hi_mutex_t
*
m
);
/******************************************************************************/
void
mutex_unlock
(
__po_hi_mutex_t
*
m
);
/*****************************************************************************/
#endif
/* __UM_THREADS_H__ */
src/po_hi_gqueue.c
View file @
cd543519
...
...
@@ -318,8 +318,11 @@ __po_hi_port_id_t __po_hi_gqueue_store_in (__po_hi_task_id id,
__DEBUGMSG
(
"__po_hi_gqueue_store_in : NULL POINTER
\n
"
);
}
#endif
/* Locking only a mutex */
__PO_HI_DEBUG_DEBUG
(
"
\n
Waiting on Store_in on task %d, port = %d, size of port = %d
\n
"
,
id
,
port
,
__po_hi_gqueue_get_port_size
(
id
,
port
));
__PO_HI_DEBUG_DEBUG
(
"
\n
Waiting on Store_in on task %d, port = %d, size of port = %d
\n
"
,
id
,
port
,
__po_hi_gqueue_get_port_size
(
id
,
port
));
int
result
=
__po_hi_sem_mutex_wait_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
__DEBUGMSG
(
"GQUEUE_SEM_MUTEX_WAIT on task %d result = %d
\n
"
,
id
,
result
);
assert
(
result
==
__PO_HI_SUCCESS
);
...
...
@@ -367,10 +370,10 @@ __po_hi_port_id_t __po_hi_gqueue_store_in (__po_hi_task_id id,
__PO_HI_DEBUG_DEBUG
(
"
\n
Before used_size ++, Store_in for task = %d, __po_hi_gqueues_used_size[id][port] = %d
\n
"
,
id
,
__po_hi_gqueues_used_size
[
id
][
port
]);
__po_hi_gqueues_used_size
[
id
][
port
]
++
;
__PO_HI_DEBUG_DEBUG
(
"
\n
After used_size ++ , Store_in for task = %d, __po_hi_gqueues_used_size[id][port] = %d
\n
"
,
id
,
__po_hi_gqueues_used_size
[
id
][
port
]);
#if defined(__PO_HI_USE_VCD) && defined(__unix__)
__po_hi_save_event_in_vcd_trace
(
__po_hi_compute_timestamp
(),
__po_hi_store_in_port_queue
,
id
,
port
,
__po_hi_gqueue_used_size
(
id
,
port
));
#endif
#endif
/* The port where information has been written is stored */
__po_hi_gqueues_global_history
[
id
][
__po_hi_gqueues_global_history_woffset
[
id
]]
=
port
;
__po_hi_gqueues_global_history_woffset
[
id
]
=
(
__po_hi_gqueues_global_history_woffset
[
id
]
+
1
)
%
__po_hi_gqueues_total_fifo_size
[
id
];
...
...
@@ -425,36 +428,36 @@ __po_hi_bool_t __po_hi_gqueue_compute_index_transition_to_execute (__po_hi_task_
int
*
initial_sizes_of_dispatch_triggers_of_all_transitions
,
__po_hi_int32_t
*
index_transition_to_execute
)
{
__po_hi_int32_t
i
=
0
;
__po_hi_bool_t
dispatch_condition_of_any_transition_is_verified
=
0
;
__po_hi_int32_t
tmp
=
0
;
__po_hi_int32_t
j
=
0
;
__po_hi_bool_t
dispatch_condition
;
while
(
i
<
next_complete_state
->
nb_transitions
&&
!
dispatch_condition_of_any_transition_is_verified
)
{
dispatch_condition
=
1
;
while
(
j
<
(
tmp
+
next_complete_state
->
nb_dispatch_triggers_of_each_transition
[
i
])
&&
dispatch_condition
)
{
dispatch_condition
=
(
initial_sizes_of_dispatch_triggers_of_all_transitions
[
j
]
<
__po_hi_gqueue_get_count
(
id
,
next_complete_state
->
dispatch_triggers_of_all_transitions
[
j
]));
j
++
;
}
if
(
dispatch_condition
)
{
*
index_transition_to_execute
=
i
+
1
;
}
tmp
=
tmp
+
next_complete_state
->
nb_dispatch_triggers_of_each_transition
[
i
];
j
=
tmp
;
dispatch_condition_of_any_transition_is_verified
=
dispatch_condition
;
i
++
;
__po_hi_int32_t
i
=
0
;
__po_hi_bool_t
dispatch_condition_of_any_transition_is_verified
=
0
;
__po_hi_int32_t
tmp
=
0
;
__po_hi_int32_t
j
=
0
;
__po_hi_bool_t
dispatch_condition
;
while
(
i
<
next_complete_state
->
nb_transitions
&&
!
dispatch_condition_of_any_transition_is_verified
)
{
dispatch_condition
=
1
;
while
(
j
<
(
tmp
+
next_complete_state
->
nb_dispatch_triggers_of_each_transition
[
i
])
&&
dispatch_condition
)
{
dispatch_condition
=
(
initial_sizes_of_dispatch_triggers_of_all_transitions
[
j
]
<
__po_hi_gqueue_get_count
(
id
,
next_complete_state
->
dispatch_triggers_of_all_transitions
[
j
]));
j
++
;
}
if
(
dispatch_condition
)
{
*
index_transition_to_execute
=
i
+
1
;
}
tmp
=
tmp
+
next_complete_state
->
nb_dispatch_triggers_of_each_transition
[
i
];
j
=
tmp
;
dispatch_condition_of_any_transition_is_verified
=
dispatch_condition
;
i
++
;
}
return
dispatch_condition
;
return
dispatch_condition
;
}
/******************************************************************************/
...
...
@@ -466,17 +469,21 @@ void __po_hi_gqueue_wait_for_specific_incoming_events (__po_hi_task_id id,
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
);
int
initial_sizes_of_dispatch_triggers_of_all_transitions
[
next_complete_state
->
nb_of_all_dispatch_events
];
for
(
int
i
=
0
;
i
<
(
next_complete_state
->
nb_of_all_dispatch_events
);
i
++
)
{
initial_sizes_of_dispatch_triggers_of_all_transitions
[
i
]
=
__po_hi_gqueue_get_count
(
id
,
next_complete_state
->
dispatch_triggers_of_all_transitions
[
i
]);
initial_sizes_of_dispatch_triggers_of_all_transitions
[
i
]
=
__po_hi_gqueue_get_count
(
id
,
next_complete_state
->
dispatch_triggers_of_all_transitions
[
i
]);
}
*
index_transition_to_execute
=
-
1
;
while
(
!
__po_hi_gqueue_compute_index_transition_to_execute
(
id
,
next_complete_state
,
initial_sizes_of_dispatch_triggers_of_all_transitions
,
index_transition_to_execute
))
while
(
!
__po_hi_gqueue_compute_index_transition_to_execute
(
id
,
next_complete_state
,
initial_sizes_of_dispatch_triggers_of_all_transitions
,
index_transition_to_execute
))
{
/* Telling the semaphore to wait with putting its condvar on wait mode */
int
res_sem
=
__po_hi_sem_wait_gqueue
(
__po_hi_gqueues_semaphores
,
id
);
...
...
@@ -490,9 +497,9 @@ void __po_hi_gqueue_wait_for_specific_incoming_events (__po_hi_task_id id,
#if defined(__PO_HI_USE_VCD) && defined(__unix__)
__po_hi_save_event_in_vcd_trace
(
__po_hi_compute_timestamp
(),
__po_hi_task_dispatched
,
id
,
invalid_local_port_t
,
-
1
);
#endif
#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
);
...
...
@@ -532,7 +539,7 @@ void __po_hi_gqueue_wait_for_incoming_event (__po_hi_task_id id,
__po_hi_save_event_in_vcd_trace
(
__po_hi_compute_timestamp
(),
__po_hi_task_dispatched
,
id
,
invalid_local_port_t
,
-
1
);
#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
);
...
...
src/po_hi_main.c
View file @
cd543519
...
...
@@ -45,6 +45,12 @@ pthread_mutex_t mutex_init;
rtems_id
__po_hi_main_initialization_barrier
;
#endif
#if defined (SIMULATOR)
#include <um_threads.h>
#include <po_hi_semaphore.h>
#endif
#ifdef _WIN32
CRITICAL_SECTION
__po_hi_main_initialization_critical_section
;
HANDLE
__po_hi_main_initialization_event
;
...
...
@@ -526,6 +532,9 @@ int __po_hi_wait_initialization (void)
LeaveCriticalSection
(
&
__po_hi_main_initialization_critical_section
);
return
(
__PO_HI_SUCCESS
);
#elif defined (SIMULATOR)
um_wait_all
();
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
rtems_status_code
ret
;
...
...
src/po_hi_protected.c
View file @
cd543519
...
...
@@ -5,7 +5,7 @@
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-20
18
ESA & ISAE.
* Copyright (C) 2007-2009 Telecom ParisTech, 2010-20
20
ESA & ISAE.
*/
#include <po_hi_config.h>
...
...
@@ -35,6 +35,10 @@
#include <rtems.h>
#endif
#ifdef SIMULATOR
#include <um_threads.h>
#endif
#if __PO_HI_NB_PROTECTED > 0
/* Declare only needed mutexes according to the generated
...
...
@@ -160,6 +164,12 @@ int __po_hi_mutex_init (__po_hi_mutex_t* mutex, const __po_hi_mutex_protocol_t p
return
__PO_HI_ERROR_UNKNOWN
;
}
#endif
#if defined (SIMULATOR)
if
(
priority
==
0
)
mutex
->
priority
=
__PO_HI_MAX_PRIORITY
-
1
;
else
mutex
->
priority
=
priority
;
#endif
#if defined (XENO_NATIVE)
if
(
rt_mutex_create
(
&
mutex
->
xeno_mutex
,
NULL
)
!=
0
)
{
...
...
@@ -195,6 +205,9 @@ int __po_hi_mutex_lock (__po_hi_mutex_t* mutex)
return
__PO_HI_ERROR_MUTEX_LOCK
;
}
#endif
#if defined (SIMULATOR)
mutex_lock
(
mutex
);
#endif
#ifdef __PO_HI_RTEMS_CLASSIC_API
if
(
rtems_semaphore_obtain
(
mutex
->
rtems_mutex
,
RTEMS_WAIT
,
RTEMS_NO_TIMEOUT
)
!=
RTEMS_SUCCESSFUL
)
{
...
...
@@ -237,6 +250,9 @@ int __po_hi_mutex_unlock (__po_hi_mutex_t* mutex)
return
__PO_HI_ERROR_MUTEX_UNLOCK
;
}
#endif
#if defined (SIMULATOR)
mutex_unlock
(
mutex
);
#endif
#ifdef __PO_HI_RTEMS_CLASSIC_API
if
(
rtems_semaphore_release
(
mutex
->
rtems_mutex
)
!=
RTEMS_SUCCESSFUL
)
{
...
...
src/po_hi_semaphore.c
View file @
cd543519
...
...
@@ -5,7 +5,7 @@
*
* For more informations, please visit http://taste.tuxfamily.org/wiki
*
* Copyright (C) 2018 ESA & ISAE.
* Copyright (C) 2018
-2020
ESA & ISAE.
*/
#include <po_hi_returns.h>
...
...
@@ -38,7 +38,7 @@
/* TO INITIALIZE THE STRUCTURES */
int
__po_hi_sem_init
(
__po_hi_sem_t
*
sem
,
const
__po_hi_mutex_protocol_t
protocol
,
const
int
priority
,
int
id
)
{
__PO_HI_DEBUG_INFO
(
"[SEM] Sem Task %d is initialized"
,
id
);
__PO_HI_DEBUG_INFO
(
"[SEM] Sem Task %d is initialized
\n
"
,
id
);
#if defined (RTEMS_POSIX) || defined (POSIX) || defined (XENO_POSIX)
/* Attribute and mutex initialization */
...
...
@@ -60,6 +60,15 @@ int __po_hi_sem_init(__po_hi_sem_t* sem, const __po_hi_mutex_protocol_t protocol
return
__PO_HI_ERROR_SEM_CREATE
;
}
#elif defined (SIMULATOR)
static
int
_name
=
0
;
sem
->
um_barrier
=
(
semaphore
*
)
malloc
(
sizeof
(
semaphore
));
sem
->
um_mutex
=
(
semaphore
*
)
malloc
(
sizeof
(
semaphore
));
semaphore_init
(
sem
->
um_barrier
,
0
,
++
_name
);
__PO_HI_DEBUG_INFO
(
"[SEM] Task %d barrier is: %d
\n
"
,
id
,
_name
);
semaphore_init
(
sem
->
um_mutex
,
1
,
++
_name
);
__PO_HI_DEBUG_INFO
(
"[SEM] Task %d mutex: %d
\n
"
,
id
,
_name
);
#elif defined (XENO_NATIVE)
/* Mutex initialization */
/* The protocol and priority are unused here */
...
...
@@ -105,6 +114,7 @@ int __po_hi_sem_init(__po_hi_sem_t* sem, const __po_hi_mutex_protocol_t protocol
#else
#error Unsupported platform
#endif
return
(
__PO_HI_SUCCESS
);
}
...
...
@@ -118,7 +128,7 @@ int __po_hi_sem_wait(__po_hi_sem_t* sem)
if
(
pthread_mutex_trylock
(
&
sem
->
mutex
.
posix_mutex
)
==
0
)
{
pthread_mutex_lock
(
&
sem
->
mutex
.
posix_mutex
);
}
/* Waiting on a condition and unlocking the mutex while doing so */
if
(
pthread_cond_wait
(
&
sem
->
posix_condvar
,
&
sem
->
mutex
.
posix_mutex
)
!=
0
)
{
...
...
@@ -126,6 +136,14 @@ int __po_hi_sem_wait(__po_hi_sem_t* sem)
return
__PO_HI_ERROR_SEM_WAIT
;
}
#elif defined (SIMULATOR)
if
((
sem
->
um_mutex
)
->
value
==
0
)
{
semaphore_post
(
sem
->
um_mutex
);
///
}
//assert((sem->um_barrier)->value !=0);
semaphore_wait
(
sem
->
um_barrier
);
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
if
(
rtems_semaphore_release
(
sem
->
rtems_sem
)
!=
RTEMS_SUCCESSFUL
)
{
...
...
@@ -165,9 +183,8 @@ int __po_hi_sem_wait(__po_hi_sem_t* sem)
}
/* Waiting for ownership of the specified critical section object */
EnterCriticalSection
(
&
sem
->
win32_criticalsection
);
#endif
return
__PO_HI_SUCCESS
;
}
...
...
@@ -181,6 +198,9 @@ int __po_hi_sem_mutex_wait(__po_hi_sem_t* sem){
return
__PO_HI_ERROR_SEM_WAIT
;
}
#elif defined (SIMULATOR)
semaphore_wait
(
sem
->
um_mutex
);
#elif defined (__PO_HI_RTEMS_CLASSIC_API)
if
(
rtems_semaphore_obtain
(
sem
->
rtems_sem
,
RTEMS_WAIT
,
RTEMS_NO_TIMEOUT
)
!=
RTEMS_SUCCESSFUL
)
{
...
...
@@ -211,6 +231,10 @@ int __po_hi_sem_release(__po_hi_sem_t* sem)
return
__PO_HI_ERROR_SEM_RELEASE
;
}
#elif defined (SIMULATOR)
semaphore_post
(
sem
->
um_barrier
);
semaphore_post
(
sem
->
um_mutex
);
//
#elif defined(__PO_HI_RTEMS_CLASSIC_API)
if
(
rtems_semaphore_release
(
sem
->
rtems_sem
)
!=
RTEMS_SUCCESSFUL
)
{
...
...
@@ -240,6 +264,7 @@ int __po_hi_sem_release(__po_hi_sem_t* sem)
__DEBUGMSG
(
"SetEvent failed (%d)
\n
"
,
GetLastError
());
return
__PO_HI_ERROR_SEM_RELEASE
;