Changeset 1142f55 in rtems


Ignore:
Timestamp:
Apr 8, 2016, 4:56:46 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
b4b062f
Parents:
572cb62
git-author:
Sebastian Huber <sebastian.huber@…> (04/08/16 04:56:46)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/12/16 05:36:19)
Message:

rtems: Add and use _Region_Get_and_lock()

Get region and lock allocator in _Region_Get_and_lock() in case the
region exists and unlock it in _Region_Unlock().

Location:
cpukit/rtems
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • cpukit/rtems/include/rtems/rtems/regionimpl.h

    r572cb62 r1142f55  
    2020#include <rtems/rtems/region.h>
    2121#include <rtems/score/apimutex.h>
    22 #include <rtems/score/assert.h>
    2322#include <rtems/score/heapimpl.h>
    2423#include <rtems/score/objectimpl.h>
     
    6867}
    6968
    70 RTEMS_INLINE_ROUTINE Region_Control *_Region_Get( Objects_Id id )
     69RTEMS_INLINE_ROUTINE Region_Control *_Region_Get_and_lock( Objects_Id id )
    7170{
    72   _Assert( _RTEMS_Allocator_is_owner() );
    73   return (Region_Control *)
     71  Region_Control *the_region;
     72
     73  _RTEMS_Lock_allocator();
     74
     75  the_region = (Region_Control *)
    7476    _Objects_Get_no_protection( &_Region_Information, id );
     77
     78  if ( the_region != NULL ) {
     79    /* Keep allocator lock */
     80    return the_region;
     81  }
     82
     83  _RTEMS_Unlock_allocator();
     84  return NULL;
     85}
     86
     87RTEMS_INLINE_ROUTINE void _Region_Unlock( Region_Control *the_region )
     88{
     89  (void) the_region;
     90  _RTEMS_Unlock_allocator();
    7591}
    7692
  • cpukit/rtems/src/regiondelete.c

    r572cb62 r1142f55  
    2929
    3030  _Objects_Allocator_lock();
    31   _RTEMS_Lock_allocator();
    3231
    33   the_region = _Region_Get( id );
     32  the_region = _Region_Get_and_lock( id );
    3433
    35   if ( the_region != NULL ) {
    36     if ( the_region->number_of_used_blocks != 0 ) {
    37       status = RTEMS_RESOURCE_IN_USE;
    38     } else {
    39       _Objects_Close( &_Region_Information, &the_region->Object );
    40       _Region_Free( the_region );
    41       status = RTEMS_SUCCESSFUL;
    42     }
    43   } else {
    44     status = RTEMS_INVALID_ID;
     34  if ( the_region == NULL ) {
     35    _Objects_Allocator_unlock();
     36    return RTEMS_INVALID_ID;
    4537  }
    4638
    47   _RTEMS_Unlock_allocator();
     39  if ( the_region->number_of_used_blocks != 0 ) {
     40    status = RTEMS_RESOURCE_IN_USE;
     41  } else {
     42    _Objects_Close( &_Region_Information, &the_region->Object );
     43    _Region_Free( the_region );
     44    status = RTEMS_SUCCESSFUL;
     45  }
     46
     47  _Region_Unlock( the_region );
    4848  _Objects_Allocator_unlock();
    4949  return status;
  • cpukit/rtems/src/regionextend.c

    r572cb62 r1142f55  
    3535  }
    3636
    37   _RTEMS_Lock_allocator();
     37  the_region = _Region_Get_and_lock( id );
    3838
    39   the_region = _Region_Get( id );
    40 
    41   if ( the_region != NULL ) {
    42     amount_extended = _Heap_Extend(
    43       &the_region->Memory,
    44       starting_address,
    45       length,
    46       0
    47     );
    48 
    49     if ( amount_extended > 0 ) {
    50       the_region->length               += amount_extended;
    51       the_region->maximum_segment_size += amount_extended;
    52       status = RTEMS_SUCCESSFUL;
    53     } else {
    54       status = RTEMS_INVALID_ADDRESS;
    55     }
    56   } else {
    57     status = RTEMS_INVALID_ID;
     39  if ( the_region == NULL ) {
     40    return RTEMS_INVALID_ID;
    5841  }
    5942
    60   _RTEMS_Unlock_allocator();
     43  amount_extended = _Heap_Extend(
     44    &the_region->Memory,
     45    starting_address,
     46    length,
     47    0
     48  );
     49
     50  if ( amount_extended > 0 ) {
     51    the_region->length               += amount_extended;
     52    the_region->maximum_segment_size += amount_extended;
     53    status = RTEMS_SUCCESSFUL;
     54  } else {
     55    status = RTEMS_INVALID_ADDRESS;
     56  }
     57
     58  _Region_Unlock( the_region );
    6159  return status;
    6260}
  • cpukit/rtems/src/regiongetfreeinfo.c

    r572cb62 r1142f55  
    2828)
    2929{
    30   rtems_status_code  status;
    31   Region_Control    *the_region;
     30  Region_Control *the_region;
    3231
    3332  if ( the_info == NULL ) {
     
    3534  }
    3635
    37   _RTEMS_Lock_allocator();
     36  the_region = _Region_Get_and_lock( id );
    3837
    39   the_region = _Region_Get( id );
    40 
    41   if ( the_region != NULL ) {
    42     memset( &the_info->Used, 0, sizeof( the_info->Used ) );
    43     _Heap_Get_free_information( &the_region->Memory, &the_info->Free );
    44     status = RTEMS_SUCCESSFUL;
    45   } else {
    46     status = RTEMS_INVALID_ID;
     38  if ( the_region == NULL ) {
     39    return RTEMS_INVALID_ID;
    4740  }
    4841
    49   _RTEMS_Unlock_allocator();
    50   return status;
     42  memset( &the_info->Used, 0, sizeof( the_info->Used ) );
     43  _Heap_Get_free_information( &the_region->Memory, &the_info->Free );
     44
     45  _Region_Unlock( the_region );
     46  return RTEMS_SUCCESSFUL;
    5147}
  • cpukit/rtems/src/regiongetinfo.c

    r572cb62 r1142f55  
    2626)
    2727{
    28   rtems_status_code  status;
    29   Region_Control    *the_region;
     28  Region_Control *the_region;
    3029
    3130  if ( the_info == NULL ) {
     
    3332  }
    3433
    35   _RTEMS_Lock_allocator();
     34  the_region = _Region_Get_and_lock( id );
    3635
    37   the_region = _Region_Get( id );
    38 
    39   if ( the_region != NULL ) {
    40     _Heap_Get_information( &the_region->Memory, the_info );
    41     status = RTEMS_SUCCESSFUL;
    42   } else {
    43     status = RTEMS_INVALID_ID;
     36  if ( the_region == NULL ) {
     37    return RTEMS_INVALID_ID;
    4438  }
    4539
    46   _RTEMS_Unlock_allocator();
    47   return status;
     40  _Heap_Get_information( &the_region->Memory, the_info );
     41
     42  _Region_Unlock( the_region );
     43  return RTEMS_SUCCESSFUL;
    4844}
  • cpukit/rtems/src/regiongetsegment.c

    r572cb62 r1142f55  
    4545  }
    4646
    47   _RTEMS_Lock_allocator();
     47  the_region = _Region_Get_and_lock( id );
    4848
    49   the_region = _Region_Get( id );
    50 
    51   if ( the_region != NULL ) {
    52     if ( size > the_region->maximum_segment_size ) {
    53       status = RTEMS_INVALID_SIZE;
    54     } else {
    55       void *the_segment;
    56 
    57       the_segment = _Region_Allocate_segment( the_region, size );
    58 
    59       if ( the_segment != NULL ) {
    60         the_region->number_of_used_blocks += 1;
    61         *segment = the_segment;
    62         status = RTEMS_SUCCESSFUL;
    63       } else if ( _Options_Is_no_wait( option_set ) ) {
    64         status = RTEMS_UNSATISFIED;
    65       } else {
    66         Per_CPU_Control *cpu_self;
    67         Thread_Control  *executing;
    68 
    69         /*
    70          *  Switch from using the memory allocation mutex to using a
    71          *  dispatching disabled critical section.  We have to do this
    72          *  because this thread is going to block.
    73          */
    74         /* FIXME: This is a home grown condition variable */
    75         cpu_self = _Thread_Dispatch_disable();
    76         _RTEMS_Unlock_allocator();
    77 
    78         executing  = _Per_CPU_Get_executing( cpu_self );
    79 
    80         executing->Wait.count           = size;
    81         executing->Wait.return_argument = segment;
    82 
    83         _Thread_queue_Enqueue(
    84           &the_region->Wait_queue,
    85           the_region->wait_operations,
    86           executing,
    87           STATES_WAITING_FOR_SEGMENT,
    88           timeout,
    89           RTEMS_TIMEOUT
    90         );
    91 
    92         _Thread_Dispatch_enable( cpu_self );
    93 
    94         return (rtems_status_code) executing->Wait.return_code;
    95       }
    96     }
    97   } else {
    98     status = RTEMS_INVALID_ID;
     49  if ( the_region == NULL ) {
     50    return RTEMS_INVALID_ID;
    9951  }
    10052
    101   _RTEMS_Unlock_allocator();
     53  if ( size > the_region->maximum_segment_size ) {
     54    status = RTEMS_INVALID_SIZE;
     55  } else {
     56    void *the_segment;
     57
     58    the_segment = _Region_Allocate_segment( the_region, size );
     59
     60    if ( the_segment != NULL ) {
     61      the_region->number_of_used_blocks += 1;
     62      *segment = the_segment;
     63      status = RTEMS_SUCCESSFUL;
     64    } else if ( _Options_Is_no_wait( option_set ) ) {
     65      status = RTEMS_UNSATISFIED;
     66    } else {
     67      Per_CPU_Control *cpu_self;
     68      Thread_Control  *executing;
     69
     70      /*
     71       *  Switch from using the memory allocation mutex to using a
     72       *  dispatching disabled critical section.  We have to do this
     73       *  because this thread is going to block.
     74       */
     75      /* FIXME: This is a home grown condition variable */
     76      cpu_self = _Thread_Dispatch_disable();
     77      _Region_Unlock( the_region );
     78
     79      executing  = _Per_CPU_Get_executing( cpu_self );
     80
     81      executing->Wait.count           = size;
     82      executing->Wait.return_argument = segment;
     83
     84      _Thread_queue_Enqueue(
     85        &the_region->Wait_queue,
     86        the_region->wait_operations,
     87        executing,
     88        STATES_WAITING_FOR_SEGMENT,
     89        timeout,
     90        RTEMS_TIMEOUT
     91      );
     92
     93      _Thread_Dispatch_enable( cpu_self );
     94
     95      return (rtems_status_code) executing->Wait.return_code;
     96    }
     97  }
     98
     99  _Region_Unlock( the_region );
    102100  return status;
    103101}
  • cpukit/rtems/src/regiongetsegmentsize.c

    r572cb62 r1142f55  
    3838  }
    3939
    40   _RTEMS_Lock_allocator();
     40  the_region = _Region_Get_and_lock( id );
    4141
    42   the_region = _Region_Get( id );
    43 
    44   if ( the_region != NULL ) {
    45     if ( _Heap_Size_of_alloc_area( &the_region->Memory, segment, size ) ) {
    46       status = RTEMS_SUCCESSFUL;
    47     } else {
    48       status = RTEMS_INVALID_ADDRESS;
    49     }
    50   } else {
    51     status = RTEMS_INVALID_ID;
     42  if ( the_region == NULL ) {
     43    return RTEMS_INVALID_ID;
    5244  }
    5345
    54   _RTEMS_Unlock_allocator();
     46  if ( _Heap_Size_of_alloc_area( &the_region->Memory, segment, size ) ) {
     47    status = RTEMS_SUCCESSFUL;
     48  } else {
     49    status = RTEMS_INVALID_ADDRESS;
     50  }
     51
     52  _Region_Unlock( the_region );
    5553  return status;
    5654}
  • cpukit/rtems/src/regionprocessqueue.c

    r572cb62 r1142f55  
    4141   */
    4242  cpu_self = _Thread_Dispatch_disable();
    43   _RTEMS_Unlock_allocator();
     43  _Region_Unlock( the_region );
    4444
    4545  /*
  • cpukit/rtems/src/regionresizesegment.c

    r572cb62 r1142f55  
    3838  }
    3939
    40   _RTEMS_Lock_allocator();
     40  the_region = _Region_Get_and_lock( id );
    4141
    42   the_region = _Region_Get( id );
    43 
    44   if ( the_region != NULL ) {
    45     resize_status = _Heap_Resize_block(
    46       &the_region->Memory,
    47       segment,
    48       (uint32_t) size,
    49       &osize,
    50       &avail_size
    51     );
    52     *old_size = (uint32_t) osize;
    53 
    54     switch ( resize_status ) {
    55       case HEAP_RESIZE_SUCCESSFUL:
    56         /* Unlocks allocator */
    57         _Region_Process_queue( the_region );
    58         return RTEMS_SUCCESSFUL;
    59 
    60       case HEAP_RESIZE_UNSATISFIED:
    61         status = RTEMS_UNSATISFIED;
    62         break;
    63 
    64       default:
    65         status = RTEMS_INVALID_ADDRESS;
    66         break;
    67     }
    68   } else {
    69     status = RTEMS_INVALID_ID;
     42  if ( the_region == NULL ) {
     43    return RTEMS_INVALID_ID;
    7044  }
    7145
    72   _RTEMS_Unlock_allocator();
     46  resize_status = _Heap_Resize_block(
     47    &the_region->Memory,
     48    segment,
     49    (uint32_t) size,
     50    &osize,
     51    &avail_size
     52  );
     53  *old_size = (uint32_t) osize;
     54
     55  switch ( resize_status ) {
     56    case HEAP_RESIZE_SUCCESSFUL:
     57      /* Unlocks allocator */
     58      _Region_Process_queue( the_region );
     59      return RTEMS_SUCCESSFUL;
     60
     61    case HEAP_RESIZE_UNSATISFIED:
     62      status = RTEMS_UNSATISFIED;
     63      break;
     64
     65    default:
     66      status = RTEMS_INVALID_ADDRESS;
     67      break;
     68  }
     69
     70  _Region_Unlock( the_region );
    7371  return status;
    7472}
  • cpukit/rtems/src/regionreturnsegment.c

    r572cb62 r1142f55  
    2626)
    2727{
    28   rtems_status_code  status;
    29   Region_Control    *the_region;
     28  Region_Control *the_region;
    3029
    31   _RTEMS_Lock_allocator();
     30  the_region = _Region_Get_and_lock( id );
    3231
    33   the_region = _Region_Get( id );
    34 
    35   if ( the_region != NULL ) {
    36      if ( _Region_Free_segment( the_region, segment ) ) {
    37        the_region->number_of_used_blocks -= 1;
    38 
    39        /* Unlocks allocator */
    40        _Region_Process_queue( the_region );
    41        return RTEMS_SUCCESSFUL;
    42      } else {
    43        status = RTEMS_INVALID_ADDRESS;
    44      }
    45   } else {
    46     status = RTEMS_INVALID_ID;
     32  if ( the_region == NULL ) {
     33    return RTEMS_INVALID_ID;
    4734  }
    4835
    49   _RTEMS_Unlock_allocator();
    50   return status;
     36  if ( _Region_Free_segment( the_region, segment ) ) {
     37    the_region->number_of_used_blocks -= 1;
     38
     39    /* Unlocks allocator */
     40    _Region_Process_queue( the_region );
     41    return RTEMS_SUCCESSFUL;
     42  }
     43
     44  _Region_Unlock( the_region );
     45  return RTEMS_INVALID_ADDRESS;
    5146}
Note: See TracChangeset for help on using the changeset viewer.