From 7f4ee2b4ae39928ab5f449048e562ef6b2c5d17d Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 22 Apr 2016 14:37:13 +0200 Subject: posix: Avoid Giant lock for condition variables Update #2555. --- cpukit/posix/src/conddestroy.c | 55 +++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'cpukit/posix/src/conddestroy.c') 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 -#include - -#include -#include #include -#include /** * 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; } -- cgit v1.2.3