[PATCH 17/17] score: PR2152: Use allocator mutex for objects
Sebastian Huber
sebastian.huber at embedded-brains.de
Tue Mar 25 12:49:21 UTC 2014
Use allocator mutex for objects allocate/free. This prevents that the
thread dispatch latency depends on the workspace/heap fragmentation.
---
cpukit/libcsupport/src/resource_snapshot.c | 25 ++++--------
cpukit/posix/include/rtems/posix/barrierimpl.h | 16 +++----
cpukit/posix/include/rtems/posix/condimpl.h | 14 ++----
cpukit/posix/include/rtems/posix/keyimpl.h | 16 +++----
cpukit/posix/include/rtems/posix/mqueueimpl.h | 27 +++++-------
cpukit/posix/include/rtems/posix/muteximpl.h | 15 +++----
cpukit/posix/include/rtems/posix/pthreadimpl.h | 23 +++-------
cpukit/posix/include/rtems/posix/rwlockimpl.h | 16 +++----
cpukit/posix/include/rtems/posix/semaphoreimpl.h | 10 +----
cpukit/posix/include/rtems/posix/spinlockimpl.h | 16 +++----
cpukit/posix/include/rtems/posix/timerimpl.h | 15 +++----
cpukit/posix/src/conddestroy.c | 9 +++-
cpukit/posix/src/condinit.c | 11 +++--
cpukit/posix/src/keycreate.c | 9 ++--
cpukit/posix/src/keydelete.c | 5 ++
cpukit/posix/src/mqueueclose.c | 5 ++
cpukit/posix/src/mqueuecreatesupp.c | 15 +++----
cpukit/posix/src/mqueueopen.c | 19 ++++----
cpukit/posix/src/mqueueunlink.c | 4 ++
cpukit/posix/src/mutexdestroy.c | 11 ++++-
cpukit/posix/src/mutexinit.c | 12 ++----
cpukit/posix/src/pbarrierdestroy.c | 8 +++-
cpukit/posix/src/pbarrierinit.c | 15 ++-----
cpukit/posix/src/prwlockdestroy.c | 9 +++-
cpukit/posix/src/prwlockinit.c | 12 ++----
cpukit/posix/src/pspindestroy.c | 8 +++-
cpukit/posix/src/pspininit.c | 10 ++---
cpukit/posix/src/pthreadcreate.c | 16 +++----
cpukit/posix/src/semaphorecreatesupp.c | 5 --
cpukit/posix/src/semclose.c | 5 ++
cpukit/posix/src/semdestroy.c | 5 ++
cpukit/posix/src/seminit.c | 3 +
cpukit/posix/src/semopen.c | 12 +++---
cpukit/posix/src/semunlink.c | 12 ++++--
cpukit/posix/src/timercreate.c | 11 ++---
cpukit/posix/src/timerdelete.c | 8 +++-
cpukit/rtems/Makefile.am | 1 -
cpukit/rtems/include/rtems/rtems/barrierimpl.h | 15 +++----
cpukit/rtems/include/rtems/rtems/dpmemimpl.h | 18 +++-----
cpukit/rtems/include/rtems/rtems/messageimpl.h | 20 ++++----
cpukit/rtems/include/rtems/rtems/partimpl.h | 16 +++----
cpukit/rtems/include/rtems/rtems/ratemonimpl.h | 17 +++----
cpukit/rtems/include/rtems/rtems/regionimpl.h | 20 +++++----
cpukit/rtems/include/rtems/rtems/semimpl.h | 16 +++----
cpukit/rtems/include/rtems/rtems/tasksimpl.h | 15 +++----
cpukit/rtems/include/rtems/rtems/timerimpl.h | 15 +++----
cpukit/rtems/src/barriercreate.c | 9 ++--
cpukit/rtems/src/barrierdelete.c | 9 +++-
cpukit/rtems/src/dpmemcreate.c | 11 ++---
cpukit/rtems/src/dpmemdelete.c | 7 +++-
cpukit/rtems/src/msgqallocate.c | 37 ----------------
cpukit/rtems/src/msgqcreate.c | 14 +++---
cpukit/rtems/src/msgqdelete.c | 10 +++-
cpukit/rtems/src/partcreate.c | 13 +++---
cpukit/rtems/src/partdelete.c | 10 ++++-
cpukit/rtems/src/ratemoncreate.c | 11 ++---
cpukit/rtems/src/ratemondelete.c | 7 +++-
cpukit/rtems/src/regioncreate.c | 6 +--
cpukit/rtems/src/regiondelete.c | 4 +-
cpukit/rtems/src/regionextend.c | 6 ++-
cpukit/rtems/src/regiongetfreeinfo.c | 6 ++-
cpukit/rtems/src/regiongetinfo.c | 6 ++-
cpukit/rtems/src/regiongetsegment.c | 10 +++--
cpukit/rtems/src/regiongetsegmentsize.c | 6 ++-
cpukit/rtems/src/regionprocessqueue.c | 5 +-
cpukit/rtems/src/regionresizesegment.c | 10 +++--
cpukit/rtems/src/regionreturnsegment.c | 8 ++-
cpukit/rtems/src/semcreate.c | 15 +++----
cpukit/rtems/src/semdelete.c | 12 ++++-
cpukit/rtems/src/taskcreate.c | 16 +++----
cpukit/rtems/src/timercreate.c | 9 ++--
cpukit/rtems/src/timerdelete.c | 7 +++-
cpukit/sapi/include/rtems/extensionimpl.h | 9 +++-
cpukit/sapi/src/extensioncreate.c | 11 +++--
cpukit/sapi/src/extensiondelete.c | 7 +++-
cpukit/score/include/rtems/score/objectimpl.h | 33 ++++++++++++--
cpukit/score/include/rtems/score/threadimpl.h | 7 +--
cpukit/score/src/apimutex.c | 3 +-
cpukit/score/src/objectactivecount.c | 10 ++++-
cpukit/score/src/objectallocate.c | 30 ++++++++++++-
cpukit/score/src/objectextendinformation.c | 49 ++++++++++-----------
cpukit/score/src/objectfree.c | 5 ++-
cpukit/score/src/objectshrinkinformation.c | 5 ++-
testsuites/sptests/spobjgetnext/init.c | 3 +
84 files changed, 531 insertions(+), 490 deletions(-)
delete mode 100644 cpukit/rtems/src/msgqallocate.c
diff --git a/cpukit/libcsupport/src/resource_snapshot.c b/cpukit/libcsupport/src/resource_snapshot.c
index 8c66f0f..78aafb4 100644
--- a/cpukit/libcsupport/src/resource_snapshot.c
+++ b/cpukit/libcsupport/src/resource_snapshot.c
@@ -98,38 +98,29 @@ static int open_files(void)
return (int) rtems_libio_number_iops - free_count;
}
-static void free_all_delayed_blocks(void)
-{
- #ifdef HEAP_PROTECTION
- _RTEMS_Lock_allocator();
- _Thread_Disable_dispatch();
- _Heap_Protection_free_all_delayed_blocks( RTEMS_Malloc_Heap );
- _Heap_Protection_free_all_delayed_blocks( &_Workspace_Area );
- _Thread_Enable_dispatch();
- _RTEMS_Unlock_allocator();
- #endif
-}
-
void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
{
uint32_t *active = &snapshot->rtems_api.active_barriers;
size_t i;
+ bool previous_thread_life_protection;
- free_all_delayed_blocks();
+ previous_thread_life_protection = _RTEMS_Lock_allocator();
_Thread_Kill_zombies();
- _Protected_heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
-
- _Thread_Disable_dispatch();
+ #ifdef HEAP_PROTECTION
+ _Heap_Protection_free_all_delayed_blocks(RTEMS_Malloc_Heap);
+ _Heap_Protection_free_all_delayed_blocks(&_Workspace_Area);
+ #endif
+ _Heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
_Heap_Get_information(&_Workspace_Area, &snapshot->workspace_info);
for (i = 0; i < RTEMS_ARRAY_SIZE(objects_info_table); ++i) {
active [i] = _Objects_Active_count(objects_info_table[i]);
}
- _Thread_Enable_dispatch();
+ _RTEMS_Unlock_allocator(previous_thread_life_protection);
#ifndef RTEMS_POSIX_API
memset(&snapshot->posix_api, 0, sizeof(snapshot->posix_api));
diff --git a/cpukit/posix/include/rtems/posix/barrierimpl.h b/cpukit/posix/include/rtems/posix/barrierimpl.h
index af220b9..333ff3f 100644
--- a/cpukit/posix/include/rtems/posix/barrierimpl.h
+++ b/cpukit/posix/include/rtems/posix/barrierimpl.h
@@ -58,16 +58,14 @@ int _POSIX_Barrier_Translate_core_barrier_return_code(
CORE_barrier_Status the_barrier_status
);
-/**
- * @brief Allocate a barrier control block.
- *
- * This function allocates a barrier control block from
- * the inactive chain of free barrier control blocks.
- */
-RTEMS_INLINE_ROUTINE POSIX_Barrier_Control *_POSIX_Barrier_Allocate( void )
+RTEMS_INLINE_ROUTINE POSIX_Barrier_Control *_POSIX_Barrier_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (POSIX_Barrier_Control *)
- _Objects_Allocate( &_POSIX_Barrier_Information );
+ return (POSIX_Barrier_Control *) _Objects_Allocate(
+ &_POSIX_Barrier_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/include/rtems/posix/condimpl.h b/cpukit/posix/include/rtems/posix/condimpl.h
index 66f4f63..a2c635f 100644
--- a/cpukit/posix/include/rtems/posix/condimpl.h
+++ b/cpukit/posix/include/rtems/posix/condimpl.h
@@ -49,17 +49,13 @@ extern const pthread_condattr_t _POSIX_Condition_variables_Default_attributes;
*/
void _POSIX_Condition_variables_Manager_initialization(void);
-/**
- * @brief POSIX Condition Variable Allocate
- *
- * This function allocates a condition variable control block from
- * the inactive chain of free condition variable control blocks.
- */
RTEMS_INLINE_ROUTINE POSIX_Condition_variables_Control *
- _POSIX_Condition_variables_Allocate( void )
+ _POSIX_Condition_variables_Allocate( bool *previous_thread_life_protection )
{
- return (POSIX_Condition_variables_Control *)
- _Objects_Allocate( &_POSIX_Condition_variables_Information );
+ return (POSIX_Condition_variables_Control *) _Objects_Allocate(
+ &_POSIX_Condition_variables_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/include/rtems/posix/keyimpl.h b/cpukit/posix/include/rtems/posix/keyimpl.h
index 6aab244..e2a4d94 100644
--- a/cpukit/posix/include/rtems/posix/keyimpl.h
+++ b/cpukit/posix/include/rtems/posix/keyimpl.h
@@ -106,16 +106,14 @@ RTEMS_INLINE_ROUTINE void _POSIX_Keys_Free (
POSIX_Keys_Control *the_key
);
-/**
- * @brief Allocate a keys control block.
- *
- * This function allocates a keys control block from
- * the inactive chain of free keys control blocks.
- */
-
-RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate( void )
+RTEMS_INLINE_ROUTINE POSIX_Keys_Control *_POSIX_Keys_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (POSIX_Keys_Control *) _Objects_Allocate( &_POSIX_Keys_Information );
+ return (POSIX_Keys_Control *) _Objects_Allocate(
+ &_POSIX_Keys_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/include/rtems/posix/mqueueimpl.h b/cpukit/posix/include/rtems/posix/mqueueimpl.h
index a72a9e8..70a5fd8 100644
--- a/cpukit/posix/include/rtems/posix/mqueueimpl.h
+++ b/cpukit/posix/include/rtems/posix/mqueueimpl.h
@@ -121,17 +121,13 @@ int _POSIX_Message_queue_Send_support(
Watchdog_Interval timeout
);
-/**
- * @brief POSIX Message Queue Allocate
- *
- * This function allocates a message queue control block from
- * the inactive chain of free message queue control blocks.
- */
-RTEMS_INLINE_ROUTINE
- POSIX_Message_queue_Control *_POSIX_Message_queue_Allocate( void )
+RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control *
+ _POSIX_Message_queue_Allocate( bool *previous_thread_life_protection )
{
- return (POSIX_Message_queue_Control *)
- _Objects_Allocate( &_POSIX_Message_queue_Information );
+ return (POSIX_Message_queue_Control *) _Objects_Allocate(
+ &_POSIX_Message_queue_Information,
+ previous_thread_life_protection
+ );
}
/**
@@ -218,14 +214,13 @@ int _POSIX_Message_queue_Translate_core_message_queue_return_code(
uint32_t the_message_queue_status
);
-/**
- * @brief POSIX Message Queue Allocate File Descriptor
- */
RTEMS_INLINE_ROUTINE POSIX_Message_queue_Control_fd *
- _POSIX_Message_queue_Allocate_fd( void )
+ _POSIX_Message_queue_Allocate_fd( bool *previous_thread_life_protection )
{
- return (POSIX_Message_queue_Control_fd *)
- _Objects_Allocate( &_POSIX_Message_queue_Information_fds );
+ return (POSIX_Message_queue_Control_fd *) _Objects_Allocate(
+ &_POSIX_Message_queue_Information_fds,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/include/rtems/posix/muteximpl.h b/cpukit/posix/include/rtems/posix/muteximpl.h
index 05c80ce..90f5d60 100644
--- a/cpukit/posix/include/rtems/posix/muteximpl.h
+++ b/cpukit/posix/include/rtems/posix/muteximpl.h
@@ -51,15 +51,14 @@ extern const int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1];
*/
void _POSIX_Mutex_Manager_initialization(void);
-/**
- * @brief POSIX Mutex Allocate
- *
- * This function allocates a mutexes control block from
- * the inactive chain of free mutexes control blocks.
- */
-RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void )
+RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information );
+ return (POSIX_Mutex_Control *) _Objects_Allocate(
+ &_POSIX_Mutex_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/include/rtems/posix/pthreadimpl.h b/cpukit/posix/include/rtems/posix/pthreadimpl.h
index 02d8bca..8ad92c3 100644
--- a/cpukit/posix/include/rtems/posix/pthreadimpl.h
+++ b/cpukit/posix/include/rtems/posix/pthreadimpl.h
@@ -68,16 +68,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.
*
* This routine copies the attr2 thread attribute structure
@@ -211,15 +201,16 @@ 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(
+ bool *previous_thread_life_protection
+)
{
+ *previous_thread_life_protection = _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/rwlockimpl.h b/cpukit/posix/include/rtems/posix/rwlockimpl.h
index 2d6002a..5b8c088 100644
--- a/cpukit/posix/include/rtems/posix/rwlockimpl.h
+++ b/cpukit/posix/include/rtems/posix/rwlockimpl.h
@@ -67,16 +67,14 @@ int _POSIX_RWLock_Translate_core_RWLock_return_code(
CORE_RWLock_Status the_RWLock_status
);
-/**
- * @brief Allocate a RWLock control block.
- *
- * This function allocates a RWLock control block from
- * the inactive chain of free RWLock control blocks.
- */
-RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Allocate( void )
+RTEMS_INLINE_ROUTINE POSIX_RWLock_Control *_POSIX_RWLock_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (POSIX_RWLock_Control *)
- _Objects_Allocate( &_POSIX_RWLock_Information );
+ return (POSIX_RWLock_Control *) _Objects_Allocate(
+ &_POSIX_RWLock_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/include/rtems/posix/semaphoreimpl.h b/cpukit/posix/include/rtems/posix/semaphoreimpl.h
index 7754ee9..26fca50 100644
--- a/cpukit/posix/include/rtems/posix/semaphoreimpl.h
+++ b/cpukit/posix/include/rtems/posix/semaphoreimpl.h
@@ -48,20 +48,12 @@ 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 )
{
return (POSIX_Semaphore_Control *)
- _Objects_Allocate( &_POSIX_Semaphore_Information );
+ _Objects_Allocate_unprotected( &_POSIX_Semaphore_Information );
}
-
/**
* @brief POSIX Semaphore Free
*
diff --git a/cpukit/posix/include/rtems/posix/spinlockimpl.h b/cpukit/posix/include/rtems/posix/spinlockimpl.h
index 71a958d..1cdcae3 100644
--- a/cpukit/posix/include/rtems/posix/spinlockimpl.h
+++ b/cpukit/posix/include/rtems/posix/spinlockimpl.h
@@ -58,16 +58,14 @@ int _POSIX_Spinlock_Translate_core_spinlock_return_code(
CORE_spinlock_Status the_spinlock_status
);
-/**
- * @brief Allocate a spinlock control block.
- *
- * This function allocates a spinlock control block from
- * the inactive chain of free spinlock control blocks.
- */
-RTEMS_INLINE_ROUTINE POSIX_Spinlock_Control *_POSIX_Spinlock_Allocate( void )
+RTEMS_INLINE_ROUTINE POSIX_Spinlock_Control *_POSIX_Spinlock_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (POSIX_Spinlock_Control *)
- _Objects_Allocate( &_POSIX_Spinlock_Information );
+ return (POSIX_Spinlock_Control *) _Objects_Allocate(
+ &_POSIX_Spinlock_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/include/rtems/posix/timerimpl.h b/cpukit/posix/include/rtems/posix/timerimpl.h
index ff340d1..8c1f81d 100644
--- a/cpukit/posix/include/rtems/posix/timerimpl.h
+++ b/cpukit/posix/include/rtems/posix/timerimpl.h
@@ -81,15 +81,14 @@ bool _POSIX_Timer_Insert_helper(
*/
POSIX_EXTERN Objects_Information _POSIX_Timer_Information;
-/**
- * @brief POSIX Timer Allocate
- *
- * This function allocates a timer control block from
- * the inactive chain of free timer control blocks.
- */
-RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Allocate( void )
+RTEMS_INLINE_ROUTINE POSIX_Timer_Control *_POSIX_Timer_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (POSIX_Timer_Control *) _Objects_Allocate( &_POSIX_Timer_Information );
+ return (POSIX_Timer_Control *) _Objects_Allocate(
+ &_POSIX_Timer_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/posix/src/conddestroy.c b/cpukit/posix/src/conddestroy.c
index 75bf4cd..231b571 100644
--- a/cpukit/posix/src/conddestroy.c
+++ b/cpukit/posix/src/conddestroy.c
@@ -37,7 +37,9 @@ int pthread_cond_destroy(
{
POSIX_Condition_variables_Control *the_cond;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_cond = _POSIX_Condition_variables_Get( cond, &location );
switch ( location ) {
@@ -45,6 +47,7 @@ int pthread_cond_destroy(
if ( _Thread_queue_First( &the_cond->Wait_queue ) ) {
_Objects_Put( &the_cond->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EBUSY;
}
@@ -52,9 +55,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( previous_thread_life_protection );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -64,5 +67,7 @@ int pthread_cond_destroy(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return EINVAL;
}
diff --git a/cpukit/posix/src/condinit.c b/cpukit/posix/src/condinit.c
index a69bc8c..c134727 100644
--- a/cpukit/posix/src/condinit.c
+++ b/cpukit/posix/src/condinit.c
@@ -38,6 +38,7 @@ int pthread_cond_init(
{
POSIX_Condition_variables_Control *the_cond;
const pthread_condattr_t *the_attr;
+ bool previous_thread_life_protection;
if ( attr ) the_attr = attr;
else the_attr = &_POSIX_Condition_variables_Default_attributes;
@@ -51,12 +52,12 @@ int pthread_cond_init(
if ( !the_attr->is_initialized )
return EINVAL;
- _Thread_Disable_dispatch();
-
- the_cond = _POSIX_Condition_variables_Allocate();
+ the_cond = _POSIX_Condition_variables_Allocate(
+ &previous_thread_life_protection
+ );
if ( !the_cond ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return ENOMEM;
}
@@ -79,7 +80,7 @@ int pthread_cond_init(
*cond = the_cond->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/keycreate.c b/cpukit/posix/src/keycreate.c
index a7f6c91..74b53ea 100644
--- a/cpukit/posix/src/keycreate.c
+++ b/cpukit/posix/src/keycreate.c
@@ -37,19 +37,18 @@ int pthread_key_create(
)
{
POSIX_Keys_Control *the_key;
+ bool previous_thread_life_protection;
- _Thread_Disable_dispatch();
-
- the_key = _POSIX_Keys_Allocate();
+ the_key = _POSIX_Keys_Allocate( &previous_thread_life_protection );
if ( !the_key ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
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( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/keydelete.c b/cpukit/posix/src/keydelete.c
index cd2b398..1b50508 100644
--- a/cpukit/posix/src/keydelete.c
+++ b/cpukit/posix/src/keydelete.c
@@ -37,7 +37,9 @@ int pthread_key_delete(
{
POSIX_Keys_Control *the_key;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_key = _POSIX_Keys_Get( key, &location );
switch ( location ) {
@@ -50,6 +52,7 @@ int pthread_key_delete(
*/
_POSIX_Keys_Free( the_key );
_Objects_Put(&the_key->Object);
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -59,5 +62,7 @@ int pthread_key_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return EINVAL;
}
diff --git a/cpukit/posix/src/mqueueclose.c b/cpukit/posix/src/mqueueclose.c
index 152fc7e..f63d661 100644
--- a/cpukit/posix/src/mqueueclose.c
+++ b/cpukit/posix/src/mqueueclose.c
@@ -56,7 +56,9 @@ int mq_close(
POSIX_Message_queue_Control *the_mq;
POSIX_Message_queue_Control_fd *the_mq_fd;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
if ( location == OBJECTS_LOCAL ) {
/* OBJECTS_LOCAL:
@@ -79,9 +81,12 @@ int mq_close(
_POSIX_Message_queue_Free_fd( the_mq_fd );
_Objects_Put( &the_mq_fd->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
/*
* OBJECTS_REMOTE:
* OBJECTS_ERROR:
diff --git a/cpukit/posix/src/mqueuecreatesupp.c b/cpukit/posix/src/mqueuecreatesupp.c
index 056d35d..1714e4c 100644
--- a/cpukit/posix/src/mqueuecreatesupp.c
+++ b/cpukit/posix/src/mqueuecreatesupp.c
@@ -59,11 +59,10 @@ int _POSIX_Message_queue_Create_support(
CORE_message_queue_Attributes *the_mq_attr;
struct mq_attr attr;
char *name;
+ bool previous_thread_life_protection;
/* 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,21 +74,19 @@ 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 );
}
attr = *attr_ptr;
}
- the_mq = _POSIX_Message_queue_Allocate();
+ the_mq = _POSIX_Message_queue_Allocate( &previous_thread_life_protection );
if ( !the_mq ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one( ENFILE );
}
@@ -100,7 +97,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( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one( ENOMEM );
}
@@ -128,7 +125,7 @@ int _POSIX_Message_queue_Create_support(
_POSIX_Message_queue_Free( the_mq );
_Workspace_Free(name);
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one( ENOSPC );
}
@@ -140,6 +137,6 @@ int _POSIX_Message_queue_Create_support(
*message_queue = the_mq;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c
index b33fc95..53d6744 100644
--- a/cpukit/posix/src/mqueueopen.c
+++ b/cpukit/posix/src/mqueueopen.c
@@ -71,8 +71,7 @@ mqd_t mq_open(
POSIX_Message_queue_Control_fd *the_mq_fd;
Objects_Locations location;
size_t name_len;
-
- _Thread_Disable_dispatch();
+ bool previous_thread_life_protection;
if ( oflag & O_CREAT ) {
va_start(arg, oflag);
@@ -81,9 +80,11 @@ mqd_t mq_open(
va_end(arg);
}
- the_mq_fd = _POSIX_Message_queue_Allocate_fd();
+ the_mq_fd = _POSIX_Message_queue_Allocate_fd(
+ &previous_thread_life_protection
+ );
if ( !the_mq_fd ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one( ENFILE );
}
the_mq_fd->oflag = oflag;
@@ -103,7 +104,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( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one_cast( status, mqd_t );
}
@@ -113,7 +114,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( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
}
@@ -130,7 +131,7 @@ mqd_t mq_open(
NULL
);
_Thread_Enable_dispatch();
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return (mqd_t)the_mq_fd->Object.id;
}
@@ -152,7 +153,7 @@ mqd_t mq_open(
*/
if ( status == -1 ) {
_POSIX_Message_queue_Free_fd( the_mq_fd );
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return (mqd_t) -1;
}
@@ -163,7 +164,7 @@ mqd_t mq_open(
NULL
);
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return (mqd_t) the_mq_fd->Object.id;
}
diff --git a/cpukit/posix/src/mqueueunlink.c b/cpukit/posix/src/mqueueunlink.c
index 47a0f5a..3fa1389 100644
--- a/cpukit/posix/src/mqueueunlink.c
+++ b/cpukit/posix/src/mqueueunlink.c
@@ -45,12 +45,15 @@ int mq_unlink(
POSIX_Message_queue_Control *the_mq;
Objects_Id the_mq_id;
size_t name_len;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _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( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one( status );
}
@@ -64,5 +67,6 @@ int mq_unlink(
_POSIX_Message_queue_Delete( the_mq );
_Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/mutexdestroy.c b/cpukit/posix/src/mutexdestroy.c
index 0fad9a9..0de9449 100644
--- a/cpukit/posix/src/mutexdestroy.c
+++ b/cpukit/posix/src/mutexdestroy.c
@@ -38,7 +38,9 @@ int pthread_mutex_destroy(
{
register POSIX_Mutex_Control *the_mutex;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_mutex = _POSIX_Mutex_Get( mutex, &location );
switch ( location ) {
@@ -50,15 +52,16 @@ int pthread_mutex_destroy(
if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
_Objects_Put( &the_mutex->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
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( previous_thread_life_protection );
+
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -68,5 +71,7 @@ int pthread_mutex_destroy(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return EINVAL;
}
diff --git a/cpukit/posix/src/mutexinit.c b/cpukit/posix/src/mutexinit.c
index d41b4c7..5df9493 100644
--- a/cpukit/posix/src/mutexinit.c
+++ b/cpukit/posix/src/mutexinit.c
@@ -44,6 +44,7 @@ int pthread_mutex_init(
CORE_mutex_Attributes *the_mutex_attr;
const pthread_mutexattr_t *the_attr;
CORE_mutex_Disciplines the_discipline;
+ bool previous_thread_life_protection;
if ( attr ) the_attr = attr;
else the_attr = &_POSIX_Mutex_Default_attributes;
@@ -149,15 +150,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();
+ the_mutex = _POSIX_Mutex_Allocate( &previous_thread_life_protection );
if ( !the_mutex ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EAGAIN;
}
@@ -188,6 +184,6 @@ int pthread_mutex_init(
*mutex = the_mutex->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/pbarrierdestroy.c b/cpukit/posix/src/pbarrierdestroy.c
index d2eb505..87cf457 100644
--- a/cpukit/posix/src/pbarrierdestroy.c
+++ b/cpukit/posix/src/pbarrierdestroy.c
@@ -41,10 +41,12 @@ int pthread_barrier_destroy(
{
POSIX_Barrier_Control *the_barrier = NULL;
Objects_Locations location;
+ bool previous_thread_life_protection;
if ( !barrier )
return EINVAL;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_barrier = _POSIX_Barrier_Get( barrier, &location );
switch ( location ) {
@@ -55,10 +57,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( previous_thread_life_protection );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -68,5 +70,7 @@ int pthread_barrier_destroy(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return EINVAL;
}
diff --git a/cpukit/posix/src/pbarrierinit.c b/cpukit/posix/src/pbarrierinit.c
index f2dda78..b6f329b 100644
--- a/cpukit/posix/src/pbarrierinit.c
+++ b/cpukit/posix/src/pbarrierinit.c
@@ -52,6 +52,7 @@ int pthread_barrier_init(
CORE_barrier_Attributes the_attributes;
pthread_barrierattr_t my_attr;
const pthread_barrierattr_t *the_attr;
+ bool previous_thread_life_protection;
/*
* Error check parameters
@@ -92,15 +93,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();
+ the_barrier = _POSIX_Barrier_Allocate( &previous_thread_life_protection );
if ( !the_barrier ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EAGAIN;
}
@@ -112,10 +108,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( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/prwlockdestroy.c b/cpukit/posix/src/prwlockdestroy.c
index 9054e92..b1095ed 100644
--- a/cpukit/posix/src/prwlockdestroy.c
+++ b/cpukit/posix/src/prwlockdestroy.c
@@ -40,10 +40,12 @@ int pthread_rwlock_destroy(
{
POSIX_RWLock_Control *the_rwlock = NULL;
Objects_Locations location;
+ bool previous_thread_life_protection;
if ( !rwlock )
return EINVAL;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
switch ( location ) {
@@ -53,6 +55,7 @@ int pthread_rwlock_destroy(
*/
if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) {
_Objects_Put( &the_rwlock->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EBUSY;
}
@@ -61,10 +64,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( previous_thread_life_protection );
- _Objects_Put( &the_rwlock->Object );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -74,5 +77,7 @@ int pthread_rwlock_destroy(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return EINVAL;
}
diff --git a/cpukit/posix/src/prwlockinit.c b/cpukit/posix/src/prwlockinit.c
index 488b46b..c546e0b 100644
--- a/cpukit/posix/src/prwlockinit.c
+++ b/cpukit/posix/src/prwlockinit.c
@@ -50,6 +50,7 @@ int pthread_rwlock_init(
CORE_RWLock_Attributes the_attributes;
pthread_rwlockattr_t default_attr;
const pthread_rwlockattr_t *the_attr;
+ bool previous_thread_life_protection;
/*
* Error check parameters
@@ -88,15 +89,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();
+ the_rwlock = _POSIX_RWLock_Allocate( &previous_thread_life_protection );
if ( !the_rwlock ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EAGAIN;
}
@@ -110,6 +106,6 @@ int pthread_rwlock_init(
*rwlock = the_rwlock->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/pspindestroy.c b/cpukit/posix/src/pspindestroy.c
index 7795a33..da0a033 100644
--- a/cpukit/posix/src/pspindestroy.c
+++ b/cpukit/posix/src/pspindestroy.c
@@ -41,10 +41,12 @@ int pthread_spin_destroy(
{
POSIX_Spinlock_Control *the_spinlock = NULL;
Objects_Locations location;
+ bool previous_thread_life_protection;
if ( !spinlock )
return EINVAL;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
switch ( location ) {
@@ -55,10 +57,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( previous_thread_life_protection );
- _Objects_Put( &the_spinlock->Object );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -68,5 +70,7 @@ int pthread_spin_destroy(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return EINVAL;
}
diff --git a/cpukit/posix/src/pspininit.c b/cpukit/posix/src/pspininit.c
index 6030ed0..8260b41 100644
--- a/cpukit/posix/src/pspininit.c
+++ b/cpukit/posix/src/pspininit.c
@@ -48,7 +48,7 @@ int pthread_spin_init(
{
POSIX_Spinlock_Control *the_spinlock;
CORE_spinlock_Attributes attributes;
-
+ bool previous_thread_life_protection;
if ( !spinlock )
return EINVAL;
@@ -61,12 +61,10 @@ int pthread_spin_init(
return EINVAL;
}
- _Thread_Disable_dispatch(); /* prevents deletion */
-
- the_spinlock = _POSIX_Spinlock_Allocate();
+ the_spinlock = _POSIX_Spinlock_Allocate( &previous_thread_life_protection );
if ( !the_spinlock ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EAGAIN;
}
@@ -78,6 +76,6 @@ int pthread_spin_init(
*spinlock = the_spinlock->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 5a6d929..2d72c26 100644
--- a/cpukit/posix/src/pthreadcreate.c
+++ b/cpukit/posix/src/pthreadcreate.c
@@ -62,6 +62,7 @@ int pthread_create(
struct sched_param schedparam;
Objects_Name name;
int rc;
+ bool previous_thread_life_protection;
if ( !start_routine )
return EFAULT;
@@ -156,18 +157,13 @@ int pthread_create(
#endif
/*
- * Lock the allocator mutex for protection
- */
- _RTEMS_Lock_allocator();
-
- /*
* Allocate the thread control block.
*
* NOTE: Global threads are not currently supported.
*/
- the_thread = _POSIX_Threads_Allocate();
+ the_thread = _POSIX_Threads_Allocate( &previous_thread_life_protection );
if ( !the_thread ) {
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EAGAIN;
}
@@ -190,7 +186,7 @@ int pthread_create(
);
if ( !status ) {
_POSIX_Threads_Free( the_thread );
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EAGAIN;
}
@@ -235,7 +231,7 @@ int pthread_create(
if ( !status ) {
_Thread_Enable_dispatch();
_POSIX_Threads_Free( the_thread );
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return EINVAL;
}
#endif
@@ -254,6 +250,6 @@ int pthread_create(
*/
*thread = the_thread->Object.id;
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/semaphorecreatesupp.c b/cpukit/posix/src/semaphorecreatesupp.c
index 54b5b46..df3dde6 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();
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 1c205bf..594cd1b 100644
--- a/cpukit/posix/src/semclose.c
+++ b/cpukit/posix/src/semclose.c
@@ -37,7 +37,9 @@ int sem_close(
{
POSIX_Semaphore_Control *the_semaphore;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_semaphore = _POSIX_Semaphore_Get( sem, &location );
switch ( location ) {
@@ -45,6 +47,7 @@ int sem_close(
the_semaphore->open_count -= 1;
_POSIX_Semaphore_Delete( the_semaphore );
_Objects_Put( &the_semaphore->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -54,5 +57,7 @@ int sem_close(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
rtems_set_errno_and_return_minus_one( EINVAL );
}
diff --git a/cpukit/posix/src/semdestroy.c b/cpukit/posix/src/semdestroy.c
index 8c3f079..a0d2824 100644
--- a/cpukit/posix/src/semdestroy.c
+++ b/cpukit/posix/src/semdestroy.c
@@ -37,7 +37,9 @@ int sem_destroy(
{
POSIX_Semaphore_Control *the_semaphore;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_semaphore = _POSIX_Semaphore_Get( sem, &location );
switch ( location ) {
@@ -53,6 +55,7 @@ int sem_destroy(
_POSIX_Semaphore_Delete( the_semaphore );
_Objects_Put( &the_semaphore->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -62,5 +65,7 @@ int sem_destroy(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
rtems_set_errno_and_return_minus_one( EINVAL );
}
diff --git a/cpukit/posix/src/seminit.c b/cpukit/posix/src/seminit.c
index 466b2d0..adf837b 100644
--- a/cpukit/posix/src/seminit.c
+++ b/cpukit/posix/src/seminit.c
@@ -43,10 +43,12 @@ int sem_init(
{
int status;
POSIX_Semaphore_Control *the_semaphore;
+ bool previous_thread_life_protection;
if ( !sem )
rtems_set_errno_and_return_minus_one( EINVAL );
+ previous_thread_life_protection = _Objects_Allocator_lock();
status = _POSIX_Semaphore_Create_support(
NULL,
0,
@@ -54,6 +56,7 @@ int sem_init(
value,
&the_semaphore
);
+ _Objects_Allocator_unlock( previous_thread_life_protection );
if ( status != -1 )
*sem = the_semaphore->Object.id;
diff --git a/cpukit/posix/src/semopen.c b/cpukit/posix/src/semopen.c
index 20e2e92..22eb685 100644
--- a/cpukit/posix/src/semopen.c
+++ b/cpukit/posix/src/semopen.c
@@ -65,8 +65,7 @@ sem_t *sem_open(
POSIX_Semaphore_Control *the_semaphore;
Objects_Locations location;
size_t name_len;
-
- _Thread_Disable_dispatch();
+ bool previous_thread_life_protection;
if ( oflag & O_CREAT ) {
va_start(arg, oflag);
@@ -75,6 +74,7 @@ sem_t *sem_open(
va_end(arg);
}
+ previous_thread_life_protection = _Objects_Allocator_lock();
status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len );
/*
@@ -92,7 +92,7 @@ sem_t *sem_open(
*/
if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
rtems_set_errno_and_return_minus_one_cast( status, sem_t * );
}
} else {
@@ -102,14 +102,14 @@ sem_t *sem_open(
*/
if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
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( previous_thread_life_protection );
goto return_id;
}
@@ -130,7 +130,7 @@ sem_t *sem_open(
* errno was set by Create_support, so don't set it again.
*/
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
if ( status == -1 )
return SEM_FAILED;
diff --git a/cpukit/posix/src/semunlink.c b/cpukit/posix/src/semunlink.c
index 180facc..db60713 100644
--- a/cpukit/posix/src/semunlink.c
+++ b/cpukit/posix/src/semunlink.c
@@ -35,11 +35,13 @@ 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;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
_Thread_Disable_dispatch();
status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len );
@@ -58,5 +60,7 @@ int sem_unlink(
_POSIX_Semaphore_Delete( the_semaphore );
_Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return 0;
}
diff --git a/cpukit/posix/src/timercreate.c b/cpukit/posix/src/timercreate.c
index f55e2db..e130627 100644
--- a/cpukit/posix/src/timercreate.c
+++ b/cpukit/posix/src/timercreate.c
@@ -39,6 +39,7 @@ int timer_create(
)
{
POSIX_Timer_Control *ptimer;
+ bool previous_thread_life_protection;
if ( clock_id != CLOCK_REALTIME )
rtems_set_errno_and_return_minus_one( EINVAL );
@@ -66,21 +67,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();
+ ptimer = _POSIX_Timer_Allocate( &previous_thread_life_protection );
if ( !ptimer ) {
- _Objects_Put( &ptimer->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
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 +97,6 @@ int timer_create(
_Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
*timerid = ptimer->Object.id;
- _Objects_Put( &ptimer->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return 0;
}
diff --git a/cpukit/posix/src/timerdelete.c b/cpukit/posix/src/timerdelete.c
index 5ebf8f8..e2354fa 100644
--- a/cpukit/posix/src/timerdelete.c
+++ b/cpukit/posix/src/timerdelete.c
@@ -46,7 +46,9 @@ int timer_delete(
*/
POSIX_Timer_Control *ptimer;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
ptimer = _POSIX_Timer_Get( timerid, &location );
switch ( location ) {
@@ -54,8 +56,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( previous_thread_life_protection );
+
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -65,5 +69,7 @@ int timer_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
rtems_set_errno_and_return_minus_one( EINVAL );
}
diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am
index f89a896..cf8ca3b 100644
--- a/cpukit/rtems/Makefile.am
+++ b/cpukit/rtems/Makefile.am
@@ -175,7 +175,6 @@ librtems_a_SOURCES += src/rtemstimerdata.c
## MESSAGE_QUEUE_C_FILES
librtems_a_SOURCES += src/msg.c
-librtems_a_SOURCES += src/msgqallocate.c
librtems_a_SOURCES += src/msgqbroadcast.c
librtems_a_SOURCES += src/msgqcreate.c
librtems_a_SOURCES += src/msgqdelete.c
diff --git a/cpukit/rtems/include/rtems/rtems/barrierimpl.h b/cpukit/rtems/include/rtems/rtems/barrierimpl.h
index 628a570..8d4ce1e 100644
--- a/cpukit/rtems/include/rtems/rtems/barrierimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/barrierimpl.h
@@ -65,15 +65,14 @@ RTEMS_BARRIER_EXTERN Objects_Information _Barrier_Information;
*/
void _Barrier_Manager_initialization(void);
-/**
- * @brief _Barrier_Allocate
- *
- * This function allocates a barrier control block from
- * the inactive chain of free barrier control blocks.
- */
-RTEMS_INLINE_ROUTINE Barrier_Control *_Barrier_Allocate( void )
+RTEMS_INLINE_ROUTINE Barrier_Control *_Barrier_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Barrier_Control *) _Objects_Allocate( &_Barrier_Information );
+ return (Barrier_Control *) _Objects_Allocate(
+ &_Barrier_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/rtems/include/rtems/rtems/dpmemimpl.h b/cpukit/rtems/include/rtems/rtems/dpmemimpl.h
index 717cf84..3b0aec0 100644
--- a/cpukit/rtems/include/rtems/rtems/dpmemimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/dpmemimpl.h
@@ -51,18 +51,14 @@ RTEMS_DPMEM_EXTERN Objects_Information _Dual_ported_memory_Information;
*/
void _Dual_ported_memory_Manager_initialization(void);
-/**
- * @brief Allocates a port control block from the inactive chain
- * of free port control blocks.
- *
- * This routine allocates a port control block from the inactive chain
- * of free port control blocks.
- */
-RTEMS_INLINE_ROUTINE Dual_ported_memory_Control
- *_Dual_ported_memory_Allocate ( void )
+RTEMS_INLINE_ROUTINE Dual_ported_memory_Control *_Dual_ported_memory_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Dual_ported_memory_Control *)
- _Objects_Allocate( &_Dual_ported_memory_Information );
+ return (Dual_ported_memory_Control *) _Objects_Allocate(
+ &_Dual_ported_memory_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/rtems/include/rtems/rtems/messageimpl.h b/cpukit/rtems/include/rtems/rtems/messageimpl.h
index da87fd1..1d78545 100644
--- a/cpukit/rtems/include/rtems/rtems/messageimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/messageimpl.h
@@ -90,16 +90,6 @@ rtems_status_code _Message_queue_Submit(
);
/**
- * @brief Message Queue Allocate
- *
- * This function allocates a message queue control block from
- * the inactive chain of free message queue control blocks.
- *
- * @retval the_message_queue filled in if successful, NULL otherwise
- */
-Message_queue_Control *_Message_queue_Allocate (void);
-
-/**
* @brief Message queue Translate Core Message Queue Return Code
*
* This function returns a RTEMS status code based on
@@ -162,6 +152,16 @@ RTEMS_INLINE_ROUTINE Message_queue_Control *_Message_queue_Get (
_Objects_Get( &_Message_queue_Information, id, location );
}
+RTEMS_INLINE_ROUTINE Message_queue_Control *_Message_queue_Allocate(
+ bool *previous_thread_life_protection
+)
+{
+ return (Message_queue_Control *) _Objects_Allocate(
+ &_Message_queue_Information,
+ previous_thread_life_protection
+ );
+}
+
/**@}*/
#ifdef __cplusplus
diff --git a/cpukit/rtems/include/rtems/rtems/partimpl.h b/cpukit/rtems/include/rtems/rtems/partimpl.h
index 5992829..fd7dfe7 100644
--- a/cpukit/rtems/include/rtems/rtems/partimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/partimpl.h
@@ -143,16 +143,14 @@ RTEMS_INLINE_ROUTINE bool _Partition_Is_buffer_size_aligned (
return ((buffer_size % CPU_PARTITION_ALIGNMENT) == 0);
}
-/**
- * @brief Allocates a partition control block from the
- * inactive chain of free partition control blocks.
- *
- * This function allocates a partition control block from
- * the inactive chain of free partition control blocks.
- */
-RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Allocate ( void )
+RTEMS_INLINE_ROUTINE Partition_Control *_Partition_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Partition_Control *) _Objects_Allocate( &_Partition_Information );
+ return (Partition_Control *) _Objects_Allocate(
+ &_Partition_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/rtems/include/rtems/rtems/ratemonimpl.h b/cpukit/rtems/include/rtems/rtems/ratemonimpl.h
index 9dcec14..61c1530 100644
--- a/cpukit/rtems/include/rtems/rtems/ratemonimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/ratemonimpl.h
@@ -61,17 +61,14 @@ RTEMS_RATEMON_EXTERN Objects_Information _Rate_monotonic_Information;
*/
void _Rate_monotonic_Manager_initialization(void);
-/**
- * @brief Allocates a period control block from
- * the inactive chain of free period control blocks.
- *
- * This function allocates a period control block from
- * the inactive chain of free period control blocks.
- */
-RTEMS_INLINE_ROUTINE Rate_monotonic_Control *_Rate_monotonic_Allocate( void )
+RTEMS_INLINE_ROUTINE Rate_monotonic_Control *_Rate_monotonic_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Rate_monotonic_Control *)
- _Objects_Allocate( &_Rate_monotonic_Information );
+ return (Rate_monotonic_Control *) _Objects_Allocate(
+ &_Rate_monotonic_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/rtems/include/rtems/rtems/regionimpl.h b/cpukit/rtems/include/rtems/rtems/regionimpl.h
index 8dbfbd6..2a5601f 100644
--- a/cpukit/rtems/include/rtems/rtems/regionimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/regionimpl.h
@@ -63,15 +63,14 @@ RTEMS_REGION_EXTERN Objects_Information _Region_Information;
*/
void _Region_Manager_initialization(void);
-/**
- * @brief Region_Allocate
- *
- * This function allocates a region control block from
- * the inactive chain of free region control blocks.
- */
-RTEMS_INLINE_ROUTINE Region_Control *_Region_Allocate( void )
+RTEMS_INLINE_ROUTINE Region_Control *_Region_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Region_Control *) _Objects_Allocate( &_Region_Information );
+ return (Region_Control *) _Objects_Allocate(
+ &_Region_Information,
+ previous_thread_life_protection
+ );
}
/**
@@ -154,7 +153,10 @@ RTEMS_INLINE_ROUTINE bool _Region_Is_null (
*
* @param[in] the_region is the the region
*/
-extern void _Region_Process_queue(Region_Control *the_region);
+void _Region_Process_queue(
+ Region_Control *the_region,
+ bool previous_thread_life_protection
+);
/**
* @brief _Region_Debug_Walk
diff --git a/cpukit/rtems/include/rtems/rtems/semimpl.h b/cpukit/rtems/include/rtems/rtems/semimpl.h
index 51da4cd..4399033 100644
--- a/cpukit/rtems/include/rtems/rtems/semimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/semimpl.h
@@ -121,16 +121,14 @@ _Semaphore_Translate_core_semaphore_return_code(
return _Semaphore_Translate_core_semaphore_return_code_[status];
}
-/**
- * @brief Allocates a semaphore control block from
- * the inactive chain of free semaphore control blocks.
- *
- * This function allocates a semaphore control block from
- * the inactive chain of free semaphore control blocks.
- */
-RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Allocate( void )
+RTEMS_INLINE_ROUTINE Semaphore_Control *_Semaphore_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Semaphore_Control *) _Objects_Allocate( &_Semaphore_Information );
+ return (Semaphore_Control *) _Objects_Allocate(
+ &_Semaphore_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/rtems/include/rtems/rtems/tasksimpl.h b/cpukit/rtems/include/rtems/rtems/tasksimpl.h
index 2a99812..e3ded47 100644
--- a/cpukit/rtems/include/rtems/rtems/tasksimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/tasksimpl.h
@@ -77,17 +77,16 @@ void _RTEMS_Tasks_Invoke_task_variable_dtor(
rtems_task_variable_t *tvp
);
-/**
- * @brief Allocates a task control block.
- *
- * This function allocates a task control block from
- * the inactive chain of free task control blocks.
- */
-RTEMS_INLINE_ROUTINE Thread_Control *_RTEMS_tasks_Allocate( void )
+RTEMS_INLINE_ROUTINE Thread_Control *_RTEMS_tasks_Allocate(
+ bool *previous_thread_life_protection
+)
{
+ *previous_thread_life_protection = _Objects_Allocator_lock();
+
_Thread_Kill_zombies();
- return (Thread_Control *) _Objects_Allocate( &_RTEMS_tasks_Information );
+ return (Thread_Control *)
+ _Objects_Allocate_unprotected( &_RTEMS_tasks_Information );
}
/**
diff --git a/cpukit/rtems/include/rtems/rtems/timerimpl.h b/cpukit/rtems/include/rtems/rtems/timerimpl.h
index 4a4defe..f7d5254 100644
--- a/cpukit/rtems/include/rtems/rtems/timerimpl.h
+++ b/cpukit/rtems/include/rtems/rtems/timerimpl.h
@@ -138,15 +138,14 @@ RTEMS_TIMER_EXTERN Objects_Information _Timer_Information;
*/
void _Timer_Manager_initialization(void);
-/**
- * @brief Timer_Allocate
- *
- * This function allocates a timer control block from
- * the inactive chain of free timer control blocks.
- */
-RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Allocate( void )
+RTEMS_INLINE_ROUTINE Timer_Control *_Timer_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Timer_Control *) _Objects_Allocate( &_Timer_Information );
+ return (Timer_Control *) _Objects_Allocate(
+ &_Timer_Information,
+ previous_thread_life_protection
+ );
}
/**
diff --git a/cpukit/rtems/src/barriercreate.c b/cpukit/rtems/src/barriercreate.c
index e865774..374d82f 100644
--- a/cpukit/rtems/src/barriercreate.c
+++ b/cpukit/rtems/src/barriercreate.c
@@ -52,6 +52,7 @@ rtems_status_code rtems_barrier_create(
{
Barrier_Control *the_barrier;
CORE_barrier_Attributes the_attributes;
+ bool previous_thread_life_protection;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -68,12 +69,10 @@ rtems_status_code rtems_barrier_create(
the_attributes.discipline = CORE_BARRIER_MANUAL_RELEASE;
the_attributes.maximum_count = maximum_waiters;
- _Thread_Disable_dispatch(); /* prevents deletion */
-
- the_barrier = _Barrier_Allocate();
+ the_barrier = _Barrier_Allocate( &previous_thread_life_protection );
if ( !the_barrier ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
@@ -89,6 +88,6 @@ rtems_status_code rtems_barrier_create(
*id = the_barrier->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/barrierdelete.c b/cpukit/rtems/src/barrierdelete.c
index 90fff5e..3f79509 100644
--- a/cpukit/rtems/src/barrierdelete.c
+++ b/cpukit/rtems/src/barrierdelete.c
@@ -27,7 +27,9 @@ rtems_status_code rtems_barrier_delete(
{
Barrier_Control *the_barrier;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_barrier = _Barrier_Get( id, &location );
switch ( location ) {
@@ -39,10 +41,9 @@ rtems_status_code rtems_barrier_delete(
);
_Objects_Close( &_Barrier_Information, &the_barrier->Object );
-
- _Barrier_Free( the_barrier );
-
_Objects_Put( &the_barrier->Object );
+ _Barrier_Free( the_barrier );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -52,5 +53,7 @@ rtems_status_code rtems_barrier_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/rtems/src/dpmemcreate.c b/cpukit/rtems/src/dpmemcreate.c
index 9ad1588..84fee1a 100644
--- a/cpukit/rtems/src/dpmemcreate.c
+++ b/cpukit/rtems/src/dpmemcreate.c
@@ -33,7 +33,8 @@ rtems_status_code rtems_port_create(
rtems_id *id
)
{
- Dual_ported_memory_Control *the_port;
+ Dual_ported_memory_Control *the_port;
+ bool previous_thread_life_protection;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -45,12 +46,10 @@ rtems_status_code rtems_port_create(
!_Addresses_Is_aligned( external_start ) )
return RTEMS_INVALID_ADDRESS;
- _Thread_Disable_dispatch(); /* to prevent deletion */
-
- the_port = _Dual_ported_memory_Allocate();
+ the_port = _Dual_ported_memory_Allocate( &previous_thread_life_protection );
if ( !the_port ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
@@ -65,6 +64,6 @@ rtems_status_code rtems_port_create(
);
*id = the_port->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/dpmemdelete.c b/cpukit/rtems/src/dpmemdelete.c
index d6b42ff..6170de9 100644
--- a/cpukit/rtems/src/dpmemdelete.c
+++ b/cpukit/rtems/src/dpmemdelete.c
@@ -31,14 +31,17 @@ rtems_status_code rtems_port_delete(
{
Dual_ported_memory_Control *the_port;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_port = _Dual_ported_memory_Get( id, &location );
switch ( location ) {
case OBJECTS_LOCAL:
_Objects_Close( &_Dual_ported_memory_Information, &the_port->Object );
- _Dual_ported_memory_Free( the_port );
_Objects_Put( &the_port->Object );
+ _Dual_ported_memory_Free( the_port );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -48,5 +51,7 @@ rtems_status_code rtems_port_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/rtems/src/msgqallocate.c b/cpukit/rtems/src/msgqallocate.c
deleted file mode 100644
index f5776f1..0000000
--- a/cpukit/rtems/src/msgqallocate.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * @file
- *
- * @brief Message Queue Allocate
- * @ingroup ClassicMessageQueue
- */
-
-/*
- * COPYRIGHT (c) 1989-1999.
- * On-Line Applications Research Corporation (OAR).
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/system.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/coremsgimpl.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/wkspace.h>
-#include <rtems/rtems/status.h>
-#include <rtems/rtems/attrimpl.h>
-#include <rtems/rtems/messageimpl.h>
-#include <rtems/rtems/options.h>
-#include <rtems/rtems/support.h>
-
-Message_queue_Control *_Message_queue_Allocate(void)
-{
- return (Message_queue_Control *)
- _Objects_Allocate(&_Message_queue_Information);
-}
diff --git a/cpukit/rtems/src/msgqcreate.c b/cpukit/rtems/src/msgqcreate.c
index 6f60773..1400fb0 100644
--- a/cpukit/rtems/src/msgqcreate.c
+++ b/cpukit/rtems/src/msgqcreate.c
@@ -41,6 +41,7 @@ rtems_status_code rtems_message_queue_create(
{
Message_queue_Control *the_message_queue;
CORE_message_queue_Attributes the_msgq_attributes;
+ bool previous_thread_life_protection;
#if defined(RTEMS_MULTIPROCESSING)
bool is_global;
#endif
@@ -81,12 +82,11 @@ rtems_status_code rtems_message_queue_create(
#endif
#endif
- _Thread_Disable_dispatch(); /* protects object pointer */
-
- the_message_queue = _Message_queue_Allocate();
+ the_message_queue =
+ _Message_queue_Allocate( &previous_thread_life_protection );
if ( !the_message_queue ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
@@ -95,7 +95,7 @@ rtems_status_code rtems_message_queue_create(
!( _Objects_MP_Allocate_and_open( &_Message_queue_Information,
name, the_message_queue->Object.id, false ) ) ) {
_Message_queue_Free( the_message_queue );
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
#endif
@@ -120,7 +120,7 @@ rtems_status_code rtems_message_queue_create(
#endif
_Message_queue_Free( the_message_queue );
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_UNSATISFIED;
}
@@ -142,6 +142,6 @@ rtems_status_code rtems_message_queue_create(
);
#endif
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/msgqdelete.c b/cpukit/rtems/src/msgqdelete.c
index d3c0767..25d7e09 100644
--- a/cpukit/rtems/src/msgqdelete.c
+++ b/cpukit/rtems/src/msgqdelete.c
@@ -36,7 +36,9 @@ rtems_status_code rtems_message_queue_delete(
{
Message_queue_Control *the_message_queue;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_message_queue = _Message_queue_Get( id, &location );
switch ( location ) {
@@ -54,8 +56,6 @@ rtems_status_code rtems_message_queue_delete(
CORE_MESSAGE_QUEUE_STATUS_WAS_DELETED
);
- _Message_queue_Free( the_message_queue );
-
#if defined(RTEMS_MULTIPROCESSING)
if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) {
_Objects_MP_Close(
@@ -72,11 +72,13 @@ rtems_status_code rtems_message_queue_delete(
}
#endif
_Objects_Put( &the_message_queue->Object );
+ _Message_queue_Free( the_message_queue );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE:
- _Thread_Dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
#endif
@@ -84,5 +86,7 @@ rtems_status_code rtems_message_queue_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/rtems/src/partcreate.c b/cpukit/rtems/src/partcreate.c
index 32758f8..9e03f4c 100644
--- a/cpukit/rtems/src/partcreate.c
+++ b/cpukit/rtems/src/partcreate.c
@@ -53,7 +53,8 @@ rtems_status_code rtems_partition_create(
rtems_id *id
)
{
- Partition_Control *the_partition;
+ Partition_Control *the_partition;
+ bool previous_thread_life_protection;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -77,12 +78,10 @@ rtems_status_code rtems_partition_create(
return RTEMS_MP_NOT_CONFIGURED;
#endif
- _Thread_Disable_dispatch(); /* prevents deletion */
-
- the_partition = _Partition_Allocate();
+ the_partition = _Partition_Allocate( &previous_thread_life_protection );
if ( !the_partition ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
@@ -91,7 +90,7 @@ rtems_status_code rtems_partition_create(
!( _Objects_MP_Allocate_and_open( &_Partition_Information, name,
the_partition->Object.id, false ) ) ) {
_Partition_Free( the_partition );
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
#endif
@@ -122,6 +121,6 @@ rtems_status_code rtems_partition_create(
);
#endif
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/partdelete.c b/cpukit/rtems/src/partdelete.c
index cc10abc..f68e871 100644
--- a/cpukit/rtems/src/partdelete.c
+++ b/cpukit/rtems/src/partdelete.c
@@ -28,14 +28,15 @@ rtems_status_code rtems_partition_delete(
{
Partition_Control *the_partition;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_partition = _Partition_Get( id, &location );
switch ( location ) {
case OBJECTS_LOCAL:
if ( the_partition->number_of_used_blocks == 0 ) {
_Objects_Close( &_Partition_Information, &the_partition->Object );
- _Partition_Free( the_partition );
#if defined(RTEMS_MULTIPROCESSING)
if ( _Attributes_Is_global( the_partition->attribute_set ) ) {
@@ -54,14 +55,17 @@ rtems_status_code rtems_partition_delete(
#endif
_Objects_Put( &the_partition->Object );
+ _Partition_Free( the_partition );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
_Objects_Put( &the_partition->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_RESOURCE_IN_USE;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE:
- _Thread_Dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
#endif
@@ -69,5 +73,7 @@ rtems_status_code rtems_partition_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/rtems/src/ratemoncreate.c b/cpukit/rtems/src/ratemoncreate.c
index ce0e1de..1c3292d 100644
--- a/cpukit/rtems/src/ratemoncreate.c
+++ b/cpukit/rtems/src/ratemoncreate.c
@@ -48,6 +48,7 @@ rtems_status_code rtems_rate_monotonic_create(
)
{
Rate_monotonic_Control *the_period;
+ bool previous_thread_life_protection;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -55,16 +56,14 @@ rtems_status_code rtems_rate_monotonic_create(
if ( !id )
return RTEMS_INVALID_ADDRESS;
- _Thread_Disable_dispatch(); /* to prevent deletion */
-
- the_period = _Rate_monotonic_Allocate();
+ the_period = _Rate_monotonic_Allocate( &previous_thread_life_protection );
if ( !the_period ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
- the_period->owner = _Thread_Executing;
+ the_period->owner = _Thread_Get_executing();
the_period->state = RATE_MONOTONIC_INACTIVE;
_Watchdog_Initialize( &the_period->Timer, NULL, 0, NULL );
@@ -78,6 +77,6 @@ rtems_status_code rtems_rate_monotonic_create(
);
*id = the_period->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/ratemondelete.c b/cpukit/rtems/src/ratemondelete.c
index 0a9e6a49..c0467aa 100644
--- a/cpukit/rtems/src/ratemondelete.c
+++ b/cpukit/rtems/src/ratemondelete.c
@@ -29,7 +29,9 @@ rtems_status_code rtems_rate_monotonic_delete(
{
Rate_monotonic_Control *the_period;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_period = _Rate_monotonic_Get( id, &location );
switch ( location ) {
@@ -38,8 +40,9 @@ rtems_status_code rtems_rate_monotonic_delete(
_Objects_Close( &_Rate_monotonic_Information, &the_period->Object );
(void) _Watchdog_Remove( &the_period->Timer );
the_period->state = RATE_MONOTONIC_INACTIVE;
- _Rate_monotonic_Free( the_period );
_Objects_Put( &the_period->Object );
+ _Rate_monotonic_Free( the_period );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -49,5 +52,7 @@ rtems_status_code rtems_rate_monotonic_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/rtems/src/regioncreate.c b/cpukit/rtems/src/regioncreate.c
index 23d42fc..791e031 100644
--- a/cpukit/rtems/src/regioncreate.c
+++ b/cpukit/rtems/src/regioncreate.c
@@ -67,9 +67,7 @@ rtems_status_code rtems_region_create(
if ( !id )
return RTEMS_INVALID_ADDRESS;
- previous_thread_life_protection = _RTEMS_Lock_allocator();
-
- the_region = _Region_Allocate();
+ the_region = _Region_Allocate( &previous_thread_life_protection);
if ( !the_region )
return_status = RTEMS_TOO_MANY;
@@ -112,7 +110,7 @@ rtems_status_code rtems_region_create(
}
}
- _RTEMS_Unlock_allocator( previous_thread_life_protection );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return return_status;
}
diff --git a/cpukit/rtems/src/regiondelete.c b/cpukit/rtems/src/regiondelete.c
index b793dc6..748aec7 100644
--- a/cpukit/rtems/src/regiondelete.c
+++ b/cpukit/rtems/src/regiondelete.c
@@ -35,7 +35,7 @@ rtems_status_code rtems_region_delete(
Region_Control *the_region;
bool previous_thread_life_protection;
- previous_thread_life_protection = _RTEMS_Lock_allocator();
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -62,7 +62,7 @@ rtems_status_code rtems_region_delete(
break;
}
- _RTEMS_Unlock_allocator( previous_thread_life_protection );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return return_status;
}
diff --git a/cpukit/rtems/src/regionextend.c b/cpukit/rtems/src/regionextend.c
index 289377d..a36aa49 100644
--- a/cpukit/rtems/src/regionextend.c
+++ b/cpukit/rtems/src/regionextend.c
@@ -36,11 +36,12 @@ rtems_status_code rtems_region_extend(
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
+ bool previous_thread_life_protection;
if ( !starting_address )
return RTEMS_INVALID_ADDRESS;
- _RTEMS_Lock_allocator(); /* to prevent deletion */
+ previous_thread_life_protection = _RTEMS_Lock_allocator(); /* to prevent deletion */
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -74,6 +75,7 @@ rtems_status_code rtems_region_extend(
break;
}
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
+
return return_status;
}
diff --git a/cpukit/rtems/src/regiongetfreeinfo.c b/cpukit/rtems/src/regiongetfreeinfo.c
index be0f008..0292ac2 100644
--- a/cpukit/rtems/src/regiongetfreeinfo.c
+++ b/cpukit/rtems/src/regiongetfreeinfo.c
@@ -34,11 +34,12 @@ rtems_status_code rtems_region_get_free_information(
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
+ bool previous_thread_life_protection;
if ( !the_info )
return RTEMS_INVALID_ADDRESS;
- _RTEMS_Lock_allocator();
+ previous_thread_life_protection = _RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -65,6 +66,7 @@ rtems_status_code rtems_region_get_free_information(
break;
}
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
+
return return_status;
}
diff --git a/cpukit/rtems/src/regiongetinfo.c b/cpukit/rtems/src/regiongetinfo.c
index c3466f0..c3b53e8 100644
--- a/cpukit/rtems/src/regiongetinfo.c
+++ b/cpukit/rtems/src/regiongetinfo.c
@@ -34,11 +34,12 @@ rtems_status_code rtems_region_get_information(
Objects_Locations location;
rtems_status_code return_status;
Region_Control *the_region;
+ bool previous_thread_life_protection;
if ( !the_info )
return RTEMS_INVALID_ADDRESS;
- _RTEMS_Lock_allocator();
+ previous_thread_life_protection = _RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -59,6 +60,7 @@ rtems_status_code rtems_region_get_information(
break;
}
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
+
return return_status;
}
diff --git a/cpukit/rtems/src/regiongetsegment.c b/cpukit/rtems/src/regiongetsegment.c
index 92b3a94..d899cf2 100644
--- a/cpukit/rtems/src/regiongetsegment.c
+++ b/cpukit/rtems/src/regiongetsegment.c
@@ -36,6 +36,7 @@ rtems_status_code rtems_region_get_segment(
rtems_status_code return_status;
Region_Control *the_region;
void *the_segment;
+ bool previous_thread_life_protection;
if ( !segment )
return RTEMS_INVALID_ADDRESS;
@@ -45,9 +46,9 @@ rtems_status_code rtems_region_get_segment(
if ( size == 0 )
return RTEMS_INVALID_SIZE;
- _RTEMS_Lock_allocator();
+ previous_thread_life_protection = _RTEMS_Lock_allocator();
- executing = _Thread_Executing;
+ executing = _Thread_Get_executing();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -76,7 +77,7 @@ rtems_status_code rtems_region_get_segment(
*/
/* FIXME: Lock order reversal */
_Thread_Disable_dispatch();
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
executing->Wait.queue = &the_region->Wait_queue;
executing->Wait.id = id;
@@ -109,6 +110,7 @@ rtems_status_code rtems_region_get_segment(
break;
}
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
+
return return_status;
}
diff --git a/cpukit/rtems/src/regiongetsegmentsize.c b/cpukit/rtems/src/regiongetsegmentsize.c
index 8f823fc..24f1ea8 100644
--- a/cpukit/rtems/src/regiongetsegmentsize.c
+++ b/cpukit/rtems/src/regiongetsegmentsize.c
@@ -34,6 +34,7 @@ rtems_status_code rtems_region_get_segment_size(
Objects_Locations location;
rtems_status_code return_status = RTEMS_SUCCESSFUL;
Region_Control *the_region;
+ bool previous_thread_life_protection;
if ( !segment )
return RTEMS_INVALID_ADDRESS;
@@ -41,7 +42,7 @@ rtems_status_code rtems_region_get_segment_size(
if ( !size )
return RTEMS_INVALID_ADDRESS;
- _RTEMS_Lock_allocator();
+ previous_thread_life_protection = _RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -61,6 +62,7 @@ rtems_status_code rtems_region_get_segment_size(
break;
}
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
+
return return_status;
}
diff --git a/cpukit/rtems/src/regionprocessqueue.c b/cpukit/rtems/src/regionprocessqueue.c
index 54081af..dc496cf 100644
--- a/cpukit/rtems/src/regionprocessqueue.c
+++ b/cpukit/rtems/src/regionprocessqueue.c
@@ -23,7 +23,8 @@
#include <rtems/score/threadqimpl.h>
void _Region_Process_queue(
- Region_Control *the_region
+ Region_Control *the_region,
+ bool previous_thread_life_protection
)
{
Thread_Control *the_thread;
@@ -39,7 +40,7 @@ void _Region_Process_queue(
* switch could occur.
*/
_Thread_Disable_dispatch();
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
/*
* NOTE: The following loop is O(n) where n is the number of
diff --git a/cpukit/rtems/src/regionresizesegment.c b/cpukit/rtems/src/regionresizesegment.c
index ff45215..78c14cb 100644
--- a/cpukit/rtems/src/regionresizesegment.c
+++ b/cpukit/rtems/src/regionresizesegment.c
@@ -39,11 +39,12 @@ rtems_status_code rtems_region_resize_segment(
rtems_status_code return_status;
Heap_Resize_status status;
Region_Control *the_region;
+ bool previous_thread_life_protection;
if ( !old_size )
return RTEMS_INVALID_ADDRESS;
- _RTEMS_Lock_allocator();
+ previous_thread_life_protection = _RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -64,9 +65,10 @@ rtems_status_code rtems_region_resize_segment(
_Region_Debug_Walk( the_region, 8 );
if ( status == HEAP_RESIZE_SUCCESSFUL )
- _Region_Process_queue( the_region ); /* unlocks allocator */
+ /* unlocks allocator */
+ _Region_Process_queue( the_region, previous_thread_life_protection );
else
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
if (status == HEAP_RESIZE_SUCCESSFUL)
@@ -87,6 +89,6 @@ rtems_status_code rtems_region_resize_segment(
break;
}
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
return return_status;
}
diff --git a/cpukit/rtems/src/regionreturnsegment.c b/cpukit/rtems/src/regionreturnsegment.c
index 6ae537f..f95ec01 100644
--- a/cpukit/rtems/src/regionreturnsegment.c
+++ b/cpukit/rtems/src/regionreturnsegment.c
@@ -46,8 +46,9 @@ rtems_status_code rtems_region_return_segment(
#endif
int status;
Region_Control *the_region;
+ bool previous_thread_life_protection;
- _RTEMS_Lock_allocator();
+ previous_thread_life_protection = _RTEMS_Lock_allocator();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -71,7 +72,8 @@ rtems_status_code rtems_region_return_segment(
else {
the_region->number_of_used_blocks -= 1;
- _Region_Process_queue(the_region); /* unlocks allocator */
+ /* unlocks allocator */
+ _Region_Process_queue(the_region, previous_thread_life_protection);
return RTEMS_SUCCESSFUL;
}
@@ -91,6 +93,6 @@ rtems_status_code rtems_region_return_segment(
break;
}
- _RTEMS_Unlock_allocator();
+ _RTEMS_Unlock_allocator( previous_thread_life_protection );
return return_status;
}
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index bf9229e..a4a0e6e 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -64,6 +64,7 @@ rtems_status_code rtems_semaphore_create(
CORE_mutex_Attributes the_mutex_attr;
CORE_semaphore_Attributes the_semaphore_attr;
CORE_mutex_Status mutex_status;
+ bool previous_thread_life_protection;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -100,12 +101,10 @@ rtems_status_code rtems_semaphore_create(
if ( !_Attributes_Is_counting_semaphore( attribute_set ) && ( count > 1 ) )
return RTEMS_INVALID_NUMBER;
- _Thread_Disable_dispatch(); /* prevents deletion */
-
- the_semaphore = _Semaphore_Allocate();
+ the_semaphore = _Semaphore_Allocate( &previous_thread_life_protection );
if ( !the_semaphore ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
@@ -114,7 +113,7 @@ rtems_status_code rtems_semaphore_create(
! ( _Objects_MP_Allocate_and_open( &_Semaphore_Information, name,
the_semaphore->Object.id, false ) ) ) {
_Semaphore_Free( the_semaphore );
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
#endif
@@ -179,14 +178,14 @@ rtems_status_code rtems_semaphore_create(
mutex_status = _CORE_mutex_Initialize(
&the_semaphore->Core_control.mutex,
- _Thread_Executing,
+ _Thread_Get_executing(),
&the_mutex_attr,
(count == 1) ? CORE_MUTEX_UNLOCKED : CORE_MUTEX_LOCKED
);
if ( mutex_status == CORE_MUTEX_STATUS_CEILING_VIOLATED ) {
_Semaphore_Free( the_semaphore );
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_INVALID_PRIORITY;
}
}
@@ -212,6 +211,6 @@ rtems_status_code rtems_semaphore_create(
0 /* Not used */
);
#endif
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/semdelete.c b/cpukit/rtems/src/semdelete.c
index ea82b77..c699abd 100644
--- a/cpukit/rtems/src/semdelete.c
+++ b/cpukit/rtems/src/semdelete.c
@@ -43,6 +43,9 @@ rtems_status_code rtems_semaphore_delete(
{
Semaphore_Control *the_semaphore;
Objects_Locations location;
+ bool previous_thread_life_protection;
+
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_semaphore = _Semaphore_Get( id, &location );
switch ( location ) {
@@ -53,6 +56,7 @@ rtems_status_code rtems_semaphore_delete(
!_Attributes_Is_simple_binary_semaphore(
the_semaphore->attribute_set ) ) {
_Objects_Put( &the_semaphore->Object );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_RESOURCE_IN_USE;
}
_CORE_mutex_Flush(
@@ -70,8 +74,6 @@ rtems_status_code rtems_semaphore_delete(
_Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
- _Semaphore_Free( the_semaphore );
-
#if defined(RTEMS_MULTIPROCESSING)
if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
@@ -85,12 +87,15 @@ rtems_status_code rtems_semaphore_delete(
);
}
#endif
+
_Objects_Put( &the_semaphore->Object );
+ _Semaphore_Free( the_semaphore );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE:
- _Thread_Dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
#endif
@@ -98,5 +103,6 @@ rtems_status_code rtems_semaphore_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/rtems/src/taskcreate.c b/cpukit/rtems/src/taskcreate.c
index ae4e188..97024d9 100644
--- a/cpukit/rtems/src/taskcreate.c
+++ b/cpukit/rtems/src/taskcreate.c
@@ -46,6 +46,7 @@ rtems_status_code rtems_task_create(
Priority_Control core_priority;
RTEMS_API_Control *api;
ASR_Information *asr;
+ bool previous_thread_life_protection;
if ( !id )
@@ -105,11 +106,6 @@ rtems_status_code rtems_task_create(
*/
/*
- * Lock the allocator mutex for protection
- */
- _RTEMS_Lock_allocator();
-
- /*
* Allocate the thread control block and -- if the task is global --
* allocate a global object control block.
*
@@ -119,10 +115,10 @@ rtems_status_code rtems_task_create(
* the event of an error.
*/
- the_thread = _RTEMS_tasks_Allocate();
+ the_thread = _RTEMS_tasks_Allocate( &previous_thread_life_protection );
if ( !the_thread ) {
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
@@ -132,7 +128,7 @@ rtems_status_code rtems_task_create(
if ( _Objects_MP_Is_null_global_object( the_global_object ) ) {
_RTEMS_tasks_Free( the_thread );
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
}
@@ -164,7 +160,7 @@ rtems_status_code rtems_task_create(
_Objects_MP_Free_global_object( the_global_object );
#endif
_RTEMS_tasks_Free( the_thread );
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_UNSATISFIED;
}
@@ -195,6 +191,6 @@ rtems_status_code rtems_task_create(
}
#endif
- _RTEMS_Unlock_allocator();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/timercreate.c b/cpukit/rtems/src/timercreate.c
index 35cdfab..c70e007 100644
--- a/cpukit/rtems/src/timercreate.c
+++ b/cpukit/rtems/src/timercreate.c
@@ -31,6 +31,7 @@ rtems_status_code rtems_timer_create(
)
{
Timer_Control *the_timer;
+ bool previous_thread_life_protection;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -38,12 +39,10 @@ rtems_status_code rtems_timer_create(
if ( !id )
return RTEMS_INVALID_ADDRESS;
- _Thread_Disable_dispatch(); /* to prevent deletion */
-
- the_timer = _Timer_Allocate();
+ the_timer = _Timer_Allocate( &previous_thread_life_protection );
if ( !the_timer ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
@@ -57,6 +56,6 @@ rtems_status_code rtems_timer_create(
);
*id = the_timer->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/rtems/src/timerdelete.c b/cpukit/rtems/src/timerdelete.c
index a3cf52a..48f9345 100644
--- a/cpukit/rtems/src/timerdelete.c
+++ b/cpukit/rtems/src/timerdelete.c
@@ -31,15 +31,18 @@ rtems_status_code rtems_timer_delete(
{
Timer_Control *the_timer;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_timer = _Timer_Get( id, &location );
switch ( location ) {
case OBJECTS_LOCAL:
_Objects_Close( &_Timer_Information, &the_timer->Object );
(void) _Watchdog_Remove( &the_timer->Ticker );
- _Timer_Free( the_timer );
_Objects_Put( &the_timer->Object );
+ _Timer_Free( the_timer );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -49,5 +52,7 @@ rtems_status_code rtems_timer_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/sapi/include/rtems/extensionimpl.h b/cpukit/sapi/include/rtems/extensionimpl.h
index 5b3964e..23020d4 100644
--- a/cpukit/sapi/include/rtems/extensionimpl.h
+++ b/cpukit/sapi/include/rtems/extensionimpl.h
@@ -38,9 +38,14 @@ SAPI_EXT_EXTERN Objects_Information _Extension_Information;
*/
void _Extension_Manager_initialization(void);
-RTEMS_INLINE_ROUTINE Extension_Control *_Extension_Allocate( void )
+RTEMS_INLINE_ROUTINE Extension_Control *_Extension_Allocate(
+ bool *previous_thread_life_protection
+)
{
- return (Extension_Control *) _Objects_Allocate( &_Extension_Information );
+ return (Extension_Control *) _Objects_Allocate(
+ &_Extension_Information,
+ previous_thread_life_protection
+ );
}
RTEMS_INLINE_ROUTINE void _Extension_Free (
diff --git a/cpukit/sapi/src/extensioncreate.c b/cpukit/sapi/src/extensioncreate.c
index 1d7232f..0816f1c 100644
--- a/cpukit/sapi/src/extensioncreate.c
+++ b/cpukit/sapi/src/extensioncreate.c
@@ -32,6 +32,7 @@ rtems_status_code rtems_extension_create(
)
{
Extension_Control *the_extension;
+ bool previous_thread_life_protection;
if ( !id )
return RTEMS_INVALID_ADDRESS;
@@ -39,16 +40,16 @@ rtems_status_code rtems_extension_create(
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
- _Thread_Disable_dispatch(); /* to prevent deletion */
-
- the_extension = _Extension_Allocate();
+ the_extension = _Extension_Allocate( &previous_thread_life_protection );
if ( !the_extension ) {
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_TOO_MANY;
}
+ _Thread_Disable_dispatch();
_User_extensions_Add_set_with_table( &the_extension->Extension, extension_table );
+ _Thread_Enable_dispatch();
_Objects_Open(
&_Extension_Information,
@@ -57,6 +58,6 @@ rtems_status_code rtems_extension_create(
);
*id = the_extension->Object.id;
- _Thread_Enable_dispatch();
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
}
diff --git a/cpukit/sapi/src/extensiondelete.c b/cpukit/sapi/src/extensiondelete.c
index 0eaaffd..f6d6e06 100644
--- a/cpukit/sapi/src/extensiondelete.c
+++ b/cpukit/sapi/src/extensiondelete.c
@@ -29,14 +29,17 @@ rtems_status_code rtems_extension_delete(
{
Extension_Control *the_extension;
Objects_Locations location;
+ bool previous_thread_life_protection;
+ previous_thread_life_protection = _Objects_Allocator_lock();
the_extension = _Extension_Get( id, &location );
switch ( location ) {
case OBJECTS_LOCAL:
_User_extensions_Remove_set( &the_extension->Extension );
_Objects_Close( &_Extension_Information, &the_extension->Object );
- _Extension_Free( the_extension );
_Objects_Put( &the_extension->Object );
+ _Extension_Free( the_extension );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -46,5 +49,7 @@ rtems_status_code rtems_extension_delete(
break;
}
+ _Objects_Allocator_unlock( previous_thread_life_protection );
+
return RTEMS_INVALID_ID;
}
diff --git a/cpukit/score/include/rtems/score/objectimpl.h b/cpukit/score/include/rtems/score/objectimpl.h
index 119f11d..ceaff44 100644
--- a/cpukit/score/include/rtems/score/objectimpl.h
+++ b/cpukit/score/include/rtems/score/objectimpl.h
@@ -20,6 +20,7 @@
#define _RTEMS_SCORE_OBJECTIMPL_H
#include <rtems/score/object.h>
+#include <rtems/score/apimutex.h>
#include <rtems/score/isrlevel.h>
#include <rtems/score/threaddispatch.h>
@@ -263,16 +264,26 @@ unsigned int _Objects_API_maximum_class(
uint32_t api
);
+Objects_Control *_Objects_Allocate_unprotected(
+ Objects_Information *information
+);
+
/**
- * @brief Allocate an object.
+ * @brief Allocates an object.
*
- * This function allocates an object control block from
- * the inactive chain of free object control blocks.
+ * This function locks the object allocator mutex. The caller must later
+ * unlock the object allocator mutex via _Objects_Allocator_unlock().
*
- * @param[in] information points to an object class information block.
+ * @param[in] information The object information block.
+ * @param[out] previous_thread_life_protection The previous thread life
+ * protection. Must be passed to _Objects_Allocator_unlock().
+ *
+ * @retval NULL No object available.
+ * @retval object The allocated object.
*/
Objects_Control *_Objects_Allocate(
- Objects_Information *information
+ Objects_Information *information,
+ bool *previous_thread_life_protection
);
/**
@@ -892,6 +903,18 @@ RTEMS_INLINE_ROUTINE void _Objects_Put_for_get_isr_disable(
#endif
}
+RTEMS_INLINE_ROUTINE bool _Objects_Allocator_lock( void )
+{
+ return _RTEMS_Lock_allocator();
+}
+
+RTEMS_INLINE_ROUTINE void _Objects_Allocator_unlock(
+ bool previous_thread_life_protection
+)
+{
+ _RTEMS_Unlock_allocator( previous_thread_life_protection);
+}
+
/** @} */
#ifdef __cplusplus
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 9166e9d..06e2509 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -574,13 +574,10 @@ RTEMS_INLINE_ROUTINE uint32_t _Thread_Get_maximum_internal_threads(void)
return maximum_internal_threads;
}
-/**
- * This routine allocates an internal thread.
- */
-
RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
{
- return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
+ return (Thread_Control *)
+ _Objects_Allocate_unprotected( &_Thread_Internal_information );
}
RTEMS_INLINE_ROUTINE void _Thread_Request_dispatch_if_executing(
diff --git a/cpukit/score/src/apimutex.c b/cpukit/score/src/apimutex.c
index 18ac2db8..7899934 100644
--- a/cpukit/score/src/apimutex.c
+++ b/cpukit/score/src/apimutex.c
@@ -58,7 +58,8 @@ void _API_Mutex_Allocate(
0
};
- mutex = (API_Mutex_Control *) _Objects_Allocate( &_API_Mutex_Information );
+ mutex = (API_Mutex_Control *)
+ _Objects_Allocate_unprotected( &_API_Mutex_Information );
_CORE_mutex_Initialize( &mutex->Mutex, NULL, &attr, CORE_MUTEX_UNLOCKED );
diff --git a/cpukit/score/src/objectactivecount.c b/cpukit/score/src/objectactivecount.c
index de34212..de3243a 100644
--- a/cpukit/score/src/objectactivecount.c
+++ b/cpukit/score/src/objectactivecount.c
@@ -17,14 +17,20 @@
#endif
#include <rtems/score/objectimpl.h>
+#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
Objects_Maximum _Objects_Active_count(
const Objects_Information *information
)
{
- size_t inactive = _Chain_Node_count_unprotected( &information->Inactive );
- size_t maximum = information->maximum;
+ size_t inactive;
+ size_t maximum;
+
+ _Assert( _Debug_Is_owner_of_allocator() );
+
+ inactive = _Chain_Node_count_unprotected( &information->Inactive );
+ maximum = information->maximum;
return (Objects_Maximum) ( maximum - inactive );
}
diff --git a/cpukit/score/src/objectallocate.c b/cpukit/score/src/objectallocate.c
index 842c49d..2850590 100644
--- a/cpukit/score/src/objectallocate.c
+++ b/cpukit/score/src/objectallocate.c
@@ -19,7 +19,9 @@
#endif
#include <rtems/score/objectimpl.h>
+#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
+#include <rtems/score/sysstate.h>
/* #define RTEMS_DEBUG_OBJECT_ALLOCATION */
@@ -27,12 +29,24 @@
#include <rtems/bspIo.h>
#endif
-Objects_Control *_Objects_Allocate(
+static Objects_Control *_Objects_Get_inactive(
+ Objects_Information *information
+)
+{
+ return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
+}
+
+Objects_Control *_Objects_Allocate_unprotected(
Objects_Information *information
)
{
Objects_Control *the_object;
+ _Assert(
+ _Debug_Is_owner_of_allocator()
+ || !_System_state_Is_up( _System_state_Get() )
+ );
+
/*
* If the application is using the optional manager stubs and
* still attempts to create the object, the information block
@@ -46,7 +60,7 @@ Objects_Control *_Objects_Allocate(
* OK. The manager should be initialized and configured to have objects.
* With any luck, it is safe to attempt to allocate an object.
*/
- the_object = (Objects_Control *) _Chain_Get( &information->Inactive );
+ the_object = _Objects_Get_inactive( information );
if ( information->auto_extend ) {
/*
@@ -56,7 +70,7 @@ Objects_Control *_Objects_Allocate(
if ( !the_object ) {
_Objects_Extend_information( information );
- the_object = (Objects_Control *) _Chain_Get( &information->Inactive );
+ the_object = _Objects_Get_inactive( information );
}
if ( the_object ) {
@@ -83,3 +97,13 @@ Objects_Control *_Objects_Allocate(
return the_object;
}
+
+Objects_Control *_Objects_Allocate(
+ Objects_Information *information,
+ bool *previous_thread_life_protection
+)
+{
+ *previous_thread_life_protection = _RTEMS_Lock_allocator();
+
+ return _Objects_Allocate_unprotected( information );
+}
diff --git a/cpukit/score/src/objectextendinformation.c b/cpukit/score/src/objectextendinformation.c
index d11f927..b1fcec7 100644
--- a/cpukit/score/src/objectextendinformation.c
+++ b/cpukit/score/src/objectextendinformation.c
@@ -20,8 +20,10 @@
#include <rtems/score/objectimpl.h>
#include <rtems/score/address.h>
+#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
#include <rtems/score/isrlevel.h>
+#include <rtems/score/sysstate.h>
#include <rtems/score/wkspace.h>
#include <string.h> /* for memcpy() */
@@ -42,10 +44,10 @@ void _Objects_Extend_information(
)
{
Objects_Control *the_object;
- Chain_Control Inactive;
uint32_t block_count;
uint32_t block;
uint32_t index_base;
+ uint32_t index_end;
uint32_t minimum_index;
uint32_t index;
uint32_t maximum;
@@ -53,6 +55,11 @@ void _Objects_Extend_information(
void *new_object_block;
bool do_extend;
+ _Assert(
+ _Debug_Is_owner_of_allocator()
+ || !_System_state_Is_up( _System_state_Get() )
+ );
+
/*
* Search for a free block of indexes. If we do NOT need to allocate or
* extend the block table, then we will change do_extend.
@@ -76,6 +83,7 @@ void _Objects_Extend_information(
index_base += information->allocation_size;
}
}
+ index_end = index_base + information->allocation_size;
maximum = (uint32_t) information->maximum + information->allocation_size;
@@ -213,12 +221,11 @@ void _Objects_Extend_information(
object_blocks[block_count] = NULL;
inactive_per_block[block_count] = 0;
- for ( index=index_base ;
- index < ( information->allocation_size + index_base );
- index++ ) {
+ for ( index = index_base ; index < index_end ; ++index ) {
local_table[ index ] = NULL;
}
+ _Thread_Disable_dispatch();
_ISR_Disable( level );
old_tables = information->object_blocks;
@@ -235,6 +242,7 @@ void _Objects_Extend_information(
);
_ISR_Enable( level );
+ _Thread_Enable_dispatch();
_Workspace_Free( old_tables );
@@ -247,32 +255,21 @@ void _Objects_Extend_information(
information->object_blocks[ block ] = new_object_block;
/*
- * Initialize objects .. add to a local chain first.
+ * Append to inactive chain.
*/
- _Chain_Initialize(
- &Inactive,
- information->object_blocks[ block ],
- information->allocation_size,
- information->size
- );
-
- /*
- * Move from the local chain, initialise, then append to the inactive chain
- */
- index = index_base;
-
- while ((the_object = (Objects_Control *) _Chain_Get( &Inactive )) != NULL ) {
-
+ the_object = information->object_blocks[ block ];
+ for ( index = index_base ; index < index_end ; ++index ) {
the_object->id = _Objects_Build_id(
- information->the_api,
- information->the_class,
- _Objects_Local_node,
- index
- );
+ information->the_api,
+ information->the_class,
+ _Objects_Local_node,
+ index
+ );
- _Chain_Append( &information->Inactive, &the_object->Node );
+ _Chain_Append_unprotected( &information->Inactive, &the_object->Node );
- index++;
+ the_object = (Objects_Control *)
+ ( (char *) the_object + information->size );
}
information->inactive_per_block[ block ] = information->allocation_size;
diff --git a/cpukit/score/src/objectfree.c b/cpukit/score/src/objectfree.c
index cc2fbac..f1c0ee4 100644
--- a/cpukit/score/src/objectfree.c
+++ b/cpukit/score/src/objectfree.c
@@ -19,6 +19,7 @@
#endif
#include <rtems/score/objectimpl.h>
+#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
void _Objects_Free(
@@ -28,7 +29,9 @@ void _Objects_Free(
{
uint32_t allocation_size = information->allocation_size;
- _Chain_Append( &information->Inactive, &the_object->Node );
+ _Assert( _Debug_Is_owner_of_allocator() );
+
+ _Chain_Append_unprotected( &information->Inactive, &the_object->Node );
if ( information->auto_extend ) {
uint32_t block;
diff --git a/cpukit/score/src/objectshrinkinformation.c b/cpukit/score/src/objectshrinkinformation.c
index 9731c21..2f64cd2 100644
--- a/cpukit/score/src/objectshrinkinformation.c
+++ b/cpukit/score/src/objectshrinkinformation.c
@@ -19,6 +19,7 @@
#endif
#include <rtems/score/objectimpl.h>
+#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
#include <rtems/score/wkspace.h>
@@ -30,6 +31,8 @@ void _Objects_Shrink_information(
uint32_t block;
uint32_t index_base;
+ _Assert( _Debug_Is_owner_of_allocator() );
+
/*
* Search the list to find block or chunk with all objects inactive.
*/
@@ -55,7 +58,7 @@ void _Objects_Shrink_information(
node = _Chain_Next( node );
if ( index >= index_base && index < index_end ) {
- _Chain_Extract( &object->Node );
+ _Chain_Extract_unprotected( &object->Node );
}
}
diff --git a/testsuites/sptests/spobjgetnext/init.c b/testsuites/sptests/spobjgetnext/init.c
index 9682c34..fad005f 100644
--- a/testsuites/sptests/spobjgetnext/init.c
+++ b/testsuites/sptests/spobjgetnext/init.c
@@ -72,6 +72,7 @@ rtems_task Init(
Objects_Id id;
Objects_Information *info;
Objects_Maximum active_count;
+ bool previous_thread_life_protection;
TEST_BEGIN();
@@ -108,7 +109,9 @@ rtems_task Init(
/* XXX try with a manager with no objects created */
puts( "Init - _Objects_Active_count" );
+ previous_thread_life_protection = _Objects_Allocator_lock();
active_count = _Objects_Active_count( info );
+ _Objects_Allocator_unlock( previous_thread_life_protection );
rtems_test_assert( active_count == 1 );
TEST_END();
--
1.7.7
More information about the devel
mailing list