Changeset 0e3c59d6 in rtems


Ignore:
Timestamp:
Jun 26, 2015, 10:54:33 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
12f93fbb
Parents:
10e32a26
git-author:
Sebastian Huber <sebastian.huber@…> (06/26/15 10:54:33)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/30/15 07:11:13)
Message:

score: Use a plain ticket lock for thread locks

This enables external libraries to use thread locks since they are
independent of the actual RTEMS build configuration, e.g. profiling
enabled or disabled.

Location:
cpukit/score
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/thread.h

    r10e32a26 r0e3c59d6  
    652652  /**
    653653   * @brief The current thread lock.
    654    */
    655   ISR_lock_Control *current;
     654   *
     655   * This is a plain ticket lock without SMP lock statistics support.  This
     656   * enables external libraries to use thread locks since they are independent
     657   * of the actual RTEMS build configuration, e.g. profiling enabled or
     658   * disabled.
     659   */
     660  SMP_ticket_lock_Control *current;
    656661
    657662  /**
     
    659664   * resource.
    660665   */
    661   ISR_lock_Control Default;
     666  SMP_ticket_lock_Control Default;
     667
     668#if defined(RTEMS_PROFILING)
     669  /**
     670   * @brief The thread lock statistics.
     671   *
     672   * These statistics are used by the executing thread in case it acquires a
     673   * thread lock.  Thus the statistics are an aggregation of acquire and
     674   * release operations of diffent locks.
     675   */
     676  SMP_lock_Stats Stats;
     677#endif
    662678
    663679  /**
  • cpukit/score/include/rtems/score/threadimpl.h

    r10e32a26 r0e3c59d6  
    971971
    972972/**
    973  * @brief Acquires the default thread lock and returns the executing thread.
    974  *
    975  * @param[in] lock_context The lock context used for the corresponding lock
    976  * release.
    977  *
    978  * @return The executing thread.
    979  *
    980  * @see _Thread_Lock_release_default().
    981  */
    982 RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Lock_acquire_default_for_executing(
    983   ISR_lock_Context *lock_context
    984 )
    985 {
    986   Thread_Control *executing;
    987 
    988   _ISR_lock_ISR_disable( lock_context );
    989   executing = _Thread_Executing;
    990   _ISR_lock_Acquire( &executing->Lock.Default, lock_context );
    991 
    992   return executing;
    993 }
    994 
    995 /**
    996973 * @brief Acquires the default thread lock inside a critical section
    997974 * (interrupts disabled).
     
    1009986{
    1010987  _Assert( _ISR_Get_level() != 0 );
    1011   _ISR_lock_Acquire( &the_thread->Lock.Default, lock_context );
     988#if defined(RTEMS_SMP)
     989  _SMP_ticket_lock_Acquire(
     990    &the_thread->Lock.Default,
     991    &_Thread_Executing->Lock.Stats,
     992    &lock_context->Lock_context.Stats_context
     993  );
     994#else
     995  (void) the_thread;
     996  (void) lock_context;
     997#endif
     998}
     999
     1000/**
     1001 * @brief Acquires the default thread lock and returns the executing thread.
     1002 *
     1003 * @param[in] lock_context The lock context used for the corresponding lock
     1004 * release.
     1005 *
     1006 * @return The executing thread.
     1007 *
     1008 * @see _Thread_Lock_release_default().
     1009 */
     1010RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Lock_acquire_default_for_executing(
     1011  ISR_lock_Context *lock_context
     1012)
     1013{
     1014  Thread_Control *executing;
     1015
     1016  _ISR_lock_ISR_disable( lock_context );
     1017  executing = _Thread_Executing;
     1018  _Thread_Lock_acquire_default_critical( executing, lock_context );
     1019
     1020  return executing;
    10121021}
    10131022
     
    10261035)
    10271036{
    1028   _ISR_lock_ISR_disable_and_acquire( &the_thread->Lock.Default, lock_context );
     1037  _ISR_lock_ISR_disable( lock_context );
     1038  _Thread_Lock_acquire_default_critical( the_thread, lock_context );
    10291039}
    10301040
     
    10401050 */
    10411051RTEMS_INLINE_ROUTINE void _Thread_Lock_release_critical(
    1042   ISR_lock_Control *lock,
     1052  void            *lock,
    10431053  ISR_lock_Context *lock_context
    10441054)
    10451055{
    1046   _ISR_lock_Release( lock, lock_context );
     1056#if defined(RTEMS_SMP)
     1057  _SMP_ticket_lock_Release(
     1058    lock,
     1059    &lock_context->Lock_context.Stats_context
     1060  );
     1061#else
     1062  (void) lock;
     1063  (void) lock_context;
     1064#endif
    10471065}
    10481066
     
    10541072 */
    10551073RTEMS_INLINE_ROUTINE void _Thread_Lock_release(
    1056   ISR_lock_Control *lock,
     1074  void            *lock,
    10571075  ISR_lock_Context *lock_context
    10581076)
     
    11111129 * @return The lock required by _Thread_Lock_release().
    11121130 */
    1113 RTEMS_INLINE_ROUTINE ISR_lock_Control *_Thread_Lock_acquire(
     1131RTEMS_INLINE_ROUTINE void *_Thread_Lock_acquire(
    11141132  Thread_Control   *the_thread,
    11151133  ISR_lock_Context *lock_context
     
    11171135{
    11181136#if defined(RTEMS_SMP)
    1119   ISR_lock_Control *lock;
     1137  SMP_ticket_lock_Control *lock;
    11201138
    11211139  while ( true ) {
     
    11321150
    11331151    lock = the_thread->Lock.current;
    1134     _ISR_lock_Acquire( lock, lock_context );
     1152    _SMP_ticket_lock_Acquire(
     1153      lock,
     1154      &_Thread_Executing->Lock.Stats,
     1155      &lock_context->Lock_context.Stats_context
     1156    );
    11351157
    11361158    /*
     
    11611183 */
    11621184RTEMS_INLINE_ROUTINE void _Thread_Lock_set_unprotected(
    1163   Thread_Control   *the_thread,
    1164   ISR_lock_Control *new_lock
     1185  Thread_Control          *the_thread,
     1186  SMP_ticket_lock_Control *new_lock
    11651187)
    11661188{
     
    11971219#if defined(RTEMS_SMP)
    11981220RTEMS_INLINE_ROUTINE void _Thread_Lock_set(
    1199   Thread_Control   *the_thread,
    1200   ISR_lock_Control *new_lock
     1221  Thread_Control          *the_thread,
     1222  SMP_ticket_lock_Control *new_lock
    12011223)
    12021224{
  • cpukit/score/include/rtems/score/threadq.h

    r10e32a26 r0e3c59d6  
    7676   * _Thread_queue_Release().
    7777   */
    78   ISR_LOCK_MEMBER( Lock )
     78#if defined(RTEMS_SMP)
     79  SMP_ticket_lock_Control Lock;
     80#endif
    7981} Thread_queue_Queue;
    8082
     
    192194  Thread_queue_Queue Queue;
    193195
     196#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
     197  SMP_lock_Stats Lock_stats;
     198#endif
     199
    194200  /**
    195201   * @brief The operations for the actual thread queue.
  • cpukit/score/include/rtems/score/threadqimpl.h

    r10e32a26 r0e3c59d6  
    3939{
    4040  queue->heads = NULL;
    41   _ISR_lock_Initialize( &queue->Lock, "Thread Queue" );
    42 }
    43 
    44 RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_acquire_critical(
     41#if defined(RTEMS_SMP)
     42  _SMP_ticket_lock_Initialize( &queue->Lock );
     43#endif
     44}
     45
     46RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_do_acquire_critical(
    4547  Thread_queue_Queue *queue,
     48#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
     49  SMP_lock_Stats     *lock_stats,
     50#endif
    4651  ISR_lock_Context   *lock_context
    4752)
    4853{
    49   _ISR_lock_Acquire( &queue->Lock, lock_context );
    50 }
     54#if defined(RTEMS_SMP)
     55  _SMP_ticket_lock_Acquire(
     56    &queue->Lock,
     57    lock_stats,
     58    &lock_context->Lock_context.Stats_context
     59  );
     60#else
     61  (void) queue;
     62  (void) lock_context;
     63#endif
     64}
     65
     66#if defined(RTEMS_SMP) && defined( RTEMS_PROFILING )
     67  #define \
     68    _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \
     69    _Thread_queue_Queue_do_acquire_critical( queue, lock_stats, lock_context )
     70#else
     71  #define \
     72    _Thread_queue_Queue_acquire_critical( queue, lock_stats, lock_context ) \
     73    _Thread_queue_Queue_do_acquire_critical( queue, lock_context )
     74#endif
    5175
    5276RTEMS_INLINE_ROUTINE void _Thread_queue_Queue_release(
     
    5579)
    5680{
    57   _ISR_lock_Release_and_ISR_enable( &queue->Lock, lock_context );
     81#if defined(RTEMS_SMP)
     82  _SMP_ticket_lock_Release(
     83    &queue->Lock,
     84    &lock_context->Lock_context.Stats_context
     85  );
     86#endif
     87  _ISR_lock_ISR_enable( lock_context );
    5888}
    5989
     
    6595  _Thread_queue_Queue_acquire_critical(
    6696    &the_thread_queue->Queue,
     97    &the_thread_queue->Lock_stats,
    6798    lock_context
    6899  );
     
    83114)
    84115{
    85   _Thread_queue_Queue_release( &the_thread_queue->Queue, lock_context );
     116  _Thread_queue_Queue_release(
     117    &the_thread_queue->Queue,
     118    lock_context
     119  );
    86120}
    87121
     
    398432);
    399433
    400 #if defined(RTEMS_SMP)
     434#if defined(RTEMS_SMP) && defined(RTEMS_PROFILING)
    401435  #define THREAD_QUEUE_FIFO_INITIALIZER( designator, name ) { \
    402436      .Queue = { \
    403437        .heads = NULL, \
    404         .Lock = ISR_LOCK_INITIALIZER( name ), \
     438        .Lock = SMP_TICKET_LOCK_INITIALIZER, \
     439      }, \
     440      .Lock_stats = SMP_LOCK_STATS_INITIALIZER( name ), \
     441      .operations = &_Thread_queue_Operations_FIFO \
     442    }
     443
     444  #define THREAD_QUEUE_PRIORITY_INITIALIZER( designator, name ) { \
     445      .Queue = { \
     446        .heads = NULL, \
     447        .Lock = SMP_TICKET_LOCK_INITIALIZER, \
     448      }, \
     449      .Lock_stats = SMP_LOCK_STATS_INITIALIZER( name ), \
     450      .operations = &_Thread_queue_Operations_priority \
     451    }
     452#elif defined(RTEMS_SMP)
     453  #define THREAD_QUEUE_FIFO_INITIALIZER( designator, name ) { \
     454      .Queue = { \
     455        .heads = NULL, \
     456        .Lock = SMP_TICKET_LOCK_INITIALIZER, \
    405457      }, \
    406458      .operations = &_Thread_queue_Operations_FIFO \
     
    410462      .Queue = { \
    411463        .heads = NULL, \
    412         .Lock = ISR_LOCK_INITIALIZER( name ), \
     464        .Lock = SMP_TICKET_LOCK_INITIALIZER, \
    413465      }, \
    414466      .operations = &_Thread_queue_Operations_priority \
     
    430482)
    431483{
    432   _ISR_lock_Destroy( &the_thread_queue->Queue.Lock );
     484#if defined(RTEMS_SMP)
     485  _SMP_ticket_lock_Destroy( &the_thread_queue->Queue.Lock );
     486  _SMP_lock_Stats_destroy( &the_thread_queue->Lock_stats );
     487#endif
    433488}
    434489
  • cpukit/score/src/threadinitialize.c

    r10e32a26 r0e3c59d6  
    205205  _CPU_Context_Set_is_executing( &the_thread->Registers, false );
    206206  the_thread->Lock.current = &the_thread->Lock.Default;
    207   _ISR_lock_Initialize( &the_thread->Lock.Default, "Thread Lock Default");
     207  _SMP_ticket_lock_Initialize( &the_thread->Lock.Default );
     208  _SMP_lock_Stats_initialize( &the_thread->Lock.Stats, "Thread Lock" );
    208209  _SMP_lock_Stats_initialize( &the_thread->Potpourri_stats, "Thread Potpourri" );
    209210  _Atomic_Init_uint(&the_thread->Lock.generation, 0);
  • cpukit/score/src/threadq.c

    r10e32a26 r0e3c59d6  
    6161
    6262  _Thread_queue_Queue_initialize( &the_thread_queue->Queue );
     63#if defined(RTEMS_SMP)
     64  _SMP_lock_Stats_initialize( &the_thread_queue->Lock_stats, "Thread Queue" );
     65#endif
    6366}
  • cpukit/score/src/threadqenqueue.c

    r10e32a26 r0e3c59d6  
    169169{
    170170  ISR_lock_Context    lock_context;
    171   ISR_lock_Control   *lock;
     171  void               *lock;
    172172  Thread_queue_Queue *queue;
    173173
  • cpukit/score/src/threadrestart.c

    r10e32a26 r0e3c59d6  
    130130
    131131#if defined(RTEMS_SMP)
    132   _ISR_lock_Destroy( &the_thread->Lock.Default );
     132  _SMP_ticket_lock_Destroy( &the_thread->Lock.Default );
     133  _SMP_lock_Stats_destroy( &the_thread->Lock.Stats );
    133134  _SMP_lock_Stats_destroy( &the_thread->Potpourri_stats );
    134135#endif
  • cpukit/score/src/threadtimeout.c

    r10e32a26 r0e3c59d6  
    3737{
    3838  Thread_Control    *the_thread;
    39   ISR_lock_Control  *thread_lock;
     39  void              *thread_lock;
    4040  ISR_lock_Context   lock_context;
    4141  Thread_Wait_flags  wait_flags;
Note: See TracChangeset for help on using the changeset viewer.