summaryrefslogtreecommitdiffstats
path: root/cpukit/posix
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-05-11 14:56:49 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-05-19 12:00:48 +0200
commitaa05cfbb3d6309ec45b69f34d0870465fe30b74c (patch)
treee004fe884c7018b81bf430b095af350b66f86f6f /cpukit/posix
parentscore: Add static initializers for thread queues (diff)
downloadrtems-aa05cfbb3d6309ec45b69f34d0870465fe30b74c.tar.bz2
score: Replace _Thread_Delay_ended()
Use _Thread_Timeout() instead. Use pseudo thread queue for nanosleep() to deal with signals. Close #2130.
Diffstat (limited to 'cpukit/posix')
-rw-r--r--cpukit/posix/src/nanosleep.c35
-rw-r--r--cpukit/posix/src/psignalunblockthread.c11
2 files changed, 18 insertions, 28 deletions
diff --git a/cpukit/posix/src/nanosleep.c b/cpukit/posix/src/nanosleep.c
index 39ae84d3e4..46697ae8fc 100644
--- a/cpukit/posix/src/nanosleep.c
+++ b/cpukit/posix/src/nanosleep.c
@@ -23,9 +23,13 @@
#include <rtems/seterr.h>
#include <rtems/score/threadimpl.h>
+#include <rtems/score/threadqimpl.h>
#include <rtems/score/timespec.h>
#include <rtems/score/watchdogimpl.h>
+static Thread_queue_Control _Nanosleep_Pseudo_queue =
+ THREAD_QUEUE_FIFO_INITIALIZER( _Nanosleep_Pseudo_queue, "Nanosleep" );
+
/*
* 14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269
*/
@@ -38,7 +42,8 @@ int nanosleep(
* It is critical to obtain the executing thread after thread dispatching is
* disabled on SMP configurations.
*/
- Thread_Control *executing;
+ Thread_Control *executing;
+ Per_CPU_Control *cpu_self;
Watchdog_Interval ticks;
Watchdog_Interval elapsed;
@@ -58,16 +63,17 @@ int nanosleep(
*/
ticks = _Timespec_To_ticks( rqtp );
+ executing = _Thread_Get_executing();
+
/*
* A nanosleep for zero time is implemented as a yield.
* This behavior is also beyond the POSIX specification but is
* consistent with the RTEMS API and yields desirable behavior.
*/
if ( !ticks ) {
- _Thread_Disable_dispatch();
- executing = _Thread_Executing;
+ cpu_self = _Thread_Dispatch_disable();
_Thread_Yield( executing );
- _Thread_Enable_dispatch();
+ _Thread_Dispatch_enable( cpu_self );
if ( rmtp ) {
rmtp->tv_sec = 0;
rmtp->tv_nsec = 0;
@@ -78,20 +84,13 @@ int nanosleep(
/*
* Block for the desired amount of time
*/
- _Thread_Disable_dispatch();
- executing = _Thread_Executing;
- _Thread_Set_state(
- executing,
- STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL
- );
- _Watchdog_Initialize(
- &executing->Timer,
- _Thread_Delay_ended,
- 0,
- executing
- );
- _Watchdog_Insert_ticks( &executing->Timer, ticks );
- _Thread_Enable_dispatch();
+ _Thread_queue_Enqueue(
+ &_Nanosleep_Pseudo_queue,
+ executing,
+ STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL,
+ ticks,
+ 0
+ );
/*
* Calculate the time that passed while we were sleeping and how
diff --git a/cpukit/posix/src/psignalunblockthread.c b/cpukit/posix/src/psignalunblockthread.c
index 3b310a90b7..200e9e714b 100644
--- a/cpukit/posix/src/psignalunblockthread.c
+++ b/cpukit/posix/src/psignalunblockthread.c
@@ -110,16 +110,7 @@ bool _POSIX_signals_Unblock_thread(
if ( _States_Is_interruptible_by_signal( the_thread->current_state ) ) {
the_thread->Wait.return_code = EINTR;
- /*
- * In pthread_cond_wait, a thread will be blocking on a thread
- * queue, but is also interruptible by a POSIX signal.
- */
- if ( _States_Is_delaying(the_thread->current_state) ) {
- _Watchdog_Remove_ticks( &the_thread->Timer );
- _Thread_Unblock( the_thread );
- } else {
- _Thread_queue_Extract_with_proxy( the_thread );
- }
+ _Thread_queue_Extract_with_proxy( the_thread );
}
}
return _POSIX_signals_Unblock_thread_done( the_thread, api, false );