score: PR2152: Use allocator mutex for objects

Use allocator mutex for objects allocate/free.  This prevents that the
thread dispatch latency depends on the workspace/heap fragmentation.
This commit is contained in:
Sebastian Huber
2014-03-31 08:29:44 +02:00
parent 346845730c
commit 23fec9f0e1
63 changed files with 421 additions and 319 deletions
+7 -17
View File
@@ -98,38 +98,28 @@ 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;
free_all_delayed_blocks();
_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();
#ifndef RTEMS_POSIX_API
memset(&snapshot->posix_api, 0, sizeof(snapshot->posix_api));
+5 -16
View File
@@ -67,16 +67,6 @@ extern void (*_POSIX_Threads_Initialize_user_threads_p)(void);
*/
void _POSIX_Threads_Manager_initialization(void);
/**
* @brief Allocate POSIX thread control block.
*
* This function allocates a pthread control block from
* the inactive chain of free pthread control blocks.
*
* @return This method returns a newly allocated thread.
*/
RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void );
/**
* @brief Copy POSIX Thread attribute structure.
*
@@ -211,15 +201,14 @@ int rtems_pthread_attribute_compare(
const pthread_attr_t *attr2
);
/*
* _POSIX_Threads_Allocate
*/
RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void )
RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
{
_Objects_Allocator_lock();
_Thread_Kill_zombies();
return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information );
return (Thread_Control *)
_Objects_Allocate_unprotected( &_POSIX_Threads_Information );
}
/*
@@ -48,20 +48,13 @@ extern const int
*/
void _POSIX_Semaphore_Manager_initialization(void);
/**
* @brief POSIX Semaphore Allocate
*
* This function allocates a semaphore control block from
* the inactive chain of free semaphore control blocks.
*/
RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void )
RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
_POSIX_Semaphore_Allocate_unprotected( void )
{
return (POSIX_Semaphore_Control *)
_Objects_Allocate( &_POSIX_Semaphore_Information );
_Objects_Allocate_unprotected( &_POSIX_Semaphore_Information );
}
/**
* @brief POSIX Semaphore Free
*
+6 -2
View File
@@ -38,6 +38,7 @@ int pthread_cond_destroy(
POSIX_Condition_variables_Control *the_cond;
Objects_Locations location;
_Objects_Allocator_lock();
the_cond = _POSIX_Condition_variables_Get( cond, &location );
switch ( location ) {
@@ -45,6 +46,7 @@ int pthread_cond_destroy(
if ( _Thread_queue_First( &the_cond->Wait_queue ) ) {
_Objects_Put( &the_cond->Object );
_Objects_Allocator_unlock();
return EBUSY;
}
@@ -52,9 +54,9 @@ int pthread_cond_destroy(
&_POSIX_Condition_variables_Information,
&the_cond->Object
);
_POSIX_Condition_variables_Free( the_cond );
_Objects_Put( &the_cond->Object );
_POSIX_Condition_variables_Free( the_cond );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -64,5 +66,7 @@ int pthread_cond_destroy(
break;
}
_Objects_Allocator_unlock();
return EINVAL;
}
+2 -4
View File
@@ -51,12 +51,10 @@ int pthread_cond_init(
if ( !the_attr->is_initialized )
return EINVAL;
_Thread_Disable_dispatch();
the_cond = _POSIX_Condition_variables_Allocate();
if ( !the_cond ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return ENOMEM;
}
@@ -79,7 +77,7 @@ int pthread_cond_init(
*cond = the_cond->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+2 -4
View File
@@ -38,18 +38,16 @@ int pthread_key_create(
{
POSIX_Keys_Control *the_key;
_Thread_Disable_dispatch();
the_key = _POSIX_Keys_Allocate();
if ( !the_key ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return EAGAIN;
}
the_key->destructor = destructor;
_Objects_Open_u32( &_POSIX_Keys_Information, &the_key->Object, 0 );
*key = the_key->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+4
View File
@@ -38,6 +38,7 @@ int pthread_key_delete(
POSIX_Keys_Control *the_key;
Objects_Locations location;
_Objects_Allocator_lock();
the_key = _POSIX_Keys_Get( key, &location );
switch ( location ) {
@@ -50,6 +51,7 @@ int pthread_key_delete(
*/
_POSIX_Keys_Free( the_key );
_Objects_Put(&the_key->Object);
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -59,5 +61,7 @@ int pthread_key_delete(
break;
}
_Objects_Allocator_unlock();
return EINVAL;
}
+4
View File
@@ -57,6 +57,7 @@ int mq_close(
POSIX_Message_queue_Control_fd *the_mq_fd;
Objects_Locations location;
_Objects_Allocator_lock();
the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
if ( location == OBJECTS_LOCAL ) {
/* OBJECTS_LOCAL:
@@ -79,9 +80,12 @@ int mq_close(
_POSIX_Message_queue_Free_fd( the_mq_fd );
_Objects_Put( &the_mq_fd->Object );
_Objects_Allocator_unlock();
return 0;
}
_Objects_Allocator_unlock();
/*
* OBJECTS_REMOTE:
* OBJECTS_ERROR:
+4 -8
View File
@@ -62,8 +62,6 @@ int _POSIX_Message_queue_Create_support(
/* length of name has already been validated */
_Thread_Disable_dispatch();
/*
* There is no real basis for the default values. They will work
* but were not compared against any existing implementation for
@@ -75,12 +73,10 @@ int _POSIX_Message_queue_Create_support(
attr.mq_msgsize = 16;
} else {
if ( attr_ptr->mq_maxmsg <= 0 ){
_Thread_Enable_dispatch();
rtems_set_errno_and_return_minus_one( EINVAL );
}
if ( attr_ptr->mq_msgsize <= 0 ){
_Thread_Enable_dispatch();
rtems_set_errno_and_return_minus_one( EINVAL );
}
@@ -89,7 +85,7 @@ int _POSIX_Message_queue_Create_support(
the_mq = _POSIX_Message_queue_Allocate();
if ( !the_mq ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( ENFILE );
}
@@ -100,7 +96,7 @@ int _POSIX_Message_queue_Create_support(
name = _Workspace_String_duplicate( name_arg, name_len );
if ( !name ) {
_POSIX_Message_queue_Free( the_mq );
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( ENOMEM );
}
@@ -128,7 +124,7 @@ int _POSIX_Message_queue_Create_support(
_POSIX_Message_queue_Free( the_mq );
_Workspace_Free(name);
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( ENOSPC );
}
@@ -140,6 +136,6 @@ int _POSIX_Message_queue_Create_support(
*message_queue = the_mq;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+6 -8
View File
@@ -72,8 +72,6 @@ mqd_t mq_open(
Objects_Locations location;
size_t name_len;
_Thread_Disable_dispatch();
if ( oflag & O_CREAT ) {
va_start(arg, oflag);
mode = va_arg( arg, mode_t );
@@ -83,7 +81,7 @@ mqd_t mq_open(
the_mq_fd = _POSIX_Message_queue_Allocate_fd();
if ( !the_mq_fd ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( ENFILE );
}
the_mq_fd->oflag = oflag;
@@ -103,7 +101,7 @@ mqd_t mq_open(
*/
if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
_POSIX_Message_queue_Free_fd( the_mq_fd );
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one_cast( status, mqd_t );
}
@@ -113,7 +111,7 @@ mqd_t mq_open(
*/
if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
_POSIX_Message_queue_Free_fd( the_mq_fd );
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
}
@@ -130,7 +128,7 @@ mqd_t mq_open(
NULL
);
_Thread_Enable_dispatch();
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return (mqd_t)the_mq_fd->Object.id;
}
@@ -152,7 +150,7 @@ mqd_t mq_open(
*/
if ( status == -1 ) {
_POSIX_Message_queue_Free_fd( the_mq_fd );
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return (mqd_t) -1;
}
@@ -163,7 +161,7 @@ mqd_t mq_open(
NULL
);
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return (mqd_t) the_mq_fd->Object.id;
}
+3
View File
@@ -46,11 +46,13 @@ int mq_unlink(
Objects_Id the_mq_id;
size_t name_len;
_Objects_Allocator_lock();
_Thread_Disable_dispatch();
status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id, &name_len );
if ( status != 0 ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( status );
}
@@ -64,5 +66,6 @@ int mq_unlink(
_POSIX_Message_queue_Delete( the_mq );
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+7 -3
View File
@@ -39,6 +39,7 @@ int pthread_mutex_destroy(
register POSIX_Mutex_Control *the_mutex;
Objects_Locations location;
_Objects_Allocator_lock();
the_mutex = _POSIX_Mutex_Get( mutex, &location );
switch ( location ) {
@@ -50,15 +51,16 @@ int pthread_mutex_destroy(
if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
_Objects_Put( &the_mutex->Object );
_Objects_Allocator_unlock();
return EBUSY;
}
_Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object );
_CORE_mutex_Flush( &the_mutex->Mutex, NULL, EINVAL );
_POSIX_Mutex_Free( the_mutex );
_Objects_Put( &the_mutex->Object );
_POSIX_Mutex_Free( the_mutex );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -68,5 +70,7 @@ int pthread_mutex_destroy(
break;
}
_Objects_Allocator_unlock();
return EINVAL;
}
+2 -7
View File
@@ -149,15 +149,10 @@ int pthread_mutex_init(
}
#endif
/*
* Enter a dispatching critical section and begin to do the real work.
*/
_Thread_Disable_dispatch();
the_mutex = _POSIX_Mutex_Allocate();
if ( !the_mutex ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return EAGAIN;
}
@@ -188,6 +183,6 @@ int pthread_mutex_init(
*mutex = the_mutex->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+5 -2
View File
@@ -45,6 +45,7 @@ int pthread_barrier_destroy(
if ( !barrier )
return EINVAL;
_Objects_Allocator_lock();
the_barrier = _POSIX_Barrier_Get( barrier, &location );
switch ( location ) {
@@ -55,10 +56,10 @@ int pthread_barrier_destroy(
}
_Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object );
_Objects_Put( &the_barrier->Object );
_POSIX_Barrier_Free( the_barrier );
_Objects_Put( &the_barrier->Object );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -68,5 +69,7 @@ int pthread_barrier_destroy(
break;
}
_Objects_Allocator_unlock();
return EINVAL;
}
+2 -10
View File
@@ -92,15 +92,10 @@ int pthread_barrier_init(
the_attributes.discipline = CORE_BARRIER_AUTOMATIC_RELEASE;
the_attributes.maximum_count = count;
/*
* Enter dispatching critical section to allocate and initialize barrier
*/
_Thread_Disable_dispatch(); /* prevents deletion */
the_barrier = _POSIX_Barrier_Allocate();
if ( !the_barrier ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return EAGAIN;
}
@@ -112,10 +107,7 @@ int pthread_barrier_init(
0
);
/*
* Exit the critical section and return the user an operational barrier
*/
*barrier = the_barrier->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+7 -3
View File
@@ -44,6 +44,7 @@ int pthread_rwlock_destroy(
if ( !rwlock )
return EINVAL;
_Objects_Allocator_lock();
the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
switch ( location ) {
@@ -53,6 +54,7 @@ int pthread_rwlock_destroy(
*/
if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) {
_Objects_Put( &the_rwlock->Object );
_Objects_Allocator_unlock();
return EBUSY;
}
@@ -61,10 +63,10 @@ int pthread_rwlock_destroy(
*/
_Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
_POSIX_RWLock_Free( the_rwlock );
_Objects_Put( &the_rwlock->Object );
_POSIX_RWLock_Free( the_rwlock );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -74,5 +76,7 @@ int pthread_rwlock_destroy(
break;
}
_Objects_Allocator_unlock();
return EINVAL;
}
+2 -7
View File
@@ -88,15 +88,10 @@ int pthread_rwlock_init(
*/
_CORE_RWLock_Initialize_attributes( &the_attributes );
/*
* Enter dispatching critical section to allocate and initialize RWLock
*/
_Thread_Disable_dispatch(); /* prevents deletion */
the_rwlock = _POSIX_RWLock_Allocate();
if ( !the_rwlock ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return EAGAIN;
}
@@ -110,6 +105,6 @@ int pthread_rwlock_init(
*rwlock = the_rwlock->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+6 -3
View File
@@ -45,6 +45,7 @@ int pthread_spin_destroy(
if ( !spinlock )
return EINVAL;
_Objects_Allocator_lock();
the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
switch ( location ) {
@@ -55,10 +56,10 @@ int pthread_spin_destroy(
}
_Objects_Close( &_POSIX_Spinlock_Information, &the_spinlock->Object );
_POSIX_Spinlock_Free( the_spinlock );
_Objects_Put( &the_spinlock->Object );
_POSIX_Spinlock_Free( the_spinlock );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -68,5 +69,7 @@ int pthread_spin_destroy(
break;
}
_Objects_Allocator_unlock();
return EINVAL;
}
+2 -5
View File
@@ -49,7 +49,6 @@ int pthread_spin_init(
POSIX_Spinlock_Control *the_spinlock;
CORE_spinlock_Attributes attributes;
if ( !spinlock )
return EINVAL;
@@ -61,12 +60,10 @@ int pthread_spin_init(
return EINVAL;
}
_Thread_Disable_dispatch(); /* prevents deletion */
the_spinlock = _POSIX_Spinlock_Allocate();
if ( !the_spinlock ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return EAGAIN;
}
@@ -78,6 +75,6 @@ int pthread_spin_init(
*spinlock = the_spinlock->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+4 -9
View File
@@ -155,11 +155,6 @@ int pthread_create(
is_fp = false;
#endif
/*
* Lock the allocator mutex for protection
*/
_RTEMS_Lock_allocator();
/*
* Allocate the thread control block.
*
@@ -167,7 +162,7 @@ int pthread_create(
*/
the_thread = _POSIX_Threads_Allocate();
if ( !the_thread ) {
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return EAGAIN;
}
@@ -190,7 +185,7 @@ int pthread_create(
);
if ( !status ) {
_POSIX_Threads_Free( the_thread );
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return EAGAIN;
}
@@ -235,7 +230,7 @@ int pthread_create(
if ( !status ) {
_Thread_Enable_dispatch();
_POSIX_Threads_Free( the_thread );
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return EINVAL;
}
#endif
@@ -254,6 +249,6 @@ int pthread_create(
*/
*thread = the_thread->Object.id;
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return 0;
}
+1 -6
View File
@@ -56,11 +56,8 @@ int _POSIX_Semaphore_Create_support(
if (pshared != 0)
rtems_set_errno_and_return_minus_one( ENOSYS );
_Thread_Disable_dispatch();
the_semaphore = _POSIX_Semaphore_Allocate();
the_semaphore = _POSIX_Semaphore_Allocate_unprotected();
if ( !the_semaphore ) {
_Thread_Enable_dispatch();
rtems_set_errno_and_return_minus_one( ENOSPC );
}
@@ -72,7 +69,6 @@ int _POSIX_Semaphore_Create_support(
name = _Workspace_String_duplicate( name_arg, name_len );
if ( !name ) {
_POSIX_Semaphore_Free( the_semaphore );
_Thread_Enable_dispatch();
rtems_set_errno_and_return_minus_one( ENOMEM );
}
} else {
@@ -120,6 +116,5 @@ int _POSIX_Semaphore_Create_support(
*the_sem = the_semaphore;
_Thread_Enable_dispatch();
return 0;
}
+4
View File
@@ -38,6 +38,7 @@ int sem_close(
POSIX_Semaphore_Control *the_semaphore;
Objects_Locations location;
_Objects_Allocator_lock();
the_semaphore = _POSIX_Semaphore_Get( sem, &location );
switch ( location ) {
@@ -45,6 +46,7 @@ int sem_close(
the_semaphore->open_count -= 1;
_POSIX_Semaphore_Delete( the_semaphore );
_Objects_Put( &the_semaphore->Object );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -54,5 +56,7 @@ int sem_close(
break;
}
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( EINVAL );
}
+4
View File
@@ -38,6 +38,7 @@ int sem_destroy(
POSIX_Semaphore_Control *the_semaphore;
Objects_Locations location;
_Objects_Allocator_lock();
the_semaphore = _POSIX_Semaphore_Get( sem, &location );
switch ( location ) {
@@ -53,6 +54,7 @@ int sem_destroy(
_POSIX_Semaphore_Delete( the_semaphore );
_Objects_Put( &the_semaphore->Object );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -62,5 +64,7 @@ int sem_destroy(
break;
}
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( EINVAL );
}
+2
View File
@@ -47,6 +47,7 @@ int sem_init(
if ( !sem )
rtems_set_errno_and_return_minus_one( EINVAL );
_Objects_Allocator_lock();
status = _POSIX_Semaphore_Create_support(
NULL,
0,
@@ -54,6 +55,7 @@ int sem_init(
value,
&the_semaphore
);
_Objects_Allocator_unlock();
if ( status != -1 )
*sem = the_semaphore->Object.id;
+5 -6
View File
@@ -66,8 +66,6 @@ sem_t *sem_open(
Objects_Locations location;
size_t name_len;
_Thread_Disable_dispatch();
if ( oflag & O_CREAT ) {
va_start(arg, oflag);
mode = va_arg( arg, mode_t );
@@ -75,6 +73,7 @@ sem_t *sem_open(
va_end(arg);
}
_Objects_Allocator_lock();
status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len );
/*
@@ -92,7 +91,7 @@ sem_t *sem_open(
*/
if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one_cast( status, sem_t * );
}
} else {
@@ -102,14 +101,14 @@ sem_t *sem_open(
*/
if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one_cast( EEXIST, sem_t * );
}
the_semaphore = _POSIX_Semaphore_Get( (sem_t *) &the_semaphore_id, &location );
the_semaphore->open_count += 1;
_Thread_Enable_dispatch();
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
goto return_id;
}
@@ -130,7 +129,7 @@ sem_t *sem_open(
* errno was set by Create_support, so don't set it again.
*/
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
if ( status == -1 )
return SEM_FAILED;
+7 -4
View File
@@ -35,11 +35,12 @@ int sem_unlink(
const char *name
)
{
int status;
POSIX_Semaphore_Control *the_semaphore;
Objects_Id the_semaphore_id;
size_t name_len;
int status;
POSIX_Semaphore_Control *the_semaphore;
Objects_Id the_semaphore_id;
size_t name_len;
_Objects_Allocator_lock();
_Thread_Disable_dispatch();
status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len );
@@ -58,5 +59,7 @@ int sem_unlink(
_POSIX_Semaphore_Delete( the_semaphore );
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return 0;
}
+3 -5
View File
@@ -66,21 +66,19 @@ int timer_create(
rtems_set_errno_and_return_minus_one( EINVAL );
}
_Thread_Disable_dispatch(); /* to prevent deletion */
/*
* Allocate a timer
*/
ptimer = _POSIX_Timer_Allocate();
if ( !ptimer ) {
_Objects_Put( &ptimer->Object );
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( EAGAIN );
}
/* The data of the created timer are stored to use them later */
ptimer->state = POSIX_TIMER_STATE_CREATE_NEW;
ptimer->thread_id = _Thread_Executing->Object.id;
ptimer->thread_id = _Thread_Get_executing()->Object.id;
if ( evp != NULL ) {
ptimer->inf.sigev_notify = evp->sigev_notify;
@@ -98,6 +96,6 @@ int timer_create(
_Objects_Open_u32(&_POSIX_Timer_Information, &ptimer->Object, 0);
*timerid = ptimer->Object.id;
_Objects_Put( &ptimer->Object );
_Objects_Allocator_unlock();
return 0;
}
+6 -1
View File
@@ -47,6 +47,7 @@ int timer_delete(
POSIX_Timer_Control *ptimer;
Objects_Locations location;
_Objects_Allocator_lock();
ptimer = _POSIX_Timer_Get( timerid, &location );
switch ( location ) {
@@ -54,8 +55,10 @@ int timer_delete(
_Objects_Close( &_POSIX_Timer_Information, &ptimer->Object );
ptimer->state = POSIX_TIMER_STATE_FREE;
(void) _Watchdog_Remove( &ptimer->Timer );
_POSIX_Timer_Free( ptimer );
_Objects_Put( &ptimer->Object );
_POSIX_Timer_Free( ptimer );
_Objects_Allocator_unlock();
return 0;
#if defined(RTEMS_MULTIPROCESSING)
@@ -65,5 +68,7 @@ int timer_delete(
break;
}
_Objects_Allocator_unlock();
rtems_set_errno_and_return_minus_one( EINVAL );
}
-1
View File
@@ -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
+6 -10
View File
@@ -89,16 +89,6 @@ rtems_status_code _Message_queue_Submit(
Message_queue_Submit_types submit_type
);
/**
* @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
*
@@ -162,6 +152,12 @@ 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( void )
{
return (Message_queue_Control *)
_Objects_Allocate( &_Message_queue_Information );
}
/**@}*/
#ifdef __cplusplus
+5 -8
View File
@@ -77,17 +77,14 @@ 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(void)
{
_Objects_Allocator_lock();
_Thread_Kill_zombies();
return (Thread_Control *) _Objects_Allocate( &_RTEMS_tasks_Information );
return (Thread_Control *)
_Objects_Allocate_unprotected( &_RTEMS_tasks_Information );
}
/**
+2 -4
View File
@@ -68,12 +68,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();
if ( !the_barrier ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_TOO_MANY;
}
@@ -89,6 +87,6 @@ rtems_status_code rtems_barrier_create(
*id = the_barrier->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}
+5 -3
View File
@@ -28,6 +28,7 @@ rtems_status_code rtems_barrier_delete(
Barrier_Control *the_barrier;
Objects_Locations location;
_Objects_Allocator_lock();
the_barrier = _Barrier_Get( id, &location );
switch ( location ) {
@@ -39,10 +40,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();
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -52,5 +52,7 @@ rtems_status_code rtems_barrier_delete(
break;
}
_Objects_Allocator_unlock();
return RTEMS_INVALID_ID;
}
+3 -5
View File
@@ -33,7 +33,7 @@ rtems_status_code rtems_port_create(
rtems_id *id
)
{
Dual_ported_memory_Control *the_port;
Dual_ported_memory_Control *the_port;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -45,12 +45,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();
if ( !the_port ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_TOO_MANY;
}
@@ -65,6 +63,6 @@ rtems_status_code rtems_port_create(
);
*id = the_port->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}
+5 -1
View File
@@ -32,13 +32,15 @@ rtems_status_code rtems_port_delete(
Dual_ported_memory_Control *the_port;
Objects_Locations location;
_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();
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -48,5 +50,7 @@ rtems_status_code rtems_port_delete(
break;
}
_Objects_Allocator_unlock();
return RTEMS_INVALID_ID;
}
-37
View File
@@ -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);
}
+4 -6
View File
@@ -81,12 +81,10 @@ rtems_status_code rtems_message_queue_create(
#endif
#endif
_Thread_Disable_dispatch(); /* protects object pointer */
the_message_queue = _Message_queue_Allocate();
if ( !the_message_queue ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_TOO_MANY;
}
@@ -95,7 +93,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();
return RTEMS_TOO_MANY;
}
#endif
@@ -120,7 +118,7 @@ rtems_status_code rtems_message_queue_create(
#endif
_Message_queue_Free( the_message_queue );
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_UNSATISFIED;
}
@@ -142,6 +140,6 @@ rtems_status_code rtems_message_queue_create(
);
#endif
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}
+6 -3
View File
@@ -37,6 +37,7 @@ rtems_status_code rtems_message_queue_delete(
Message_queue_Control *the_message_queue;
Objects_Locations location;
_Objects_Allocator_lock();
the_message_queue = _Message_queue_Get( id, &location );
switch ( location ) {
@@ -54,8 +55,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 +71,13 @@ rtems_status_code rtems_message_queue_delete(
}
#endif
_Objects_Put( &the_message_queue->Object );
_Message_queue_Free( the_message_queue );
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE:
_Thread_Dispatch();
_Objects_Allocator_unlock();
return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
#endif
@@ -84,5 +85,7 @@ rtems_status_code rtems_message_queue_delete(
break;
}
_Objects_Allocator_unlock();
return RTEMS_INVALID_ID;
}
+4 -6
View File
@@ -53,7 +53,7 @@ rtems_status_code rtems_partition_create(
rtems_id *id
)
{
Partition_Control *the_partition;
Partition_Control *the_partition;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -77,12 +77,10 @@ rtems_status_code rtems_partition_create(
return RTEMS_MP_NOT_CONFIGURED;
#endif
_Thread_Disable_dispatch(); /* prevents deletion */
the_partition = _Partition_Allocate();
if ( !the_partition ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_TOO_MANY;
}
@@ -91,7 +89,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();
return RTEMS_TOO_MANY;
}
#endif
@@ -122,6 +120,6 @@ rtems_status_code rtems_partition_create(
);
#endif
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}
+7 -2
View File
@@ -29,13 +29,13 @@ rtems_status_code rtems_partition_delete(
Partition_Control *the_partition;
Objects_Locations location;
_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 +54,17 @@ rtems_status_code rtems_partition_delete(
#endif
_Objects_Put( &the_partition->Object );
_Partition_Free( the_partition );
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}
_Objects_Put( &the_partition->Object );
_Objects_Allocator_unlock();
return RTEMS_RESOURCE_IN_USE;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE:
_Thread_Dispatch();
_Objects_Allocator_unlock();
return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
#endif
@@ -69,5 +72,7 @@ rtems_status_code rtems_partition_delete(
break;
}
_Objects_Allocator_unlock();
return RTEMS_INVALID_ID;
}
+3 -5
View File
@@ -55,16 +55,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();
if ( !the_period ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
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 +76,6 @@ rtems_status_code rtems_rate_monotonic_create(
);
*id = the_period->Object.id;
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}
+5 -1
View File
@@ -30,6 +30,7 @@ rtems_status_code rtems_rate_monotonic_delete(
Rate_monotonic_Control *the_period;
Objects_Locations location;
_Objects_Allocator_lock();
the_period = _Rate_monotonic_Get( id, &location );
switch ( location ) {
@@ -38,8 +39,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();
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
@@ -49,5 +51,7 @@ rtems_status_code rtems_rate_monotonic_delete(
break;
}
_Objects_Allocator_unlock();
return RTEMS_INVALID_ID;
}
+3 -4
View File
@@ -66,9 +66,7 @@ rtems_status_code rtems_region_create(
if ( !id )
return RTEMS_INVALID_ADDRESS;
_RTEMS_Lock_allocator(); /* to prevent deletion */
the_region = _Region_Allocate();
the_region = _Region_Allocate();
if ( !the_region )
return_status = RTEMS_TOO_MANY;
@@ -111,6 +109,7 @@ rtems_status_code rtems_region_create(
}
}
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return return_status;
}
+3 -2
View File
@@ -34,7 +34,7 @@ rtems_status_code rtems_region_delete(
rtems_status_code return_status;
Region_Control *the_region;
_RTEMS_Lock_allocator();
_Objects_Allocator_lock();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -61,6 +61,7 @@ rtems_status_code rtems_region_delete(
break;
}
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return return_status;
}
+2 -1
View File
@@ -40,7 +40,7 @@ rtems_status_code rtems_region_extend(
if ( !starting_address )
return RTEMS_INVALID_ADDRESS;
_RTEMS_Lock_allocator(); /* to prevent deletion */
_RTEMS_Lock_allocator(); /* to prevent deletion */
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -75,5 +75,6 @@ rtems_status_code rtems_region_extend(
}
_RTEMS_Unlock_allocator();
return return_status;
}
+2 -1
View File
@@ -47,7 +47,7 @@ rtems_status_code rtems_region_get_segment(
_RTEMS_Lock_allocator();
executing = _Thread_Executing;
executing = _Thread_Get_executing();
the_region = _Region_Get( id, &location );
switch ( location ) {
@@ -110,5 +110,6 @@ rtems_status_code rtems_region_get_segment(
}
_RTEMS_Unlock_allocator();
return return_status;
}
+2 -1
View File
@@ -64,7 +64,8 @@ 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 );
else
_RTEMS_Unlock_allocator();
+5 -7
View File
@@ -100,12 +100,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();
if ( !the_semaphore ) {
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_TOO_MANY;
}
@@ -114,7 +112,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();
return RTEMS_TOO_MANY;
}
#endif
@@ -179,14 +177,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();
return RTEMS_INVALID_PRIORITY;
}
}
@@ -212,6 +210,6 @@ rtems_status_code rtems_semaphore_create(
0 /* Not used */
);
#endif
_Thread_Enable_dispatch();
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}
+8 -3
View File
@@ -44,6 +44,8 @@ rtems_status_code rtems_semaphore_delete(
Semaphore_Control *the_semaphore;
Objects_Locations location;
_Objects_Allocator_lock();
the_semaphore = _Semaphore_Get( id, &location );
switch ( location ) {
@@ -53,6 +55,7 @@ rtems_status_code rtems_semaphore_delete(
!_Attributes_Is_simple_binary_semaphore(
the_semaphore->attribute_set ) ) {
_Objects_Put( &the_semaphore->Object );
_Objects_Allocator_unlock();
return RTEMS_RESOURCE_IN_USE;
}
_CORE_mutex_Flush(
@@ -70,8 +73,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 +86,15 @@ rtems_status_code rtems_semaphore_delete(
);
}
#endif
_Objects_Put( &the_semaphore->Object );
_Semaphore_Free( the_semaphore );
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
#if defined(RTEMS_MULTIPROCESSING)
case OBJECTS_REMOTE:
_Thread_Dispatch();
_Objects_Allocator_unlock();
return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
#endif
@@ -98,5 +102,6 @@ rtems_status_code rtems_semaphore_delete(
break;
}
_Objects_Allocator_unlock();
return RTEMS_INVALID_ID;
}
+4 -9
View File
@@ -104,11 +104,6 @@ rtems_status_code rtems_task_create(
* Make sure system is MP if this task is global
*/
/*
* 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.
@@ -122,7 +117,7 @@ rtems_status_code rtems_task_create(
the_thread = _RTEMS_tasks_Allocate();
if ( !the_thread ) {
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return RTEMS_TOO_MANY;
}
@@ -132,7 +127,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();
return RTEMS_TOO_MANY;
}
}
@@ -164,7 +159,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();
return RTEMS_UNSATISFIED;
}
@@ -195,6 +190,6 @@ rtems_status_code rtems_task_create(
}
#endif
_RTEMS_Unlock_allocator();
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
}

Some files were not shown because too many files have changed in this diff Show More