Changeset 23fec9f in rtems


Ignore:
Timestamp:
Mar 27, 2014, 1:16:12 PM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
f0b4fd9
Parents:
34684573
git-author:
Sebastian Huber <sebastian.huber@…> (03/27/14 13:16:12)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/31/14 06:29:44)
Message:

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.

Files:
1 deleted
62 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/resource_snapshot.c

    r34684573 r23fec9f  
    9999}
    100100
    101 static void free_all_delayed_blocks(void)
    102 {
    103   #ifdef HEAP_PROTECTION
    104     _RTEMS_Lock_allocator();
    105     _Thread_Disable_dispatch();
    106     _Heap_Protection_free_all_delayed_blocks( RTEMS_Malloc_Heap );
    107     _Heap_Protection_free_all_delayed_blocks( &_Workspace_Area );
    108     _Thread_Enable_dispatch();
    109     _RTEMS_Unlock_allocator();
    110   #endif
    111 }
    112 
    113101void rtems_resource_snapshot_take(rtems_resource_snapshot *snapshot)
    114102{
     
    116104  size_t i;
    117105
    118   free_all_delayed_blocks();
     106  _RTEMS_Lock_allocator();
    119107
    120108  _Thread_Kill_zombies();
    121109
    122   _Protected_heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
     110  #ifdef HEAP_PROTECTION
     111    _Heap_Protection_free_all_delayed_blocks(RTEMS_Malloc_Heap);
     112    _Heap_Protection_free_all_delayed_blocks(&_Workspace_Area);
     113  #endif
    123114
    124   _Thread_Disable_dispatch();
    125 
     115  _Heap_Get_information(RTEMS_Malloc_Heap, &snapshot->heap_info);
    126116  _Heap_Get_information(&_Workspace_Area, &snapshot->workspace_info);
    127117
     
    130120  }
    131121
    132   _Thread_Enable_dispatch();
     122  _RTEMS_Unlock_allocator();
    133123
    134124  #ifndef RTEMS_POSIX_API
  • cpukit/posix/include/rtems/posix/pthreadimpl.h

    r34684573 r23fec9f  
    6767 */
    6868void _POSIX_Threads_Manager_initialization(void);
    69 
    70 /**
    71  * @brief Allocate POSIX thread control block.
    72  *
    73  * This function allocates a pthread control block from
    74  * the inactive chain of free pthread control blocks.
    75  *
    76  * @return This method returns a newly allocated thread.
    77  */
    78 RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void );
    7969
    8070/**
     
    212202);
    213203
    214 /*
    215  *  _POSIX_Threads_Allocate
    216  */
    217 
    218 RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate( void )
    219 {
     204RTEMS_INLINE_ROUTINE Thread_Control *_POSIX_Threads_Allocate(void)
     205{
     206  _Objects_Allocator_lock();
     207
    220208  _Thread_Kill_zombies();
    221209
    222   return (Thread_Control *) _Objects_Allocate( &_POSIX_Threads_Information );
     210  return (Thread_Control *)
     211    _Objects_Allocate_unprotected( &_POSIX_Threads_Information );
    223212}
    224213
  • cpukit/posix/include/rtems/posix/semaphoreimpl.h

    r34684573 r23fec9f  
    4949void _POSIX_Semaphore_Manager_initialization(void);
    5050
    51 /**
    52  *  @brief POSIX Semaphore Allocate
    53  *
    54  *  This function allocates a semaphore control block from
    55  *  the inactive chain of free semaphore control blocks.
    56  */
    57 
    58 RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *_POSIX_Semaphore_Allocate( void )
     51RTEMS_INLINE_ROUTINE POSIX_Semaphore_Control *
     52  _POSIX_Semaphore_Allocate_unprotected( void )
    5953{
    6054  return (POSIX_Semaphore_Control *)
    61     _Objects_Allocate( &_POSIX_Semaphore_Information );
     55    _Objects_Allocate_unprotected( &_POSIX_Semaphore_Information );
    6256}
    63 
    6457
    6558/**
  • cpukit/posix/src/conddestroy.c

    r34684573 r23fec9f  
    3939  Objects_Locations                  location;
    4040
     41  _Objects_Allocator_lock();
    4142  the_cond = _POSIX_Condition_variables_Get( cond, &location );
    4243  switch ( location ) {
     
    4647      if ( _Thread_queue_First( &the_cond->Wait_queue ) ) {
    4748        _Objects_Put( &the_cond->Object );
     49        _Objects_Allocator_unlock();
    4850        return EBUSY;
    4951      }
     
    5355        &the_cond->Object
    5456      );
    55 
     57      _Objects_Put( &the_cond->Object );
    5658      _POSIX_Condition_variables_Free( the_cond );
    57       _Objects_Put( &the_cond->Object );
     59      _Objects_Allocator_unlock();
    5860      return 0;
    5961
     
    6567  }
    6668
     69  _Objects_Allocator_unlock();
     70
    6771  return EINVAL;
    6872}
  • cpukit/posix/src/condinit.c

    r34684573 r23fec9f  
    5252    return EINVAL;
    5353
    54   _Thread_Disable_dispatch();
    55 
    5654  the_cond = _POSIX_Condition_variables_Allocate();
    5755
    5856  if ( !the_cond ) {
    59     _Thread_Enable_dispatch();
     57    _Objects_Allocator_unlock();
    6058    return ENOMEM;
    6159  }
     
    8078  *cond = the_cond->Object.id;
    8179
    82   _Thread_Enable_dispatch();
     80  _Objects_Allocator_unlock();
    8381
    8482  return 0;
  • cpukit/posix/src/keycreate.c

    r34684573 r23fec9f  
    3939  POSIX_Keys_Control  *the_key;
    4040
    41   _Thread_Disable_dispatch();
    42 
    4341  the_key = _POSIX_Keys_Allocate();
    4442
    4543  if ( !the_key ) {
    46     _Thread_Enable_dispatch();
     44    _Objects_Allocator_unlock();
    4745    return EAGAIN;
    4846  }
     
    5149  _Objects_Open_u32( &_POSIX_Keys_Information, &the_key->Object, 0 );
    5250  *key = the_key->Object.id;
    53   _Thread_Enable_dispatch();
     51  _Objects_Allocator_unlock();
    5452  return 0;
    5553}
  • cpukit/posix/src/keydelete.c

    r34684573 r23fec9f  
    3939  Objects_Locations   location;
    4040
     41  _Objects_Allocator_lock();
    4142  the_key = _POSIX_Keys_Get( key, &location );
    4243  switch ( location ) {
     
    5152      _POSIX_Keys_Free( the_key );
    5253      _Objects_Put(&the_key->Object);
     54      _Objects_Allocator_unlock();
    5355      return 0;
    5456
     
    6062  }
    6163
     64  _Objects_Allocator_unlock();
     65
    6266  return EINVAL;
    6367}
  • cpukit/posix/src/mqueueclose.c

    r34684573 r23fec9f  
    5858  Objects_Locations               location;
    5959
     60  _Objects_Allocator_lock();
    6061  the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
    6162  if ( location == OBJECTS_LOCAL ) {
     
    8081
    8182      _Objects_Put( &the_mq_fd->Object );
     83      _Objects_Allocator_unlock();
    8284      return 0;
    8385   }
     86
     87   _Objects_Allocator_unlock();
    8488
    8589   /*
  • cpukit/posix/src/mqueuecreatesupp.c

    r34684573 r23fec9f  
    6363  /* length of name has already been validated */
    6464
    65   _Thread_Disable_dispatch();
    66 
    6765  /*
    6866   *  There is no real basis for the default values.  They will work
     
    7674  } else {
    7775    if ( attr_ptr->mq_maxmsg <= 0 ){
    78       _Thread_Enable_dispatch();
    7976      rtems_set_errno_and_return_minus_one( EINVAL );
    8077    }
    8178
    8279    if ( attr_ptr->mq_msgsize <= 0 ){
    83       _Thread_Enable_dispatch();
    8480      rtems_set_errno_and_return_minus_one( EINVAL );
    8581    }
     
    9086  the_mq = _POSIX_Message_queue_Allocate();
    9187  if ( !the_mq ) {
    92     _Thread_Enable_dispatch();
     88    _Objects_Allocator_unlock();
    9389    rtems_set_errno_and_return_minus_one( ENFILE );
    9490  }
     
    10197  if ( !name ) {
    10298    _POSIX_Message_queue_Free( the_mq );
    103     _Thread_Enable_dispatch();
     99    _Objects_Allocator_unlock();
    104100    rtems_set_errno_and_return_minus_one( ENOMEM );
    105101  }
     
    129125    _POSIX_Message_queue_Free( the_mq );
    130126    _Workspace_Free(name);
    131     _Thread_Enable_dispatch();
     127    _Objects_Allocator_unlock();
    132128    rtems_set_errno_and_return_minus_one( ENOSPC );
    133129  }
     
    141137  *message_queue = the_mq;
    142138
    143   _Thread_Enable_dispatch();
     139  _Objects_Allocator_unlock();
    144140  return 0;
    145141}
  • cpukit/posix/src/mqueueopen.c

    r34684573 r23fec9f  
    7373  size_t                          name_len;
    7474
    75   _Thread_Disable_dispatch();
    76 
    7775  if ( oflag & O_CREAT ) {
    7876    va_start(arg, oflag);
     
    8482  the_mq_fd = _POSIX_Message_queue_Allocate_fd();
    8583  if ( !the_mq_fd ) {
    86     _Thread_Enable_dispatch();
     84    _Objects_Allocator_unlock();
    8785    rtems_set_errno_and_return_minus_one( ENFILE );
    8886  }
     
    104102    if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
    105103      _POSIX_Message_queue_Free_fd( the_mq_fd );
    106       _Thread_Enable_dispatch();
     104      _Objects_Allocator_unlock();
    107105      rtems_set_errno_and_return_minus_one_cast( status, mqd_t );
    108106    }
     
    114112    if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
    115113      _POSIX_Message_queue_Free_fd( the_mq_fd );
    116       _Thread_Enable_dispatch();
     114      _Objects_Allocator_unlock();
    117115      rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
    118116    }
     
    131129    );
    132130    _Thread_Enable_dispatch();
    133     _Thread_Enable_dispatch();
     131    _Objects_Allocator_unlock();
    134132    return (mqd_t)the_mq_fd->Object.id;
    135133
     
    153151  if ( status == -1 ) {
    154152    _POSIX_Message_queue_Free_fd( the_mq_fd );
    155     _Thread_Enable_dispatch();
     153    _Objects_Allocator_unlock();
    156154    return (mqd_t) -1;
    157155  }
     
    164162  );
    165163
    166   _Thread_Enable_dispatch();
     164  _Objects_Allocator_unlock();
    167165
    168166  return (mqd_t) the_mq_fd->Object.id;
  • cpukit/posix/src/mqueueunlink.c

    r34684573 r23fec9f  
    4747  size_t                                name_len;
    4848
     49  _Objects_Allocator_lock();
    4950  _Thread_Disable_dispatch();
    5051
     
    5253   if ( status != 0 ) {
    5354    _Thread_Enable_dispatch();
     55    _Objects_Allocator_unlock();
    5456    rtems_set_errno_and_return_minus_one( status );
    5557   }
     
    6567
    6668  _Thread_Enable_dispatch();
     69   _Objects_Allocator_unlock();
    6770  return 0;
    6871}
  • cpukit/posix/src/mutexdestroy.c

    r34684573 r23fec9f  
    4040  Objects_Locations             location;
    4141
     42  _Objects_Allocator_lock();
    4243  the_mutex = _POSIX_Mutex_Get( mutex, &location );
    4344  switch ( location ) {
     
    5152      if ( _CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
    5253        _Objects_Put( &the_mutex->Object );
     54        _Objects_Allocator_unlock();
    5355        return EBUSY;
    5456      }
    5557
    5658      _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object );
     59      _CORE_mutex_Flush( &the_mutex->Mutex, NULL, EINVAL );
     60      _Objects_Put( &the_mutex->Object );
     61      _POSIX_Mutex_Free( the_mutex );
     62      _Objects_Allocator_unlock();
    5763
    58       _CORE_mutex_Flush( &the_mutex->Mutex, NULL, EINVAL );
    59 
    60       _POSIX_Mutex_Free( the_mutex );
    61       _Objects_Put( &the_mutex->Object );
    6264      return 0;
    6365
     
    6971  }
    7072
     73  _Objects_Allocator_unlock();
     74
    7175  return EINVAL;
    7276}
  • cpukit/posix/src/mutexinit.c

    r34684573 r23fec9f  
    150150#endif
    151151
    152   /*
    153    *  Enter a dispatching critical section and begin to do the real work.
    154    */
    155   _Thread_Disable_dispatch();
    156 
    157152  the_mutex = _POSIX_Mutex_Allocate();
    158153
    159154  if ( !the_mutex ) {
    160     _Thread_Enable_dispatch();
     155    _Objects_Allocator_unlock();
    161156    return EAGAIN;
    162157  }
     
    189184  *mutex = the_mutex->Object.id;
    190185
    191   _Thread_Enable_dispatch();
     186  _Objects_Allocator_unlock();
    192187  return 0;
    193188}
  • cpukit/posix/src/pbarrierdestroy.c

    r34684573 r23fec9f  
    4646    return EINVAL;
    4747
     48  _Objects_Allocator_lock();
    4849  the_barrier = _POSIX_Barrier_Get( barrier, &location );
    4950  switch ( location ) {
     
    5657
    5758      _Objects_Close( &_POSIX_Barrier_Information, &the_barrier->Object );
     59      _Objects_Put( &the_barrier->Object );
    5860
    5961      _POSIX_Barrier_Free( the_barrier );
    60 
    61       _Objects_Put( &the_barrier->Object );
     62      _Objects_Allocator_unlock();
    6263      return 0;
    6364
     
    6970  }
    7071
     72  _Objects_Allocator_unlock();
     73
    7174  return EINVAL;
    7275}
  • cpukit/posix/src/pbarrierinit.c

    r34684573 r23fec9f  
    9393  the_attributes.maximum_count = count;
    9494
    95   /*
    96    * Enter dispatching critical section to allocate and initialize barrier
    97    */
    98   _Thread_Disable_dispatch();             /* prevents deletion */
    99 
    10095  the_barrier = _POSIX_Barrier_Allocate();
    10196
    10297  if ( !the_barrier ) {
    103     _Thread_Enable_dispatch();
     98    _Objects_Allocator_unlock();
    10499    return EAGAIN;
    105100  }
     
    113108  );
    114109
    115   /*
    116    * Exit the critical section and return the user an operational barrier
    117    */
    118110  *barrier = the_barrier->Object.id;
    119   _Thread_Enable_dispatch();
     111  _Objects_Allocator_unlock();
    120112  return 0;
    121113}
  • cpukit/posix/src/prwlockdestroy.c

    r34684573 r23fec9f  
    4545    return EINVAL;
    4646
     47  _Objects_Allocator_lock();
    4748  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
    4849  switch ( location ) {
     
    5455      if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) {
    5556        _Objects_Put( &the_rwlock->Object );
     57        _Objects_Allocator_unlock();
    5658        return EBUSY;
    5759      }
     
    6264
    6365      _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
     66      _Objects_Put( &the_rwlock->Object );
     67      _POSIX_RWLock_Free( the_rwlock );
     68      _Objects_Allocator_unlock();
    6469
    65       _POSIX_RWLock_Free( the_rwlock );
    66 
    67       _Objects_Put( &the_rwlock->Object );
    6870      return 0;
    6971
     
    7577  }
    7678
     79  _Objects_Allocator_unlock();
     80
    7781  return EINVAL;
    7882}
  • cpukit/posix/src/prwlockinit.c

    r34684573 r23fec9f  
    8989  _CORE_RWLock_Initialize_attributes( &the_attributes );
    9090
    91   /*
    92    * Enter dispatching critical section to allocate and initialize RWLock
    93    */
    94   _Thread_Disable_dispatch();             /* prevents deletion */
    95 
    9691  the_rwlock = _POSIX_RWLock_Allocate();
    9792
    9893  if ( !the_rwlock ) {
    99     _Thread_Enable_dispatch();
     94    _Objects_Allocator_unlock();
    10095    return EAGAIN;
    10196  }
     
    111106  *rwlock = the_rwlock->Object.id;
    112107
    113   _Thread_Enable_dispatch();
     108  _Objects_Allocator_unlock();
    114109  return 0;
    115110}
  • cpukit/posix/src/pspindestroy.c

    r34684573 r23fec9f  
    4646    return EINVAL;
    4747
     48  _Objects_Allocator_lock();
    4849  the_spinlock = _POSIX_Spinlock_Get( spinlock, &location );
    4950  switch ( location ) {
     
    5657
    5758      _Objects_Close( &_POSIX_Spinlock_Information, &the_spinlock->Object );
     59      _Objects_Put( &the_spinlock->Object );
     60      _POSIX_Spinlock_Free( the_spinlock );
     61      _Objects_Allocator_unlock();
    5862
    59       _POSIX_Spinlock_Free( the_spinlock );
    60 
    61       _Objects_Put( &the_spinlock->Object );
    6263      return 0;
    6364
     
    6970  }
    7071
     72  _Objects_Allocator_unlock();
     73
    7174  return EINVAL;
    7275}
  • cpukit/posix/src/pspininit.c

    r34684573 r23fec9f  
    5050  CORE_spinlock_Attributes  attributes;
    5151
    52 
    5352  if ( !spinlock )
    5453    return EINVAL;
     
    6261  }
    6362
    64   _Thread_Disable_dispatch();             /* prevents deletion */
    65 
    6663  the_spinlock = _POSIX_Spinlock_Allocate();
    6764
    6865  if ( !the_spinlock ) {
    69     _Thread_Enable_dispatch();
     66    _Objects_Allocator_unlock();
    7067    return EAGAIN;
    7168  }
     
    7976  *spinlock = the_spinlock->Object.id;
    8077
    81   _Thread_Enable_dispatch();
     78  _Objects_Allocator_unlock();
    8279  return 0;
    8380}
  • cpukit/posix/src/pthreadcreate.c

    r34684573 r23fec9f  
    157157
    158158  /*
    159    *  Lock the allocator mutex for protection
    160    */
    161   _RTEMS_Lock_allocator();
    162 
    163   /*
    164159   *  Allocate the thread control block.
    165160   *
     
    168163  the_thread = _POSIX_Threads_Allocate();
    169164  if ( !the_thread ) {
    170     _RTEMS_Unlock_allocator();
     165    _Objects_Allocator_unlock();
    171166    return EAGAIN;
    172167  }
     
    191186  if ( !status ) {
    192187    _POSIX_Threads_Free( the_thread );
    193     _RTEMS_Unlock_allocator();
     188    _Objects_Allocator_unlock();
    194189    return EAGAIN;
    195190  }
     
    236231      _Thread_Enable_dispatch();
    237232      _POSIX_Threads_Free( the_thread );
    238       _RTEMS_Unlock_allocator();
     233      _Objects_Allocator_unlock();
    239234      return EINVAL;
    240235    }
     
    255250  *thread = the_thread->Object.id;
    256251
    257   _RTEMS_Unlock_allocator();
     252  _Objects_Allocator_unlock();
    258253  return 0;
    259254}
  • cpukit/posix/src/semaphorecreatesupp.c

    r34684573 r23fec9f  
    5757    rtems_set_errno_and_return_minus_one( ENOSYS );
    5858
    59   _Thread_Disable_dispatch();
    60 
    61   the_semaphore = _POSIX_Semaphore_Allocate();
     59  the_semaphore = _POSIX_Semaphore_Allocate_unprotected();
    6260  if ( !the_semaphore ) {
    63     _Thread_Enable_dispatch();
    6461    rtems_set_errno_and_return_minus_one( ENOSPC );
    6562  }
     
    7370    if ( !name ) {
    7471      _POSIX_Semaphore_Free( the_semaphore );
    75       _Thread_Enable_dispatch();
    7672      rtems_set_errno_and_return_minus_one( ENOMEM );
    7773    }
     
    121117  *the_sem = the_semaphore;
    122118
    123   _Thread_Enable_dispatch();
    124119  return 0;
    125120}
  • cpukit/posix/src/semclose.c

    r34684573 r23fec9f  
    3939  Objects_Locations                 location;
    4040
     41  _Objects_Allocator_lock();
    4142  the_semaphore = _POSIX_Semaphore_Get( sem, &location );
    4243  switch ( location ) {
     
    4647      _POSIX_Semaphore_Delete( the_semaphore );
    4748      _Objects_Put( &the_semaphore->Object );
     49      _Objects_Allocator_unlock();
    4850      return 0;
    4951
     
    5557  }
    5658
     59  _Objects_Allocator_unlock();
     60
    5761  rtems_set_errno_and_return_minus_one( EINVAL );
    5862}
  • cpukit/posix/src/semdestroy.c

    r34684573 r23fec9f  
    3939  Objects_Locations                 location;
    4040
     41  _Objects_Allocator_lock();
    4142  the_semaphore = _POSIX_Semaphore_Get( sem, &location );
    4243  switch ( location ) {
     
    5455      _POSIX_Semaphore_Delete( the_semaphore );
    5556      _Objects_Put( &the_semaphore->Object );
     57      _Objects_Allocator_unlock();
    5658      return 0;
    5759
     
    6365  }
    6466
     67  _Objects_Allocator_unlock();
     68
    6569  rtems_set_errno_and_return_minus_one( EINVAL );
    6670}
  • cpukit/posix/src/seminit.c

    r34684573 r23fec9f  
    4848    rtems_set_errno_and_return_minus_one( EINVAL );
    4949
     50  _Objects_Allocator_lock();
    5051  status = _POSIX_Semaphore_Create_support(
    5152    NULL,
     
    5556    &the_semaphore
    5657  );
     58  _Objects_Allocator_unlock();
    5759
    5860  if ( status != -1 )
  • cpukit/posix/src/semopen.c

    r34684573 r23fec9f  
    6767  size_t                     name_len;
    6868
    69   _Thread_Disable_dispatch();
    70 
    7169  if ( oflag & O_CREAT ) {
    7270    va_start(arg, oflag);
     
    7674  }
    7775
     76  _Objects_Allocator_lock();
    7877  status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id, &name_len );
    7978
     
    9392
    9493    if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
    95       _Thread_Enable_dispatch();
     94      _Objects_Allocator_unlock();
    9695      rtems_set_errno_and_return_minus_one_cast( status, sem_t * );
    9796    }
     
    103102
    104103    if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
    105       _Thread_Enable_dispatch();
     104      _Objects_Allocator_unlock();
    106105      rtems_set_errno_and_return_minus_one_cast( EEXIST, sem_t * );
    107106    }
     
    110109    the_semaphore->open_count += 1;
    111110    _Thread_Enable_dispatch();
    112     _Thread_Enable_dispatch();
     111    _Objects_Allocator_unlock();
    113112    goto return_id;
    114113  }
     
    131130   */
    132131
    133   _Thread_Enable_dispatch();
     132  _Objects_Allocator_unlock();
    134133
    135134  if ( status == -1 )
  • cpukit/posix/src/semunlink.c

    r34684573 r23fec9f  
    3636)
    3737{
    38   int  status;
    39   POSIX_Semaphore_Control          *the_semaphore;
    40   Objects_Id the_semaphore_id;
    41   size_t name_len;
     38  int                      status;
     39  POSIX_Semaphore_Control *the_semaphore;
     40  Objects_Id               the_semaphore_id;
     41  size_t                   name_len;
    4242
     43  _Objects_Allocator_lock();
    4344  _Thread_Disable_dispatch();
    4445
     
    5960
    6061  _Thread_Enable_dispatch();
     62  _Objects_Allocator_unlock();
     63
    6164  return 0;
    6265}
  • cpukit/posix/src/timercreate.c

    r34684573 r23fec9f  
    6767  }
    6868
    69   _Thread_Disable_dispatch();         /* to prevent deletion */
    70 
    7169  /*
    7270   *  Allocate a timer
     
    7472  ptimer = _POSIX_Timer_Allocate();
    7573  if ( !ptimer ) {
    76     _Objects_Put( &ptimer->Object );
     74    _Objects_Allocator_unlock();
    7775    rtems_set_errno_and_return_minus_one( EAGAIN );
    7876  }
     
    8179
    8280  ptimer->state     = POSIX_TIMER_STATE_CREATE_NEW;
    83   ptimer->thread_id = _Thread_Executing->Object.id;
     81  ptimer->thread_id = _Thread_Get_executing()->Object.id;
    8482
    8583  if ( evp != NULL ) {
     
    9997
    10098  *timerid  = ptimer->Object.id;
    101   _Objects_Put( &ptimer->Object );
     99  _Objects_Allocator_unlock();
    102100  return 0;
    103101}
  • cpukit/posix/src/timerdelete.c

    r34684573 r23fec9f  
    4848  Objects_Locations    location;
    4949
     50  _Objects_Allocator_lock();
    5051  ptimer = _POSIX_Timer_Get( timerid, &location );
    5152  switch ( location ) {
     
    5556      ptimer->state = POSIX_TIMER_STATE_FREE;
    5657      (void) _Watchdog_Remove( &ptimer->Timer );
     58      _Objects_Put( &ptimer->Object );
    5759      _POSIX_Timer_Free( ptimer );
    58       _Objects_Put( &ptimer->Object );
     60      _Objects_Allocator_unlock();
     61
    5962      return 0;
    6063
     
    6669  }
    6770
     71  _Objects_Allocator_unlock();
     72
    6873  rtems_set_errno_and_return_minus_one( EINVAL );
    6974}
  • cpukit/rtems/Makefile.am

    r34684573 r23fec9f  
    176176## MESSAGE_QUEUE_C_FILES
    177177librtems_a_SOURCES += src/msg.c
    178 librtems_a_SOURCES += src/msgqallocate.c
    179178librtems_a_SOURCES += src/msgqbroadcast.c
    180179librtems_a_SOURCES += src/msgqcreate.c
  • cpukit/rtems/include/rtems/rtems/messageimpl.h

    r34684573 r23fec9f  
    9191
    9292/**
    93  * @brief Message Queue Allocate
    94  *
    95  * This function allocates a message queue control block from
    96  * the inactive chain of free message queue control blocks.
    97  *
    98  * @retval the_message_queue filled in if successful, NULL otherwise
    99  */
    100 Message_queue_Control *_Message_queue_Allocate (void);
    101 
    102 /**
    10393 * @brief Message queue Translate Core Message Queue Return Code
    10494 *
     
    163153}
    164154
     155RTEMS_INLINE_ROUTINE Message_queue_Control *_Message_queue_Allocate( void )
     156{
     157  return (Message_queue_Control *)
     158    _Objects_Allocate( &_Message_queue_Information );
     159}
     160
    165161/**@}*/
    166162
  • cpukit/rtems/include/rtems/rtems/tasksimpl.h

    r34684573 r23fec9f  
    7878);
    7979
    80 /**
    81  *  @brief Allocates a task control block.
    82  *
    83  *  This function allocates a task control block from
    84  *  the inactive chain of free task control blocks.
    85  */
    86 RTEMS_INLINE_ROUTINE Thread_Control *_RTEMS_tasks_Allocate( void )
     80RTEMS_INLINE_ROUTINE Thread_Control *_RTEMS_tasks_Allocate(void)
    8781{
     82  _Objects_Allocator_lock();
     83
    8884  _Thread_Kill_zombies();
    8985
    90   return (Thread_Control *) _Objects_Allocate( &_RTEMS_tasks_Information );
     86  return (Thread_Control *)
     87    _Objects_Allocate_unprotected( &_RTEMS_tasks_Information );
    9188}
    9289
  • cpukit/rtems/src/barriercreate.c

    r34684573 r23fec9f  
    6969  the_attributes.maximum_count = maximum_waiters;
    7070
    71   _Thread_Disable_dispatch();             /* prevents deletion */
    72 
    7371  the_barrier = _Barrier_Allocate();
    7472
    7573  if ( !the_barrier ) {
    76     _Thread_Enable_dispatch();
     74    _Objects_Allocator_unlock();
    7775    return RTEMS_TOO_MANY;
    7876  }
     
    9088  *id = the_barrier->Object.id;
    9189
    92   _Thread_Enable_dispatch();
     90  _Objects_Allocator_unlock();
    9391  return RTEMS_SUCCESSFUL;
    9492}
  • cpukit/rtems/src/barrierdelete.c

    r34684573 r23fec9f  
    2929  Objects_Locations  location;
    3030
     31  _Objects_Allocator_lock();
    3132  the_barrier = _Barrier_Get( id, &location );
    3233  switch ( location ) {
     
    4041
    4142      _Objects_Close( &_Barrier_Information, &the_barrier->Object );
    42 
     43      _Objects_Put( &the_barrier->Object );
    4344      _Barrier_Free( the_barrier );
    44 
    45       _Objects_Put( &the_barrier->Object );
     45      _Objects_Allocator_unlock();
    4646      return RTEMS_SUCCESSFUL;
    4747
     
    5353  }
    5454
     55  _Objects_Allocator_unlock();
     56
    5557  return RTEMS_INVALID_ID;
    5658}
  • cpukit/rtems/src/dpmemcreate.c

    r34684573 r23fec9f  
    3434)
    3535{
    36   Dual_ported_memory_Control          *the_port;
     36  Dual_ported_memory_Control *the_port;
    3737
    3838  if ( !rtems_is_name_valid( name ) )
     
    4646    return RTEMS_INVALID_ADDRESS;
    4747
    48   _Thread_Disable_dispatch();             /* to prevent deletion */
    49 
    5048  the_port = _Dual_ported_memory_Allocate();
    5149
    5250  if ( !the_port ) {
    53     _Thread_Enable_dispatch();
     51    _Objects_Allocator_unlock();
    5452    return RTEMS_TOO_MANY;
    5553  }
     
    6664
    6765  *id = the_port->Object.id;
    68   _Thread_Enable_dispatch();
     66  _Objects_Allocator_unlock();
    6967  return RTEMS_SUCCESSFUL;
    7068}
  • cpukit/rtems/src/dpmemdelete.c

    r34684573 r23fec9f  
    3333  Objects_Locations                    location;
    3434
     35  _Objects_Allocator_lock();
    3536  the_port = _Dual_ported_memory_Get( id, &location );
    3637  switch ( location ) {
     
    3839    case OBJECTS_LOCAL:
    3940      _Objects_Close( &_Dual_ported_memory_Information, &the_port->Object );
     41      _Objects_Put( &the_port->Object );
    4042      _Dual_ported_memory_Free( the_port );
    41       _Objects_Put( &the_port->Object );
     43      _Objects_Allocator_unlock();
    4244      return RTEMS_SUCCESSFUL;
    4345
     
    4951  }
    5052
     53  _Objects_Allocator_unlock();
     54
    5155  return RTEMS_INVALID_ID;
    5256}
  • cpukit/rtems/src/msgqcreate.c

    r34684573 r23fec9f  
    8282#endif
    8383
    84   _Thread_Disable_dispatch();              /* protects object pointer */
    85 
    8684  the_message_queue = _Message_queue_Allocate();
    8785
    8886  if ( !the_message_queue ) {
    89     _Thread_Enable_dispatch();
     87    _Objects_Allocator_unlock();
    9088    return RTEMS_TOO_MANY;
    9189  }
     
    9694                              name, the_message_queue->Object.id, false ) ) ) {
    9795    _Message_queue_Free( the_message_queue );
    98     _Thread_Enable_dispatch();
     96    _Objects_Allocator_unlock();
    9997    return RTEMS_TOO_MANY;
    10098  }
     
    121119
    122120    _Message_queue_Free( the_message_queue );
    123     _Thread_Enable_dispatch();
     121    _Objects_Allocator_unlock();
    124122    return RTEMS_UNSATISFIED;
    125123  }
     
    143141#endif
    144142
    145   _Thread_Enable_dispatch();
     143  _Objects_Allocator_unlock();
    146144  return RTEMS_SUCCESSFUL;
    147145}
  • cpukit/rtems/src/msgqdelete.c

    r34684573 r23fec9f  
    3838  Objects_Locations               location;
    3939
     40  _Objects_Allocator_lock();
    4041  the_message_queue = _Message_queue_Get( id, &location );
    4142  switch ( location ) {
     
    5556      );
    5657
    57       _Message_queue_Free( the_message_queue );
    58 
    5958#if defined(RTEMS_MULTIPROCESSING)
    6059      if ( _Attributes_Is_global( the_message_queue->attribute_set ) ) {
     
    7372#endif
    7473      _Objects_Put( &the_message_queue->Object );
     74      _Message_queue_Free( the_message_queue );
     75      _Objects_Allocator_unlock();
    7576      return RTEMS_SUCCESSFUL;
    7677
    7778#if defined(RTEMS_MULTIPROCESSING)
    7879    case OBJECTS_REMOTE:
    79       _Thread_Dispatch();
     80      _Objects_Allocator_unlock();
    8081      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
    8182#endif
     
    8586  }
    8687
     88  _Objects_Allocator_unlock();
     89
    8790  return RTEMS_INVALID_ID;
    8891}
  • cpukit/rtems/src/partcreate.c

    r34684573 r23fec9f  
    5454)
    5555{
    56    Partition_Control          *the_partition;
     56  Partition_Control *the_partition;
    5757
    5858  if ( !rtems_is_name_valid( name ) )
     
    7878#endif
    7979
    80   _Thread_Disable_dispatch();               /* prevents deletion */
    81 
    8280  the_partition = _Partition_Allocate();
    8381
    8482  if ( !the_partition ) {
    85     _Thread_Enable_dispatch();
     83    _Objects_Allocator_unlock();
    8684    return RTEMS_TOO_MANY;
    8785  }
     
    9290                            the_partition->Object.id, false ) ) ) {
    9391    _Partition_Free( the_partition );
    94     _Thread_Enable_dispatch();
     92    _Objects_Allocator_unlock();
    9593    return RTEMS_TOO_MANY;
    9694  }
     
    123121#endif
    124122
    125   _Thread_Enable_dispatch();
     123  _Objects_Allocator_unlock();
    126124  return RTEMS_SUCCESSFUL;
    127125}
  • cpukit/rtems/src/partdelete.c

    r34684573 r23fec9f  
    3030  Objects_Locations           location;
    3131
     32  _Objects_Allocator_lock();
    3233  the_partition = _Partition_Get( id, &location );
    3334  switch ( location ) {
     
    3637      if ( the_partition->number_of_used_blocks == 0 ) {
    3738        _Objects_Close( &_Partition_Information, &the_partition->Object );
    38         _Partition_Free( the_partition );
    3939#if defined(RTEMS_MULTIPROCESSING)
    4040        if ( _Attributes_Is_global( the_partition->attribute_set ) ) {
     
    5555
    5656        _Objects_Put( &the_partition->Object );
     57        _Partition_Free( the_partition );
     58        _Objects_Allocator_unlock();
    5759        return RTEMS_SUCCESSFUL;
    5860      }
    5961      _Objects_Put( &the_partition->Object );
     62      _Objects_Allocator_unlock();
    6063      return RTEMS_RESOURCE_IN_USE;
    6164
    6265#if defined(RTEMS_MULTIPROCESSING)
    6366    case OBJECTS_REMOTE:
    64       _Thread_Dispatch();
     67      _Objects_Allocator_unlock();
    6568      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
    6669#endif
     
    7073  }
    7174
     75  _Objects_Allocator_unlock();
     76
    7277  return RTEMS_INVALID_ID;
    7378}
  • cpukit/rtems/src/ratemoncreate.c

    r34684573 r23fec9f  
    5656    return RTEMS_INVALID_ADDRESS;
    5757
    58   _Thread_Disable_dispatch();            /* to prevent deletion */
    59 
    6058  the_period = _Rate_monotonic_Allocate();
    6159
    6260  if ( !the_period ) {
    63     _Thread_Enable_dispatch();
     61    _Objects_Allocator_unlock();
    6462    return RTEMS_TOO_MANY;
    6563  }
    6664
    67   the_period->owner = _Thread_Executing;
     65  the_period->owner = _Thread_Get_executing();
    6866  the_period->state = RATE_MONOTONIC_INACTIVE;
    6967
     
    7977
    8078  *id = the_period->Object.id;
    81   _Thread_Enable_dispatch();
     79  _Objects_Allocator_unlock();
    8280  return RTEMS_SUCCESSFUL;
    8381}
  • cpukit/rtems/src/ratemondelete.c

    r34684573 r23fec9f  
    3131  Objects_Locations       location;
    3232
     33  _Objects_Allocator_lock();
    3334  the_period = _Rate_monotonic_Get( id, &location );
    3435  switch ( location ) {
     
    3940      (void) _Watchdog_Remove( &the_period->Timer );
    4041      the_period->state = RATE_MONOTONIC_INACTIVE;
     42      _Objects_Put( &the_period->Object );
    4143      _Rate_monotonic_Free( the_period );
    42       _Objects_Put( &the_period->Object );
     44      _Objects_Allocator_unlock();
    4345      return RTEMS_SUCCESSFUL;
    4446
     
    5052  }
    5153
     54  _Objects_Allocator_unlock();
     55
    5256  return RTEMS_INVALID_ID;
    5357}
  • cpukit/rtems/src/regioncreate.c

    r34684573 r23fec9f  
    6767    return RTEMS_INVALID_ADDRESS;
    6868
    69   _RTEMS_Lock_allocator();                      /* to prevent deletion */
    70 
    71     the_region = _Region_Allocate();
     69  the_region = _Region_Allocate();
    7270
    7371    if ( !the_region )
     
    112110    }
    113111
    114   _RTEMS_Unlock_allocator();
     112  _Objects_Allocator_unlock();
     113
    115114  return return_status;
    116115}
  • cpukit/rtems/src/regiondelete.c

    r34684573 r23fec9f  
    3535  Region_Control     *the_region;
    3636
    37   _RTEMS_Lock_allocator();
     37  _Objects_Allocator_lock();
    3838
    3939    the_region = _Region_Get( id, &location );
     
    6262    }
    6363
    64   _RTEMS_Unlock_allocator();
     64  _Objects_Allocator_unlock();
     65
    6566  return return_status;
    6667}
  • cpukit/rtems/src/regionextend.c

    r34684573 r23fec9f  
    4141    return RTEMS_INVALID_ADDRESS;
    4242
    43   _RTEMS_Lock_allocator();                      /* to prevent deletion */
     43  _RTEMS_Lock_allocator(); /* to prevent deletion */
    4444
    4545    the_region = _Region_Get( id, &location );
     
    7676
    7777  _RTEMS_Unlock_allocator();
     78
    7879  return return_status;
    7980}
  • cpukit/rtems/src/regiongetsegment.c

    r34684573 r23fec9f  
    4848  _RTEMS_Lock_allocator();
    4949
    50     executing  = _Thread_Executing;
     50    executing  = _Thread_Get_executing();
    5151    the_region = _Region_Get( id, &location );
    5252    switch ( location ) {
     
    111111
    112112  _RTEMS_Unlock_allocator();
     113
    113114  return return_status;
    114115}
  • cpukit/rtems/src/regionresizesegment.c

    r34684573 r23fec9f  
    6565
    6666        if ( status == HEAP_RESIZE_SUCCESSFUL )
    67           _Region_Process_queue( the_region );    /* unlocks allocator */
     67          /* unlocks allocator */
     68          _Region_Process_queue( the_region );
    6869        else
    6970          _RTEMS_Unlock_allocator();
  • cpukit/rtems/src/semcreate.c

    r34684573 r23fec9f  
    101101    return RTEMS_INVALID_NUMBER;
    102102
    103   _Thread_Disable_dispatch();             /* prevents deletion */
    104 
    105103  the_semaphore = _Semaphore_Allocate();
    106104
    107105  if ( !the_semaphore ) {
    108     _Thread_Enable_dispatch();
     106    _Objects_Allocator_unlock();
    109107    return RTEMS_TOO_MANY;
    110108  }
     
    115113                            the_semaphore->Object.id, false ) ) ) {
    116114    _Semaphore_Free( the_semaphore );
    117     _Thread_Enable_dispatch();
     115    _Objects_Allocator_unlock();
    118116    return RTEMS_TOO_MANY;
    119117  }
     
    180178    mutex_status = _CORE_mutex_Initialize(
    181179      &the_semaphore->Core_control.mutex,
    182       _Thread_Executing,
     180      _Thread_Get_executing(),
    183181      &the_mutex_attr,
    184182      (count == 1) ? CORE_MUTEX_UNLOCKED : CORE_MUTEX_LOCKED
     
    187185    if ( mutex_status == CORE_MUTEX_STATUS_CEILING_VIOLATED ) {
    188186      _Semaphore_Free( the_semaphore );
    189       _Thread_Enable_dispatch();
     187      _Objects_Allocator_unlock();
    190188      return RTEMS_INVALID_PRIORITY;
    191189    }
     
    213211    );
    214212#endif
    215   _Thread_Enable_dispatch();
     213  _Objects_Allocator_unlock();
    216214  return RTEMS_SUCCESSFUL;
    217215}
  • cpukit/rtems/src/semdelete.c

    r34684573 r23fec9f  
    4545  Objects_Locations           location;
    4646
     47  _Objects_Allocator_lock();
     48
    4749  the_semaphore = _Semaphore_Get( id, &location );
    4850  switch ( location ) {
     
    5456                 the_semaphore->attribute_set ) ) {
    5557          _Objects_Put( &the_semaphore->Object );
     58          _Objects_Allocator_unlock();
    5659          return RTEMS_RESOURCE_IN_USE;
    5760        }
     
    7174      _Objects_Close( &_Semaphore_Information, &the_semaphore->Object );
    7275
    73       _Semaphore_Free( the_semaphore );
    74 
    7576#if defined(RTEMS_MULTIPROCESSING)
    7677      if ( _Attributes_Is_global( the_semaphore->attribute_set ) ) {
     
    8687      }
    8788#endif
     89
    8890      _Objects_Put( &the_semaphore->Object );
     91      _Semaphore_Free( the_semaphore );
     92      _Objects_Allocator_unlock();
    8993      return RTEMS_SUCCESSFUL;
    9094
    9195#if defined(RTEMS_MULTIPROCESSING)
    9296    case OBJECTS_REMOTE:
    93       _Thread_Dispatch();
     97      _Objects_Allocator_unlock();
    9498      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
    9599#endif
     
    99103  }
    100104
     105  _Objects_Allocator_unlock();
    101106  return RTEMS_INVALID_ID;
    102107}
  • cpukit/rtems/src/taskcreate.c

    r34684573 r23fec9f  
    106106
    107107  /*
    108    *  Lock the allocator mutex for protection
    109    */
    110   _RTEMS_Lock_allocator();
    111 
    112   /*
    113108   *  Allocate the thread control block and -- if the task is global --
    114109   *  allocate a global object control block.
     
    123118
    124119  if ( !the_thread ) {
    125     _RTEMS_Unlock_allocator();
     120    _Objects_Allocator_unlock();
    126121    return RTEMS_TOO_MANY;
    127122  }
     
    133128    if ( _Objects_MP_Is_null_global_object( the_global_object ) ) {
    134129      _RTEMS_tasks_Free( the_thread );
    135       _RTEMS_Unlock_allocator();
     130      _Objects_Allocator_unlock();
    136131      return RTEMS_TOO_MANY;
    137132    }
     
    165160#endif
    166161    _RTEMS_tasks_Free( the_thread );
    167     _RTEMS_Unlock_allocator();
     162    _Objects_Allocator_unlock();
    168163    return RTEMS_UNSATISFIED;
    169164  }
     
    196191#endif
    197192
    198   _RTEMS_Unlock_allocator();
     193  _Objects_Allocator_unlock();
    199194  return RTEMS_SUCCESSFUL;
    200195}
  • cpukit/rtems/src/timercreate.c

    r34684573 r23fec9f  
    3939    return RTEMS_INVALID_ADDRESS;
    4040
    41   _Thread_Disable_dispatch();         /* to prevent deletion */
    42 
    4341  the_timer = _Timer_Allocate();
    4442
    4543  if ( !the_timer ) {
    46     _Thread_Enable_dispatch();
     44    _Objects_Allocator_unlock();
    4745    return RTEMS_TOO_MANY;
    4846  }
     
    5856
    5957  *id = the_timer->Object.id;
    60   _Thread_Enable_dispatch();
     58  _Objects_Allocator_unlock();
    6159  return RTEMS_SUCCESSFUL;
    6260}
  • cpukit/rtems/src/timerdelete.c

    r34684573 r23fec9f  
    3333  Objects_Locations  location;
    3434
     35  _Objects_Allocator_lock();
    3536  the_timer = _Timer_Get( id, &location );
    3637  switch ( location ) {
     
    3940      _Objects_Close( &_Timer_Information, &the_timer->Object );
    4041      (void) _Watchdog_Remove( &the_timer->Ticker );
     42      _Objects_Put( &the_timer->Object );
    4143      _Timer_Free( the_timer );
    42       _Objects_Put( &the_timer->Object );
     44      _Objects_Allocator_unlock();
    4345      return RTEMS_SUCCESSFUL;
    4446
     
    5052  }
    5153
     54  _Objects_Allocator_unlock();
     55
    5256  return RTEMS_INVALID_ID;
    5357}
  • cpukit/sapi/src/extensioncreate.c

    r34684573 r23fec9f  
    4040    return RTEMS_INVALID_NAME;
    4141
    42   _Thread_Disable_dispatch();         /* to prevent deletion */
    43 
    4442  the_extension = _Extension_Allocate();
    4543
    4644  if ( !the_extension ) {
    47     _Thread_Enable_dispatch();
     45    _Objects_Allocator_unlock();
    4846    return RTEMS_TOO_MANY;
    4947  }
    5048
     49  _Thread_Disable_dispatch();
    5150  _User_extensions_Add_set_with_table( &the_extension->Extension, extension_table );
     51  _Thread_Enable_dispatch();
    5252
    5353  _Objects_Open(
     
    5858
    5959  *id = the_extension->Object.id;
    60   _Thread_Enable_dispatch();
     60  _Objects_Allocator_unlock();
    6161  return RTEMS_SUCCESSFUL;
    6262}
  • cpukit/sapi/src/extensiondelete.c

    r34684573 r23fec9f  
    3131  Objects_Locations    location;
    3232
     33  _Objects_Allocator_lock();
    3334  the_extension = _Extension_Get( id, &location );
    3435  switch ( location ) {
     
    3637      _User_extensions_Remove_set( &the_extension->Extension );
    3738      _Objects_Close( &_Extension_Information, &the_extension->Object );
     39      _Objects_Put( &the_extension->Object );
    3840      _Extension_Free( the_extension );
    39       _Objects_Put( &the_extension->Object );
     41      _Objects_Allocator_unlock();
    4042      return RTEMS_SUCCESSFUL;
    4143
     
    4749  }
    4850
     51  _Objects_Allocator_unlock();
     52
    4953  return RTEMS_INVALID_ID;
    5054}
  • cpukit/score/include/rtems/score/objectimpl.h

    r34684573 r23fec9f  
    2121
    2222#include <rtems/score/object.h>
     23#include <rtems/score/apimutex.h>
    2324#include <rtems/score/isrlevel.h>
    2425#include <rtems/score/threaddispatch.h>
     
    265266
    266267/**
    267  *  @brief Allocate an object.
    268  *
    269  *  This function allocates an object control block from
    270  *  the inactive chain of free object control blocks.
    271  *
    272  *  @param[in] information points to an object class information block.
    273  */
    274 Objects_Control *_Objects_Allocate(
     268 * @brief Allocates an object without locking the allocator mutex.
     269 *
     270 * This function can be called in two contexts
     271 * - the executing thread is the owner of the object allocator mutex, or
     272 * - in case the system state is not up, e.g. during sequential system
     273 *   initialization.
     274 *
     275 * @param[in] information The object information block.
     276 *
     277 * @retval NULL No object available.
     278 * @retval object The allocated object.
     279 *
     280 * @see _Objects_Allocate() and _Objects_Free().
     281 */
     282Objects_Control *_Objects_Allocate_unprotected(
    275283  Objects_Information *information
    276284);
    277285
    278286/**
    279  *  @brief Free an object.
    280  *
    281  *  This function frees an object control block to the
    282  *  inactive chain of free object control blocks.
    283  *
    284  *  @param[in] information points to an object class information block.
    285  *  @param[in] the_object points to the object to deallocate.
     287 * @brief Allocates an object.
     288 *
     289 * This function locks the object allocator mutex via
     290 * _Objects_Allocator_lock().  The caller must later unlock the object
     291 * allocator mutex via _Objects_Allocator_unlock().  The caller must unlock the
     292 * mutex in any case, even if the allocation failed due to resource shortage.
     293 *
     294 * A typical object allocation code looks like this:
     295 * @code
     296 * rtems_status_code some_create( rtems_id *id )
     297 * {
     298 *   rtems_status_code  sc;
     299 *   Some_Control      *some;
     300 *
     301 *   // The object allocator mutex protects the executing thread from
     302 *   // asynchronous thread restart and deletion.
     303 *   some = (Some_Control *) _Objects_Allocate( &_Some_Information );
     304 *
     305 *   if ( some != NULL ) {
     306 *     _Some_Initialize( some );
     307 *     sc = RTEMS_SUCCESSFUL;
     308 *   } else {
     309 *     sc = RTEMS_TOO_MANY;
     310 *   }
     311 *
     312 *   _Objects_Allocator_unlock();
     313 *
     314 *   return sc;
     315 * }
     316 * @endcode
     317 *
     318 * @param[in] information The object information block.
     319 *
     320 * @retval NULL No object available.
     321 * @retval object The allocated object.
     322 *
     323 * @see _Objects_Free().
     324 */
     325Objects_Control *_Objects_Allocate( Objects_Information *information );
     326
     327/**
     328 * @brief Frees an object.
     329 *
     330 * Appends the object to the chain of inactive objects.
     331 *
     332 * @param[in] information The object information block.
     333 * @param[in] the_object The object to free.
     334 *
     335 * @see _Objects_Allocate().
     336 *
     337 * A typical object deletion code looks like this:
     338 * @code
     339 * rtems_status_code some_delete( rtems_id id )
     340 * {
     341 *   rtems_status_code  sc;
     342 *   Some_Control      *some;
     343 *   Objects_Locations  location;
     344 *
     345 *   // The object allocator mutex protects the executing thread from
     346 *   // asynchronous thread restart and deletion.
     347 *   _Objects_Allocator_lock();
     348 *
     349 *   // This will disable thread dispatching, so this starts a thread dispatch
     350 *   // critical section.
     351 *   some = (Semaphore_Control *)
     352 *     _Objects_Get( &_Some_Information, id, &location );
     353 *
     354 *   switch ( location ) {
     355 *     case OBJECTS_LOCAL:
     356 *       // After the object close an object get with this identifier will
     357 *       // fail.
     358 *       _Objects_Close( &_Some_Information, &some->Object );
     359 *
     360 *       _Some_Delete( some );
     361 *
     362 *       // This enables thread dispatching, so the thread dispatch critical
     363 *       // section ends here.
     364 *       _Objects_Put( &some->Object );
     365 *
     366 *       // Thread dispatching is enabled.  The object free is only protected
     367 *       // by the object allocator mutex.
     368 *       _Objects_Free( &_Some_Information, &some->Object );
     369 *
     370 *       sc = RTEMS_SUCCESSFUL;
     371 *       break;
     372 *     default:
     373 *       sc = RTEMS_INVALID_ID;
     374 *       break;
     375 *   }
     376 *
     377 *   _Objects_Allocator_unlock();
     378 *
     379 *   return sc;
     380 * }
     381 * @endcode
    286382 */
    287383void _Objects_Free(
     
    893989}
    894990
     991/**
     992 * @brief Locks the object allocator mutex.
     993 *
     994 * While holding the allocator mutex the executing thread is protected from
     995 * asynchronous thread restart and deletion.
     996 *
     997 * The usage of the object allocator mutex with the thread life protection
     998 * makes it possible to allocate and free objects without thread dispatching
     999 * disabled.  The usage of a unified workspace and unlimited objects may lead
     1000 * to heap fragmentation.  Thus the execution time of the _Objects_Allocate()
     1001 * function may increase during system run-time.
     1002 *
     1003 * @see _Objects_Allocator_unlock() and _Objects_Allocate().
     1004 */
     1005RTEMS_INLINE_ROUTINE void _Objects_Allocator_lock( void )
     1006{
     1007  _RTEMS_Lock_allocator();
     1008}
     1009
     1010/**
     1011 * @brief Unlocks the object allocator mutex.
     1012 *
     1013 * In case the mutex is fully unlocked, then this function restores the
     1014 * previous thread life protection state and thus may not return if the
     1015 * executing thread was restarted or deleted in the mean-time.
     1016 */
     1017RTEMS_INLINE_ROUTINE void _Objects_Allocator_unlock( void )
     1018{
     1019  _RTEMS_Unlock_allocator();
     1020}
     1021
    8951022/** @} */
    8961023
  • cpukit/score/include/rtems/score/threadimpl.h

    r34684573 r23fec9f  
    591591}
    592592
    593 /**
    594  * This routine allocates an internal thread.
    595  */
    596 
    597593RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
    598594{
    599   return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
     595  return (Thread_Control *)
     596    _Objects_Allocate_unprotected( &_Thread_Internal_information );
    600597}
    601598
  • cpukit/score/src/apimutex.c

    r34684573 r23fec9f  
    5959  };
    6060
    61   mutex = (API_Mutex_Control *) _Objects_Allocate( &_API_Mutex_Information );
     61  mutex = (API_Mutex_Control *)
     62    _Objects_Allocate_unprotected( &_API_Mutex_Information );
    6263
    6364  _CORE_mutex_Initialize( &mutex->Mutex, NULL, &attr, CORE_MUTEX_UNLOCKED );
  • cpukit/score/src/objectactivecount.c

    r34684573 r23fec9f  
    1818
    1919#include <rtems/score/objectimpl.h>
     20#include <rtems/score/assert.h>
    2021#include <rtems/score/chainimpl.h>
    2122
     
    2425)
    2526{
    26   size_t inactive = _Chain_Node_count_unprotected( &information->Inactive );
    27   size_t maximum  = information->maximum;
     27  size_t inactive;
     28  size_t maximum;
     29
     30  _Assert( _Debug_Is_owner_of_allocator() );
     31
     32  inactive = _Chain_Node_count_unprotected( &information->Inactive );
     33  maximum  = information->maximum;
    2834
    2935  return (Objects_Maximum) ( maximum - inactive );
  • cpukit/score/src/objectallocate.c

    r34684573 r23fec9f  
    2020
    2121#include <rtems/score/objectimpl.h>
     22#include <rtems/score/assert.h>
    2223#include <rtems/score/chainimpl.h>
     24#include <rtems/score/sysstate.h>
    2325
    2426/* #define RTEMS_DEBUG_OBJECT_ALLOCATION */
     
    2830#endif
    2931
    30 Objects_Control *_Objects_Allocate(
     32static Objects_Control *_Objects_Get_inactive(
     33  Objects_Information *information
     34)
     35{
     36  return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
     37}
     38
     39Objects_Control *_Objects_Allocate_unprotected(
    3140  Objects_Information *information
    3241)
    3342{
    3443  Objects_Control *the_object;
     44
     45  _Assert(
     46    _Debug_Is_owner_of_allocator()
     47      || !_System_state_Is_up( _System_state_Get() )
     48  );
    3549
    3650  /*
     
    4761   *  With any luck, it is safe to attempt to allocate an object.
    4862   */
    49   the_object = (Objects_Control *) _Chain_Get( &information->Inactive );
     63  the_object = _Objects_Get_inactive( information );
    5064
    5165  if ( information->auto_extend ) {
     
    5771    if ( !the_object ) {
    5872      _Objects_Extend_information( information );
    59       the_object =  (Objects_Control *) _Chain_Get( &information->Inactive );
     73      the_object = _Objects_Get_inactive( information );
    6074    }
    6175
     
    8498  return the_object;
    8599}
     100
     101Objects_Control *_Objects_Allocate( Objects_Information *information )
     102{
     103  _RTEMS_Lock_allocator();
     104
     105  return _Objects_Allocate_unprotected( information );
     106}
  • cpukit/score/src/objectextendinformation.c

    r34684573 r23fec9f  
    2121#include <rtems/score/objectimpl.h>
    2222#include <rtems/score/address.h>
     23#include <rtems/score/assert.h>
    2324#include <rtems/score/chainimpl.h>
    2425#include <rtems/score/isrlevel.h>
     26#include <rtems/score/sysstate.h>
    2527#include <rtems/score/wkspace.h>
    2628
     
    4345{
    4446  Objects_Control  *the_object;
    45   Chain_Control     Inactive;
    4647  uint32_t          block_count;
    4748  uint32_t          block;
    4849  uint32_t          index_base;
     50  uint32_t          index_end;
    4951  uint32_t          minimum_index;
    5052  uint32_t          index;
     
    5456  bool              do_extend;
    5557
     58  _Assert(
     59    _Debug_Is_owner_of_allocator()
     60      || !_System_state_Is_up( _System_state_Get() )
     61  );
     62
    5663  /*
    5764   *  Search for a free block of indexes. If we do NOT need to allocate or
     
    7784    }
    7885  }
     86  index_end = index_base + information->allocation_size;
    7987
    8088  maximum = (uint32_t) information->maximum + information->allocation_size;
     
    214222    inactive_per_block[block_count] = 0;
    215223
    216     for ( index=index_base ;
    217           index < ( information->allocation_size + index_base );
    218           index++ ) {
     224    for ( index = index_base ; index < index_end ; ++index ) {
    219225      local_table[ index ] = NULL;
    220226    }
    221227
     228    _Thread_Disable_dispatch();
    222229    _ISR_Disable( level );
    223230
     
    236243
    237244    _ISR_Enable( level );
     245    _Thread_Enable_dispatch();
    238246
    239247    _Workspace_Free( old_tables );
     
    248256
    249257  /*
    250    *  Initialize objects .. add to a local chain first.
    251    */
    252   _Chain_Initialize(
    253     &Inactive,
    254     information->object_blocks[ block ],
    255     information->allocation_size,
    256     information->size
    257   );
    258 
    259   /*
    260    *  Move from the local chain, initialise, then append to the inactive chain
    261    */
    262   index = index_base;
    263 
    264   while ((the_object = (Objects_Control *) _Chain_Get( &Inactive )) != NULL ) {
    265 
     258   *  Append to inactive chain.
     259   */
     260  the_object = information->object_blocks[ block ];
     261  for ( index = index_base ; index < index_end ; ++index ) {
    266262    the_object->id = _Objects_Build_id(
    267         information->the_api,
    268         information->the_class,
    269         _Objects_Local_node,
    270         index
    271       );
    272 
    273     _Chain_Append( &information->Inactive, &the_object->Node );
    274 
    275     index++;
     263      information->the_api,
     264      information->the_class,
     265      _Objects_Local_node,
     266      index
     267    );
     268
     269    _Chain_Append_unprotected( &information->Inactive, &the_object->Node );
     270
     271    the_object = (Objects_Control *)
     272      ( (char *) the_object + information->size );
    276273  }
    277274
  • cpukit/score/src/objectfree.c

    r34684573 r23fec9f  
    2020
    2121#include <rtems/score/objectimpl.h>
     22#include <rtems/score/assert.h>
    2223#include <rtems/score/chainimpl.h>
    2324
     
    2930  uint32_t    allocation_size = information->allocation_size;
    3031
    31   _Chain_Append( &information->Inactive, &the_object->Node );
     32  _Assert( _Debug_Is_owner_of_allocator() );
     33
     34  _Chain_Append_unprotected( &information->Inactive, &the_object->Node );
    3235
    3336  if ( information->auto_extend ) {
  • cpukit/score/src/objectshrinkinformation.c

    r34684573 r23fec9f  
    2020
    2121#include <rtems/score/objectimpl.h>
     22#include <rtems/score/assert.h>
    2223#include <rtems/score/chainimpl.h>
    2324#include <rtems/score/wkspace.h>
     
    3031  uint32_t          block;
    3132  uint32_t          index_base;
     33
     34  _Assert( _Debug_Is_owner_of_allocator() );
    3235
    3336  /*
     
    5659
    5760        if ( index >= index_base && index < index_end ) {
    58           _Chain_Extract( &object->Node );
     61          _Chain_Extract_unprotected( &object->Node );
    5962        }
    6063      }
  • testsuites/sptests/spobjgetnext/init.c

    r34684573 r23fec9f  
    109109
    110110  puts( "Init - _Objects_Active_count" );
     111  _Objects_Allocator_lock();
    111112  active_count = _Objects_Active_count( info );
     113  _Objects_Allocator_unlock();
    112114  rtems_test_assert( active_count == 1 );
    113115
Note: See TracChangeset for help on using the changeset viewer.