summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/conddestroy.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-22 14:37:13 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-27 08:50:41 +0200
commit7f4ee2b4ae39928ab5f449048e562ef6b2c5d17d (patch)
treeec62caff9b95826169b43cc8a8e66b24fa861015 /cpukit/posix/src/conddestroy.c
parenttelnetd: Fix warnings (diff)
downloadrtems-7f4ee2b4ae39928ab5f449048e562ef6b2c5d17d.tar.bz2
posix: Avoid Giant lock for condition variables
Update #2555.
Diffstat (limited to 'cpukit/posix/src/conddestroy.c')
-rw-r--r--cpukit/posix/src/conddestroy.c55
1 files changed, 19 insertions, 36 deletions
diff --git a/cpukit/posix/src/conddestroy.c b/cpukit/posix/src/conddestroy.c
index c6696f506c..d47c6b2bed 100644
--- a/cpukit/posix/src/conddestroy.c
+++ b/cpukit/posix/src/conddestroy.c
@@ -18,13 +18,7 @@
#include "config.h"
#endif
-#include <pthread.h>
-#include <errno.h>
-
-#include <rtems/system.h>
-#include <rtems/score/watchdog.h>
#include <rtems/posix/condimpl.h>
-#include <rtems/posix/muteximpl.h>
/**
* 11.4.2 Initializing and Destroying a Condition Variable,
@@ -35,42 +29,31 @@ int pthread_cond_destroy(
)
{
POSIX_Condition_variables_Control *the_cond;
- Objects_Locations location;
+ ISR_lock_Context lock_context;
_Objects_Allocator_lock();
- the_cond = _POSIX_Condition_variables_Get( cond, &location );
- switch ( location ) {
-
- case OBJECTS_LOCAL:
+ the_cond = _POSIX_Condition_variables_Get( cond, &lock_context );
- if (
- _Thread_queue_First(
- &the_cond->Wait_queue,
- POSIX_CONDITION_VARIABLES_TQ_OPERATIONS
- )
- ) {
- _Objects_Put( &the_cond->Object );
- _Objects_Allocator_unlock();
- return EBUSY;
- }
+ if ( the_cond == NULL ) {
+ _Objects_Allocator_unlock();
+ return EINVAL;
+ }
- _Objects_Close(
- &_POSIX_Condition_variables_Information,
- &the_cond->Object
- );
- _Objects_Put( &the_cond->Object );
- _POSIX_Condition_variables_Free( the_cond );
- _Objects_Allocator_unlock();
- return 0;
+ _POSIX_Condition_variables_Acquire_critical( the_cond, &lock_context );
-#if defined(RTEMS_MULTIPROCESSING)
- case OBJECTS_REMOTE:
-#endif
- case OBJECTS_ERROR:
- break;
+ if ( !_Thread_queue_Is_empty( &the_cond->Wait_queue.Queue ) ) {
+ _POSIX_Condition_variables_Release( the_cond, &lock_context );
+ _Objects_Allocator_unlock();
+ return EBUSY;
}
+ _Objects_Close(
+ &_POSIX_Condition_variables_Information,
+ &the_cond->Object
+ );
+ _POSIX_Condition_variables_Release( the_cond, &lock_context );
+ _POSIX_Condition_variables_Destroy( the_cond );
+ _POSIX_Condition_variables_Free( the_cond );
_Objects_Allocator_unlock();
-
- return EINVAL;
+ return 0;
}