From 23fec9f0e18dc4913fab818118f836af150b98f3 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 27 Mar 2014 14:16:12 +0100 Subject: score: PR2152: Use allocator mutex for objects Use allocator mutex for objects allocate/free. This prevents that the thread dispatch latency depends on the workspace/heap fragmentation. --- cpukit/posix/include/rtems/posix/pthreadimpl.h | 21 +++++---------------- cpukit/posix/include/rtems/posix/semaphoreimpl.h | 13 +++---------- cpukit/posix/src/conddestroy.c | 8 ++++++-- cpukit/posix/src/condinit.c | 6 ++---- cpukit/posix/src/keycreate.c | 6 ++---- cpukit/posix/src/keydelete.c | 4 ++++ cpukit/posix/src/mqueueclose.c | 4 ++++ cpukit/posix/src/mqueuecreatesupp.c | 12 ++++-------- cpukit/posix/src/mqueueopen.c | 14 ++++++-------- cpukit/posix/src/mqueueunlink.c | 3 +++ cpukit/posix/src/mutexdestroy.c | 10 +++++++--- cpukit/posix/src/mutexinit.c | 9 ++------- cpukit/posix/src/pbarrierdestroy.c | 7 +++++-- cpukit/posix/src/pbarrierinit.c | 12 ++---------- cpukit/posix/src/prwlockdestroy.c | 8 ++++++-- cpukit/posix/src/prwlockinit.c | 9 ++------- cpukit/posix/src/pspindestroy.c | 7 +++++-- cpukit/posix/src/pspininit.c | 7 ++----- cpukit/posix/src/pthreadcreate.c | 13 ++++--------- cpukit/posix/src/semaphorecreatesupp.c | 7 +------ cpukit/posix/src/semclose.c | 4 ++++ cpukit/posix/src/semdestroy.c | 4 ++++ cpukit/posix/src/seminit.c | 2 ++ cpukit/posix/src/semopen.c | 11 +++++------ cpukit/posix/src/semunlink.c | 11 +++++++---- cpukit/posix/src/timercreate.c | 8 +++----- cpukit/posix/src/timerdelete.c | 7 ++++++- 27 files changed, 106 insertions(+), 121 deletions(-) (limited to 'cpukit/posix') diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h index 02d8bca0f5..d4a04e1281 100644 --- a/cpukit/posix/include/rtems/posix/pthreadimpl.h +++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h @@ -67,16 +67,6 @@ extern void (*_POSIX_Threads_Initialize_user_threads_p)(void); */ void _POSIX_Threads_Manager_initialization(void); -/** - * @brief Allocate POSIX thread control block. - * - * This function allocates a pthread control block from - * the inactive chain of free pthread control blocks. - * - * @return This method returns a newly allocated thread. - */ -RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void ); - /** * @brief Copy POSIX Thread attribute structure. * @@ -211,15 +201,14 @@ int rtems_pthread_attribute_compare( const pthread_attr_t *attr2 ); -/* - * _POSIX_Threads_Allocate - */ - -RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void ) +RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void) { + _Objects_Allocator_lock(); + _Thread_Kill_zombies(); - return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information ); + return (Thread_Control *) + _Objects_Allocate_unprotected( &_POSIX_Threads_Information ); } /* diff --git a/cpukit/posix/include/rtems/posix/semaphoreimpl.h b/cpukit/posix/include/rtems/posix/semaphoreimpl.h index 7754ee9ad7..df5e5238de 100644 --- a/cpukit/posix/include/rtems/posix/semaphoreimpl.h +++ b/cpukit/posix/include/rtems/posix/semaphoreimpl.h @@ -48,20 +48,13 @@ extern const int */ void _POSIX_Semaphore_Manager_initialization(void); -/** - * @brief POSIX Semaphore Allocate - * - * This function allocates a semaphore control block from - * the inactive chain of free semaphore control blocks. - */ - -RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void ) +RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control * + _POSIX_Semaphore_Allocate_unprotected( void ) { return (POSIX_Semaphore_Control *) - _Objects_Allocate( &_POSIX_Semaphore_Information ); + _Objects_Allocate_unprotected( &_POSIX_Semaphore_Information ); } - /** * @brief POSIX Semaphore Free * diff --git a/cpukit/posix/src/conddestroy.c b/cpukit/posix/src/conddestroy.c index 75bf4cd621..cd437a9114 100644 --- a/cpukit/posix/src/conddestroy.c +++ b/cpukit/posix/src/conddestroy.c @@ -38,6 +38,7 @@ int pthread_cond_destroy( POSIX_Condition_variables_Control *the_cond; Objects_Locations location; + _Objects_Allocator_lock(); the_cond = _POSIX_Condition_variables_Get( cond, &location ); switch ( location ) { @@ -45,6 +46,7 @@ int pthread_cond_destroy( if ( _Thread_queue_First( &the_cond->Wait_queue ) ) { _Objects_Put( &the_cond->Object ); + _Objects_Allocator_unlock(); return EBUSY; } @@ -52,9 +54,9 @@ int pthread_cond_destroy( &_POSIX_Condition_variables_Information, &the_cond->Object ); - - _POSIX_Condition_variables_Free( the_cond ); _Objects_Put( &the_cond->Object ); + _POSIX_Condition_variables_Free( the_cond ); + _Objects_Allocator_unlock(); return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -64,5 +66,7 @@ int pthread_cond_destroy( break; } + _Objects_Allocator_unlock(); + return EINVAL; } diff --git a/cpukit/posix/src/condinit.c b/cpukit/posix/src/condinit.c index a69bc8cfdc..81575f2b17 100644 --- a/cpukit/posix/src/condinit.c +++ b/cpukit/posix/src/condinit.c @@ -51,12 +51,10 @@ int pthread_cond_init( if ( !the_attr->is_initialized ) return EINVAL; - _Thread_Disable_dispatch(); - the_cond = _POSIX_Condition_variables_Allocate(); if ( !the_cond ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return ENOMEM; } @@ -79,7 +77,7 @@ int pthread_cond_init( *cond = the_cond->Object.id; - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/keycreate.c b/cpukit/posix/src/keycreate.c index a7f6c915cc..245ac9e3f3 100644 --- a/cpukit/posix/src/keycreate.c +++ b/cpukit/posix/src/keycreate.c @@ -38,18 +38,16 @@ int pthread_key_create( { POSIX_Keys_Control *the_key; - _Thread_Disable_dispatch(); - the_key = _POSIX_Keys_Allocate(); if ( !the_key ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return EAGAIN; } the_key->destructor = destructor; _Objects_Open_u32( &_POSIX_Keys_Information, &the_key->Object, 0 ); *key = the_key->Object.id; - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/keydelete.c b/cpukit/posix/src/keydelete.c index cd2b39802d..392558f0f8 100644 --- a/cpukit/posix/src/keydelete.c +++ b/cpukit/posix/src/keydelete.c @@ -38,6 +38,7 @@ int pthread_key_delete( POSIX_Keys_Control *the_key; Objects_Locations location; + _Objects_Allocator_lock(); the_key = _POSIX_Keys_Get( key, &location ); switch ( location ) { @@ -50,6 +51,7 @@ int pthread_key_delete( */ _POSIX_Keys_Free( the_key ); _Objects_Put(&the_key->Object); + _Objects_Allocator_unlock(); return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -59,5 +61,7 @@ int pthread_key_delete( break; } + _Objects_Allocator_unlock(); + return EINVAL; } diff --git a/cpukit/posix/src/mqueueclose.c b/cpukit/posix/src/mqueueclose.c index 152fc7ec46..72a7cdc40e 100644 --- a/cpukit/posix/src/mqueueclose.c +++ b/cpukit/posix/src/mqueueclose.c @@ -57,6 +57,7 @@ int mq_close( POSIX_Message_queue_Control_fd *the_mq_fd; Objects_Locations location; + _Objects_Allocator_lock(); the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); if ( location == OBJECTS_LOCAL ) { /* OBJECTS_LOCAL: @@ -79,9 +80,12 @@ int mq_close( _POSIX_Message_queue_Free_fd( the_mq_fd ); _Objects_Put( &the_mq_fd->Object ); + _Objects_Allocator_unlock(); return 0; } + _Objects_Allocator_unlock(); + /* * OBJECTS_REMOTE: * OBJECTS_ERROR: diff --git a/cpukit/posix/src/mqueuecreatesupp.c b/cpukit/posix/src/mqueuecreatesupp.c index 056d35df1b..3be64b4cc4 100644 --- a/cpukit/posix/src/mqueuecreatesupp.c +++ b/cpukit/posix/src/mqueuecreatesupp.c @@ -62,8 +62,6 @@ int _POSIX_Message_queue_Create_support( /* length of name has already been validated */ - _Thread_Disable_dispatch(); - /* * There is no real basis for the default values. They will work * but were not compared against any existing implementation for @@ -75,12 +73,10 @@ int _POSIX_Message_queue_Create_support( attr.mq_msgsize = 16; } else { if ( attr_ptr->mq_maxmsg <= 0 ){ - _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( EINVAL ); } if ( attr_ptr->mq_msgsize <= 0 ){ - _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( EINVAL ); } @@ -89,7 +85,7 @@ int _POSIX_Message_queue_Create_support( the_mq = _POSIX_Message_queue_Allocate(); if ( !the_mq ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one( ENFILE ); } @@ -100,7 +96,7 @@ int _POSIX_Message_queue_Create_support( name = _Workspace_String_duplicate( name_arg, name_len ); if ( !name ) { _POSIX_Message_queue_Free( the_mq ); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one( ENOMEM ); } @@ -128,7 +124,7 @@ int _POSIX_Message_queue_Create_support( _POSIX_Message_queue_Free( the_mq ); _Workspace_Free(name); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one( ENOSPC ); } @@ -140,6 +136,6 @@ int _POSIX_Message_queue_Create_support( *message_queue = the_mq; - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c index b33fc95d7a..43e4082b63 100644 --- a/cpukit/posix/src/mqueueopen.c +++ b/cpukit/posix/src/mqueueopen.c @@ -72,8 +72,6 @@ mqd_t mq_open( Objects_Locations location; size_t name_len; - _Thread_Disable_dispatch(); - if ( oflag & O_CREAT ) { va_start(arg, oflag); mode = va_arg( arg, mode_t ); @@ -83,7 +81,7 @@ mqd_t mq_open( the_mq_fd = _POSIX_Message_queue_Allocate_fd(); if ( !the_mq_fd ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one( ENFILE ); } the_mq_fd->oflag = oflag; @@ -103,7 +101,7 @@ mqd_t mq_open( */ if ( !( status == ENOENT && (oflag & O_CREAT) ) ) { _POSIX_Message_queue_Free_fd( the_mq_fd ); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one_cast( status, mqd_t ); } @@ -113,7 +111,7 @@ mqd_t mq_open( */ if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { _POSIX_Message_queue_Free_fd( the_mq_fd ); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t ); } @@ -130,7 +128,7 @@ mqd_t mq_open( NULL ); _Thread_Enable_dispatch(); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return (mqd_t)the_mq_fd->Object.id; } @@ -152,7 +150,7 @@ mqd_t mq_open( */ if ( status == -1 ) { _POSIX_Message_queue_Free_fd( the_mq_fd ); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return (mqd_t) -1; } @@ -163,7 +161,7 @@ mqd_t mq_open( NULL ); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return (mqd_t) the_mq_fd->Object.id; } diff --git a/cpukit/posix/src/mqueueunlink.c b/cpukit/posix/src/mqueueunlink.c index 47a0f5a368..92b1976a43 100644 --- a/cpukit/posix/src/mqueueunlink.c +++ b/cpukit/posix/src/mqueueunlink.c @@ -46,11 +46,13 @@ int mq_unlink( Objects_Id the_mq_id; size_t name_len; + _Objects_Allocator_lock(); _Thread_Disable_dispatch(); status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id, &name_len ); if ( status != 0 ) { _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one( status ); } @@ -64,5 +66,6 @@ int mq_unlink( _POSIX_Message_queue_Delete( the_mq ); _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/mutexdestroy.c b/cpukit/posix/src/mutexdestroy.c index 0fad9a915f..fce78af715 100644 --- a/cpukit/posix/src/mutexdestroy.c +++ b/cpukit/posix/src/mutexdestroy.c @@ -39,6 +39,7 @@ int pthread_mutex_destroy( register POSIX_Mutex_Control *the_mutex; Objects_Locations location; + _Objects_Allocator_lock(); the_mutex = _POSIX_Mutex_Get( mutex, &location ); switch ( location ) { @@ -50,15 +51,16 @@ int pthread_mutex_destroy( if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) { _Objects_Put( &the_mutex->Object ); + _Objects_Allocator_unlock(); return EBUSY; } _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object ); - _CORE_mutex_Flush( &the_mutex->Mutex, NULL, EINVAL ); - - _POSIX_Mutex_Free( the_mutex ); _Objects_Put( &the_mutex->Object ); + _POSIX_Mutex_Free( the_mutex ); + _Objects_Allocator_unlock(); + return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -68,5 +70,7 @@ int pthread_mutex_destroy( break; } + _Objects_Allocator_unlock(); + return EINVAL; } diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c index d41b4c79ba..73d3101b28 100644 --- a/cpukit/posix/src/mutexinit.c +++ b/cpukit/posix/src/mutexinit.c @@ -149,15 +149,10 @@ int pthread_mutex_init( } #endif - /* - * Enter a dispatching critical section and begin to do the real work. - */ - _Thread_Disable_dispatch(); - the_mutex = _POSIX_Mutex_Allocate(); if ( !the_mutex ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return EAGAIN; } @@ -188,6 +183,6 @@ int pthread_mutex_init( *mutex = the_mutex->Object.id; - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/pbarrierdestroy.c b/cpukit/posix/src/pbarrierdestroy.c index d2eb50530d..4b9a0fdca9 100644 --- a/cpukit/posix/src/pbarrierdestroy.c +++ b/cpukit/posix/src/pbarrierdestroy.c @@ -45,6 +45,7 @@ int pthread_barrier_destroy( if ( !barrier ) return EINVAL; + _Objects_Allocator_lock(); the_barrier = _POSIX_Barrier_Get( barrier, &location ); switch ( location ) { @@ -55,10 +56,10 @@ int pthread_barrier_destroy( } _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object ); + _Objects_Put( &the_barrier->Object ); _POSIX_Barrier_Free( the_barrier ); - - _Objects_Put( &the_barrier->Object ); + _Objects_Allocator_unlock(); return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -68,5 +69,7 @@ int pthread_barrier_destroy( break; } + _Objects_Allocator_unlock(); + return EINVAL; } diff --git a/cpukit/posix/src/pbarrierinit.c b/cpukit/posix/src/pbarrierinit.c index f2dda7827b..956085658b 100644 --- a/cpukit/posix/src/pbarrierinit.c +++ b/cpukit/posix/src/pbarrierinit.c @@ -92,15 +92,10 @@ int pthread_barrier_init( the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE; the_attributes.maximum_count = count; - /* - * Enter dispatching critical section to allocate and initialize barrier - */ - _Thread_Disable_dispatch(); /* prevents deletion */ - the_barrier = _POSIX_Barrier_Allocate(); if ( !the_barrier ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return EAGAIN; } @@ -112,10 +107,7 @@ int pthread_barrier_init( 0 ); - /* - * Exit the critical section and return the user an operational barrier - */ *barrier = the_barrier->Object.id; - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/prwlockdestroy.c b/cpukit/posix/src/prwlockdestroy.c index 9054e921de..d1261ca4fb 100644 --- a/cpukit/posix/src/prwlockdestroy.c +++ b/cpukit/posix/src/prwlockdestroy.c @@ -44,6 +44,7 @@ int pthread_rwlock_destroy( if ( !rwlock ) return EINVAL; + _Objects_Allocator_lock(); the_rwlock = _POSIX_RWLock_Get( rwlock, &location ); switch ( location ) { @@ -53,6 +54,7 @@ int pthread_rwlock_destroy( */ if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) { _Objects_Put( &the_rwlock->Object ); + _Objects_Allocator_unlock(); return EBUSY; } @@ -61,10 +63,10 @@ int pthread_rwlock_destroy( */ _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object ); - + _Objects_Put( &the_rwlock->Object ); _POSIX_RWLock_Free( the_rwlock ); + _Objects_Allocator_unlock(); - _Objects_Put( &the_rwlock->Object ); return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -74,5 +76,7 @@ int pthread_rwlock_destroy( break; } + _Objects_Allocator_unlock(); + return EINVAL; } diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c index 488b46b8c4..94973f6b78 100644 --- a/cpukit/posix/src/prwlockinit.c +++ b/cpukit/posix/src/prwlockinit.c @@ -88,15 +88,10 @@ int pthread_rwlock_init( */ _CORE_RWLock_Initialize_attributes( &the_attributes ); - /* - * Enter dispatching critical section to allocate and initialize RWLock - */ - _Thread_Disable_dispatch(); /* prevents deletion */ - the_rwlock = _POSIX_RWLock_Allocate(); if ( !the_rwlock ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return EAGAIN; } @@ -110,6 +105,6 @@ int pthread_rwlock_init( *rwlock = the_rwlock->Object.id; - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/pspindestroy.c b/cpukit/posix/src/pspindestroy.c index 7795a33764..ab45ad1e92 100644 --- a/cpukit/posix/src/pspindestroy.c +++ b/cpukit/posix/src/pspindestroy.c @@ -45,6 +45,7 @@ int pthread_spin_destroy( if ( !spinlock ) return EINVAL; + _Objects_Allocator_lock(); the_spinlock = _POSIX_Spinlock_Get( spinlock, &location ); switch ( location ) { @@ -55,10 +56,10 @@ int pthread_spin_destroy( } _Objects_Close( &_POSIX_Spinlock_Information, &the_spinlock->Object ); - + _Objects_Put( &the_spinlock->Object ); _POSIX_Spinlock_Free( the_spinlock ); + _Objects_Allocator_unlock(); - _Objects_Put( &the_spinlock->Object ); return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -68,5 +69,7 @@ int pthread_spin_destroy( break; } + _Objects_Allocator_unlock(); + return EINVAL; } diff --git a/cpukit/posix/src/pspininit.c b/cpukit/posix/src/pspininit.c index 6030ed00e5..02b07c8468 100644 --- a/cpukit/posix/src/pspininit.c +++ b/cpukit/posix/src/pspininit.c @@ -49,7 +49,6 @@ int pthread_spin_init( POSIX_Spinlock_Control *the_spinlock; CORE_spinlock_Attributes attributes; - if ( !spinlock ) return EINVAL; @@ -61,12 +60,10 @@ int pthread_spin_init( return EINVAL; } - _Thread_Disable_dispatch(); /* prevents deletion */ - the_spinlock = _POSIX_Spinlock_Allocate(); if ( !the_spinlock ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return EAGAIN; } @@ -78,6 +75,6 @@ int pthread_spin_init( *spinlock = the_spinlock->Object.id; - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c index 5a6d929959..8d031335cc 100644 --- a/cpukit/posix/src/pthreadcreate.c +++ b/cpukit/posix/src/pthreadcreate.c @@ -155,11 +155,6 @@ int pthread_create( is_fp = false; #endif - /* - * Lock the allocator mutex for protection - */ - _RTEMS_Lock_allocator(); - /* * Allocate the thread control block. * @@ -167,7 +162,7 @@ int pthread_create( */ the_thread = _POSIX_Threads_Allocate(); if ( !the_thread ) { - _RTEMS_Unlock_allocator(); + _Objects_Allocator_unlock(); return EAGAIN; } @@ -190,7 +185,7 @@ int pthread_create( ); if ( !status ) { _POSIX_Threads_Free( the_thread ); - _RTEMS_Unlock_allocator(); + _Objects_Allocator_unlock(); return EAGAIN; } @@ -235,7 +230,7 @@ int pthread_create( if ( !status ) { _Thread_Enable_dispatch(); _POSIX_Threads_Free( the_thread ); - _RTEMS_Unlock_allocator(); + _Objects_Allocator_unlock(); return EINVAL; } #endif @@ -254,6 +249,6 @@ int pthread_create( */ *thread = the_thread->Object.id; - _RTEMS_Unlock_allocator(); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/semaphorecreatesupp.c b/cpukit/posix/src/semaphorecreatesupp.c index 54b5b46aee..7751a58c0e 100644 --- a/cpukit/posix/src/semaphorecreatesupp.c +++ b/cpukit/posix/src/semaphorecreatesupp.c @@ -56,11 +56,8 @@ int _POSIX_Semaphore_Create_support( if (pshared != 0) rtems_set_errno_and_return_minus_one( ENOSYS ); - _Thread_Disable_dispatch(); - - the_semaphore = _POSIX_Semaphore_Allocate(); + the_semaphore = _POSIX_Semaphore_Allocate_unprotected(); if ( !the_semaphore ) { - _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( ENOSPC ); } @@ -72,7 +69,6 @@ int _POSIX_Semaphore_Create_support( name = _Workspace_String_duplicate( name_arg, name_len ); if ( !name ) { _POSIX_Semaphore_Free( the_semaphore ); - _Thread_Enable_dispatch(); rtems_set_errno_and_return_minus_one( ENOMEM ); } } else { @@ -120,6 +116,5 @@ int _POSIX_Semaphore_Create_support( *the_sem = the_semaphore; - _Thread_Enable_dispatch(); return 0; } diff --git a/cpukit/posix/src/semclose.c b/cpukit/posix/src/semclose.c index 1c205bfb36..9dedc34c1a 100644 --- a/cpukit/posix/src/semclose.c +++ b/cpukit/posix/src/semclose.c @@ -38,6 +38,7 @@ int sem_close( POSIX_Semaphore_Control *the_semaphore; Objects_Locations location; + _Objects_Allocator_lock(); the_semaphore = _POSIX_Semaphore_Get( sem, &location ); switch ( location ) { @@ -45,6 +46,7 @@ int sem_close( the_semaphore->open_count -= 1; _POSIX_Semaphore_Delete( the_semaphore ); _Objects_Put( &the_semaphore->Object ); + _Objects_Allocator_unlock(); return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -54,5 +56,7 @@ int sem_close( break; } + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EINVAL ); } diff --git a/cpukit/posix/src/semdestroy.c b/cpukit/posix/src/semdestroy.c index 8c3f079f64..1c695bb837 100644 --- a/cpukit/posix/src/semdestroy.c +++ b/cpukit/posix/src/semdestroy.c @@ -38,6 +38,7 @@ int sem_destroy( POSIX_Semaphore_Control *the_semaphore; Objects_Locations location; + _Objects_Allocator_lock(); the_semaphore = _POSIX_Semaphore_Get( sem, &location ); switch ( location ) { @@ -53,6 +54,7 @@ int sem_destroy( _POSIX_Semaphore_Delete( the_semaphore ); _Objects_Put( &the_semaphore->Object ); + _Objects_Allocator_unlock(); return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -62,5 +64,7 @@ int sem_destroy( break; } + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EINVAL ); } diff --git a/cpukit/posix/src/seminit.c b/cpukit/posix/src/seminit.c index 466b2d0a0c..a55a1c4e1b 100644 --- a/cpukit/posix/src/seminit.c +++ b/cpukit/posix/src/seminit.c @@ -47,6 +47,7 @@ int sem_init( if ( !sem ) rtems_set_errno_and_return_minus_one( EINVAL ); + _Objects_Allocator_lock(); status = _POSIX_Semaphore_Create_support( NULL, 0, @@ -54,6 +55,7 @@ int sem_init( value, &the_semaphore ); + _Objects_Allocator_unlock(); if ( status != -1 ) *sem = the_semaphore->Object.id; diff --git a/cpukit/posix/src/semopen.c b/cpukit/posix/src/semopen.c index 20e2e92c7b..0b98ca60f9 100644 --- a/cpukit/posix/src/semopen.c +++ b/cpukit/posix/src/semopen.c @@ -66,8 +66,6 @@ sem_t *sem_open( Objects_Locations location; size_t name_len; - _Thread_Disable_dispatch(); - if ( oflag & O_CREAT ) { va_start(arg, oflag); mode = va_arg( arg, mode_t ); @@ -75,6 +73,7 @@ sem_t *sem_open( va_end(arg); } + _Objects_Allocator_lock(); status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len ); /* @@ -92,7 +91,7 @@ sem_t *sem_open( */ if ( !( status == ENOENT && (oflag & O_CREAT) ) ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one_cast( status, sem_t * ); } } else { @@ -102,14 +101,14 @@ sem_t *sem_open( */ if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one_cast( EEXIST, sem_t * ); } the_semaphore = _POSIX_Semaphore_Get( (sem_t *) &the_semaphore_id, &location ); the_semaphore->open_count += 1; _Thread_Enable_dispatch(); - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); goto return_id; } @@ -130,7 +129,7 @@ sem_t *sem_open( * errno was set by Create_support, so don't set it again. */ - _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); if ( status == -1 ) return SEM_FAILED; diff --git a/cpukit/posix/src/semunlink.c b/cpukit/posix/src/semunlink.c index 180facc381..40d5660350 100644 --- a/cpukit/posix/src/semunlink.c +++ b/cpukit/posix/src/semunlink.c @@ -35,11 +35,12 @@ int sem_unlink( const char *name ) { - int status; - POSIX_Semaphore_Control *the_semaphore; - Objects_Id the_semaphore_id; - size_t name_len; + int status; + POSIX_Semaphore_Control *the_semaphore; + Objects_Id the_semaphore_id; + size_t name_len; + _Objects_Allocator_lock(); _Thread_Disable_dispatch(); status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len ); @@ -58,5 +59,7 @@ int sem_unlink( _POSIX_Semaphore_Delete( the_semaphore ); _Thread_Enable_dispatch(); + _Objects_Allocator_unlock(); + return 0; } diff --git a/cpukit/posix/src/timercreate.c b/cpukit/posix/src/timercreate.c index f55e2db8d6..6d822b3928 100644 --- a/cpukit/posix/src/timercreate.c +++ b/cpukit/posix/src/timercreate.c @@ -66,21 +66,19 @@ int timer_create( rtems_set_errno_and_return_minus_one( EINVAL ); } - _Thread_Disable_dispatch(); /* to prevent deletion */ - /* * Allocate a timer */ ptimer = _POSIX_Timer_Allocate(); if ( !ptimer ) { - _Objects_Put( &ptimer->Object ); + _Objects_Allocator_unlock(); rtems_set_errno_and_return_minus_one( EAGAIN ); } /* The data of the created timer are stored to use them later */ ptimer->state = POSIX_TIMER_STATE_CREATE_NEW; - ptimer->thread_id = _Thread_Executing->Object.id; + ptimer->thread_id = _Thread_Get_executing()->Object.id; if ( evp != NULL ) { ptimer->inf.sigev_notify = evp->sigev_notify; @@ -98,6 +96,6 @@ int timer_create( _Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0); *timerid = ptimer->Object.id; - _Objects_Put( &ptimer->Object ); + _Objects_Allocator_unlock(); return 0; } diff --git a/cpukit/posix/src/timerdelete.c b/cpukit/posix/src/timerdelete.c index 5ebf8f8660..71b25faed9 100644 --- a/cpukit/posix/src/timerdelete.c +++ b/cpukit/posix/src/timerdelete.c @@ -47,6 +47,7 @@ int timer_delete( POSIX_Timer_Control *ptimer; Objects_Locations location; + _Objects_Allocator_lock(); ptimer = _POSIX_Timer_Get( timerid, &location ); switch ( location ) { @@ -54,8 +55,10 @@ int timer_delete( _Objects_Close( &_POSIX_Timer_Information, &ptimer->Object ); ptimer->state = POSIX_TIMER_STATE_FREE; (void) _Watchdog_Remove( &ptimer->Timer ); - _POSIX_Timer_Free( ptimer ); _Objects_Put( &ptimer->Object ); + _POSIX_Timer_Free( ptimer ); + _Objects_Allocator_unlock(); + return 0; #if defined(RTEMS_MULTIPROCESSING) @@ -65,5 +68,7 @@ int timer_delete( break; } + _Objects_Allocator_unlock(); + rtems_set_errno_and_return_minus_one( EINVAL ); } -- cgit v1.2.3