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
85c37c99
Commit
85c37c99
authored
Nov 13, 2014
by
yoogx
Browse files
* Minor reformatting, hack for OS X
parent
1d305f28
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/po_hi_gqueue.c
View file @
85c37c99
...
...
@@ -39,7 +39,7 @@
#define __PO_HI_GQUEUE_OUT_PORT constant_out_identifier
#define __PO_HI_GQUEUE_OUT_PORT constant_out_identifier
/* give a default value to the out port */
__po_hi_port_t
*
__po_hi_gqueues
[
__PO_HI_NB_TASKS
];
...
...
@@ -97,6 +97,7 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
__po_hi_uint8_t
tmp
;
__po_hi_uint16_t
off
;
__po_hi_request_t
*
request
;
int
err
;
#if defined (RTEMS_PURE)
rtems_status_code
ret
;
...
...
@@ -115,7 +116,7 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
__po_hi_gqueues_port_is_empty
[
id
]
=
empties
;
__po_hi_gqueues_nb_ports
[
id
]
=
nb_ports
;
__po_hi_gqueues_nb_ports
[
id
]
=
nb_ports
;
__po_hi_gqueues_sizes
[
id
]
=
sizes
;
__po_hi_gqueues_first
[
id
]
=
first
;
__po_hi_gqueues_used_size
[
id
]
=
used_size
;
...
...
@@ -128,13 +129,19 @@ 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)
pthread_mutexattr_init
(
&
__po_hi_gqueues_mutexes_attr
[
id
]);
pthread_condattr_init
(
&
__po_hi_gqueues_conds_attr
[
id
]);
err
=
pthread_mutexattr_init
(
&
__po_hi_gqueues_mutexes_attr
[
id
]);
__DEBUGMSG
(
"MUTEX_INIT %d %d
\n
"
,
id
,
err
);
err
=
pthread_condattr_init
(
&
__po_hi_gqueues_conds_attr
[
id
]);
__DEBUGMSG
(
"MUTEX_INIT %d %d
\n
"
,
id
,
err
);
#if defined (POSIX) || defined (XENO_POSIX)
pthread_mutexattr_setpshared
(
&
__po_hi_gqueues_mutexes_attr
[
id
],
PTHREAD_PROCESS_SHARED
);
// XXX disabled for OS X
// err = pthread_mutexattr_setpshared(&__po_hi_gqueues_mutexes_attr[id],PTHREAD_PROCESS_SHARED);
__DEBUGMSG
(
"MUTEX_INIT %d
\n
"
,
err
);
#endif
pthread_mutex_init
(
&
__po_hi_gqueues_mutexes
[
id
],
&
__po_hi_gqueues_mutexes_attr
[
id
]);
pthread_cond_init
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_conds_attr
[
id
]);
err
=
pthread_mutex_init
(
&
__po_hi_gqueues_mutexes
[
id
],
&
__po_hi_gqueues_mutexes_attr
[
id
]);
__DEBUGMSG
(
"MUTEX_INIT %d %d
\n
"
,
id
,
err
);
err
=
pthread_cond_init
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_conds_attr
[
id
]);
__DEBUGMSG
(
"COND_INIT %d %d
\n
"
,
id
,
err
);
#endif
#ifdef RTEMS_PURE
...
...
@@ -170,10 +177,10 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
#endif
#ifdef _WIN32
__po_hi_gqueues_events
[
id
]
=
CreateEvent
(
NULL
,
FALSE
,
FALSE
,
NULL
);
__po_hi_gqueues_events
[
id
]
=
CreateEvent
(
NULL
,
FALSE
,
FALSE
,
NULL
);
if
(
__po_hi_gqueues_events
[
id
]
==
NULL
)
{
if
(
__po_hi_gqueues_events
[
id
]
==
NULL
)
{
__PO_HI_DEBUG_WARNING
(
"CreateEvent failed (%d)
\n
"
,
GetLastError
());
return
;
...
...
@@ -187,7 +194,7 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
{
__po_hi_gqueues_used_size
[
id
][
tmp
]
=
0
;
if
(
(
sizes
[
tmp
]
!=
__PO_HI_GQUEUE_FIFO_INDATA
)
if
(
(
sizes
[
tmp
]
!=
__PO_HI_GQUEUE_FIFO_INDATA
)
&&
(
sizes
[
tmp
]
!=
__PO_HI_GQUEUE_FIFO_OUT
))
{
__po_hi_gqueues_first
[
id
][
tmp
]
=
off
;
...
...
@@ -206,18 +213,18 @@ void __po_hi_gqueue_init (__po_hi_task_id id,
__DEBUGMSG
(
"Initialize global queue for task-id %d ... "
,
id
);
for
(
tmp
=
0
;
tmp
<
nb_ports
;
tmp
++
)
{
__DEBUGMSG
(
"port %d (used_size=%d,first=%d) "
,
tmp
,
__DEBUGMSG
(
"port %d (used_size=%d,first=%d) "
,
tmp
,
__po_hi_gqueues_used_size
[
id
][
tmp
],
__po_hi_gqueues_first
[
id
][
tmp
]);
}
__DEBUGMSG
(
" ... done
\n
"
);
#endif
#endif
}
void
__po_hi_gqueue_store_out
(
__po_hi_task_id
id
,
__po_hi_local_port_t
port
,
void
__po_hi_gqueue_store_out
(
__po_hi_task_id
id
,
__po_hi_local_port_t
port
,
__po_hi_request_t
*
request
)
{
__po_hi_request_t
*
ptr
;
...
...
@@ -230,8 +237,8 @@ void __po_hi_gqueue_store_out (__po_hi_task_id id,
__po_hi_uint8_t
__po_hi_gqueue_store_in
(
__po_hi_task_id
id
,
__po_hi_local_port_t
port
,
__po_hi_uint8_t
__po_hi_gqueue_store_in
(
__po_hi_task_id
id
,
__po_hi_local_port_t
port
,
__po_hi_request_t
*
request
)
{
__po_hi_request_t
*
ptr
;
...
...
@@ -275,23 +282,24 @@ __po_hi_uint8_t __po_hi_gqueue_store_in (__po_hi_task_id id,
#endif
if
(
__po_hi_gqueues_used_size
[
id
][
port
]
==
__po_hi_gqueues_sizes
[
id
][
port
])
{
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_mutex_unlock
(
&
__po_hi_gqueues_mutexes
[
id
]);
pthread_mutex_unlock
(
&
__po_hi_gqueues_mutexes
[
id
]);
#elif defined (XENO_NATIVE)
rt_mutex_release
(
&
__po_hi_gqueues_mutexes
[
id
]);
rt_mutex_release
(
&
__po_hi_gqueues_mutexes
[
id
]);
#elif defined (RTEMS_PURE)
ret
=
rtems_semaphore_release
(
__po_hi_gqueues_semaphores
[
id
]);
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
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
]);
LeaveCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#endif
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] QUEUE FULL, task-id=%d, port=%d
\n
"
,
id
,
port
);
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] QUEUE FULL, task-id=%d, port=%d
\n
"
,
id
,
port
);
__DEBUGMSG
(
"[GQUEUE] Semaphore released (id=%d)
\n
"
,
id
);
return
__PO_HI_ERROR_QUEUE_FULL
;
__DEBUGMSG
(
"[GQUEUE] Semaphore released (id=%d)
\n
"
,
id
);
return
__PO_HI_ERROR_QUEUE_FULL
;
}
tmp
=
(
__po_hi_request_t
*
)
&
__po_hi_gqueues
[
id
][
port
];
...
...
@@ -304,7 +312,7 @@ __po_hi_uint8_t __po_hi_gqueue_store_in (__po_hi_task_id id,
__po_hi_gqueues_woffsets
[
id
][
port
]
=
(
__po_hi_gqueues_woffsets
[
id
][
port
]
+
1
)
%
__po_hi_gqueues_sizes
[
id
][
port
];
__po_hi_gqueues_used_size
[
id
][
port
]
++
;
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"r%d p%d.%d
\n
"
,
__po_hi_gqueues_used_size
[
id
][
port
],
id
,
port
);
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"r%d p%d.%d
\n
"
,
__po_hi_gqueues_used_size
[
id
][
port
],
id
,
port
);
__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
];
...
...
@@ -319,13 +327,14 @@ __po_hi_uint8_t __po_hi_gqueue_store_in (__po_hi_task_id id,
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_mutex_unlock
(
&
__po_hi_gqueues_mutexes
[
id
]);
pthread_cond_broadcast
(
&
__po_hi_gqueues_conds
[
id
]);
int
err
=
pthread_cond_signal
(
&
__po_hi_gqueues_conds
[
id
]);
__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
])
)
if
(
!
SetEvent
(
__po_hi_gqueues_events
[
id
])
)
{
__DEBUGMSG
(
"SetEvent failed (%d)
\n
"
,
GetLastError
());
}
...
...
@@ -338,92 +347,94 @@ __po_hi_uint8_t __po_hi_gqueue_store_in (__po_hi_task_id id,
__DEBUGMSG
(
"[GQUEUE] Semaphore released (id=%d)
\n
"
,
id
);
#endif
__DEBUGMSG
(
"[GQUEUE] store_in completed
\n
"
);
return
__PO_HI_SUCCESS
;
}
void
__po_hi_gqueue_wait_for_incoming_event
(
__po_hi_task_id
id
,
void
__po_hi_gqueue_wait_for_incoming_event
(
__po_hi_task_id
id
,
__po_hi_local_port_t
*
port
)
{
#ifdef RTEMS_PURE
rtems_status_code
ret
;
rtems_status_code
ret
;
#endif
#ifdef _WIN32
DWORD
ret
;
DWORD
ret
;
#endif
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_mutex_lock
(
&
__po_hi_gqueues_mutexes
[
id
]);
int
error
=
pthread_mutex_lock
(
&
__po_hi_gqueues_mutexes
[
id
]);
__DEBUGMSG
(
"*** Locking (%d) %d
\n
"
,
id
,
error
);
#elif defined (XENO_NATIVE)
rt_mutex_acquire
(
&
__po_hi_gqueues_mutexes
[
id
],
TM_INFINITE
);
rt_mutex_acquire
(
&
__po_hi_gqueues_mutexes
[
id
],
TM_INFINITE
);
#elif defined (RTEMS_PURE)
ret
=
rtems_semaphore_obtain
(
__po_hi_gqueues_semaphores
[
id
],
RTEMS_WAIT
,
RTEMS_NO_TIMEOUT
);
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] 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
)
{
while
(
__po_hi_gqueues_queue_is_empty
[
id
]
==
1
)
{
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"0t%d
\n
"
,
id
);
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"0t%d
\n
"
,
id
);
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
pthread_cond_wait
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_mutexes
[
id
]);
__DEBUGMSG
(
"*** Waiting (%d)
\n
"
,
id
);
int
error
=
pthread_cond_wait
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_mutexes
[
id
]);
__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
);
rt_cond_wait
(
&
__po_hi_gqueues_conds
[
id
],
&
__po_hi_gqueues_mutexes
[
id
],
TM_INFINITE
);
#elif defined (RTEMS_PURE)
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
"
);
}
{
__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
"
);
}
{
__DEBUGMSG
(
"[GQUEUE] Cannot obtain semaphore in __po_hi_gqueue_store_in()
\n
"
);
}
else
{
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] semaphore %d obtained
\n
"
,
id
);
}
{
__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
]);
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
);
}
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"1t%d
\n
"
,
id
);
}
*
port
=
__po_hi_gqueues_global_history
[
id
][
__po_hi_gqueues_global_history_offset
[
id
]];
__DEBUGMSG
(
"[GQUEUE] Gogo kiki
\n
"
);
*
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
]);
pthread_mutex_unlock
(
&
__po_hi_gqueues_mutexes
[
id
]);
#elif defined (XENO_NATIVE)
rt_mutex_release
(
&
__po_hi_gqueues_mutexes
[
id
]);
rt_mutex_release
(
&
__po_hi_gqueues_mutexes
[
id
]);
#elif defined (_WIN32)
LeaveCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
LeaveCriticalSection
(
&
__po_hi_gqueues_cs
[
id
]);
#elif defined (RTEMS_PURE)
ret
=
rtems_semaphore_release
(
__po_hi_gqueues_semaphores
[
id
]);
if
(
ret
!=
RTEMS_SUCCESSFUL
)
{
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_CRITICAL
(
"[GQUEUE] semaphore %d released
\n
"
,
id
);
__PO_HI_DEBUG_CRITICAL
(
"[GQUEUE] semaphore %d released
\n
"
,
id
);
#endif
}
...
...
@@ -440,8 +451,8 @@ int __po_hi_gqueue_get_count( __po_hi_task_id id, __po_hi_local_port_t port)
}
}
int
__po_hi_gqueue_get_value
(
__po_hi_task_id
id
,
__po_hi_local_port_t
port
,
int
__po_hi_gqueue_get_value
(
__po_hi_task_id
id
,
__po_hi_local_port_t
port
,
__po_hi_request_t
*
request
)
{
__po_hi_request_t
*
ptr
;
...
...
@@ -504,11 +515,11 @@ int __po_hi_gqueue_get_value (__po_hi_task_id id,
}
else
{
ptr
=
((
__po_hi_request_t
*
)
&
__po_hi_gqueues
[
id
][
port
])
+
__po_hi_gqueues_first
[
id
][
port
]
+
__po_hi_gqueues_offsets
[
id
][
port
];
ptr
=
((
__po_hi_request_t
*
)
&
__po_hi_gqueues
[
id
][
port
])
+
__po_hi_gqueues_first
[
id
][
port
]
+
__po_hi_gqueues_offsets
[
id
][
port
];
memcpy
(
request
,
ptr
,
sizeof
(
__po_hi_request_t
));
}
__PO_HI_DEBUG_INFO
(
"[GQUEUE] Task %d get a value on port %d
\n
"
,
id
,
port
);
/*
...
...
@@ -581,13 +592,13 @@ int __po_hi_gqueue_next_value (__po_hi_task_id id, __po_hi_local_port_t port)
#endif
__po_hi_gqueues_offsets
[
id
][
port
]
=
(
__po_hi_gqueues_offsets
[
id
][
port
]
+
1
)
__po_hi_gqueues_offsets
[
id
][
port
]
=
(
__po_hi_gqueues_offsets
[
id
][
port
]
+
1
)
%
__po_hi_gqueues_sizes
[
id
][
port
];
__po_hi_gqueues_used_size
[
id
][
port
]
--
;
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"r%d p%d.%d
\n
"
,
__po_hi_gqueues_used_size
[
id
][
port
],
id
,
port
);
__PO_HI_INSTRUMENTATION_VCD_WRITE
(
"r%d p%d.%d
\n
"
,
__po_hi_gqueues_used_size
[
id
][
port
],
id
,
port
);
if
(
__po_hi_gqueues_used_size
[
id
][
port
]
==
0
)
{
...
...
@@ -600,8 +611,8 @@ int __po_hi_gqueue_next_value (__po_hi_task_id id, __po_hi_local_port_t port)
__po_hi_gqueues_queue_is_empty
[
id
]
=
1
;
}
__po_hi_gqueues_global_history_offset
[
id
]
=
(
__po_hi_gqueues_global_history_offset
[
id
]
+
1
)
__po_hi_gqueues_global_history_offset
[
id
]
=
(
__po_hi_gqueues_global_history_offset
[
id
]
+
1
)
%
__po_hi_gqueues_total_fifo_size
[
id
];
#if defined (POSIX) || defined (RTEMS_POSIX) || defined (XENO_POSIX)
...
...
@@ -635,4 +646,3 @@ __po_hi_port_t __po_hi_gqueue_get_destination (const __po_hi_task_id task_id, co
{
return
(
__po_hi_gqueues_destinations
[
task_id
][
local_port
][
destination_number
]);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment