Changeset 97312fcc in rtems


Ignore:
Timestamp:
Apr 5, 2016, 12:36:30 PM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
6ca60e5d
Parents:
d2c8693
git-author:
Sebastian Huber <sebastian.huber@…> (04/05/16 12:36:30)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/06/16 07:08:20)
Message:

score: Delete Thread_Wait_information::id

This field was only by the monitor in non-multiprocessing
configurations. Add new field Thread_Wait_information::remote_id in
multiprocessing configurations and use it for the remote procedure call
thread queue.

Add _Thread_Wait_get_id() to obtain the object identifier for debug and
system information tools. Ensure the object layout via static asserts.
Add test cases to sptests/spthreadq01.

Files:
1 added
33 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/monitor/mon-task.c

    rd2c8693 r97312fcc  
    1515#include <string.h>    /* memcpy() */
    1616
     17static void
     18rtems_monitor_task_wait_info(
     19    rtems_monitor_task_t *canonical_task,
     20    Thread_Control       *rtems_thread
     21)
     22{
     23    ISR_lock_Context  lock_context;
     24    void             *lock;
     25
     26    lock = _Thread_Lock_acquire( rtems_thread, &lock_context );
     27
     28    canonical_task->state = rtems_thread->current_state;
     29    canonical_task->wait_id = _Thread_Wait_get_id( rtems_thread );
     30    canonical_task->wait_queue = rtems_thread->Wait.queue;
     31    canonical_task->wait_operations = rtems_thread->Wait.operations;
     32
     33    _Thread_Lock_release( lock, &lock_context );
     34}
     35
    1736void
    1837rtems_monitor_task_canonical(
     
    2140)
    2241{
    23     const Thread_Control *rtems_thread = (const Thread_Control *) thread_void;
    24     RTEMS_API_Control    *api;
     42    Thread_Control    *rtems_thread;
     43    RTEMS_API_Control *api;
     44
     45    rtems_thread =
     46      RTEMS_DECONST( Thread_Control *, (const Thread_Control *) thread_void );
    2547
    2648    api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ];
     49
     50    rtems_monitor_task_wait_info( canonical_task, rtems_thread );
    2751
    2852    canonical_task->entry = rtems_thread->Start.Entry;
     
    3155    canonical_task->cpu = _Per_CPU_Get_index( _Thread_Get_CPU( rtems_thread ) );
    3256    canonical_task->priority = rtems_thread->current_priority;
    33     canonical_task->state = rtems_thread->current_state;
    34     canonical_task->wait_id = rtems_thread->Wait.id;
    35     canonical_task->wait_queue = rtems_thread->Wait.queue;
    36     canonical_task->wait_operations = rtems_thread->Wait.operations;
    3757    canonical_task->events = api->Event.pending_events;
    3858    /*
  • cpukit/posix/include/rtems/posix/cond.h

    rd2c8693 r97312fcc  
    4343typedef struct {
    4444   Objects_Control       Object;
     45   Thread_queue_Control  Wait_queue;
    4546   int                   process_shared;
    4647   pthread_mutex_t       Mutex;
    47    Thread_queue_Control  Wait_queue;
    4848}  POSIX_Condition_variables_Control;
    4949
  • cpukit/posix/include/rtems/posix/mqueue.h

    rd2c8693 r97312fcc  
    5555typedef struct {
    5656   Objects_Control             Object;
     57   CORE_message_queue_Control  Message_queue;
    5758   int                         process_shared;
    5859   bool                        named;
    5960   bool                        linked;
    6061   uint32_t                    open_count;
    61    CORE_message_queue_Control  Message_queue;
    6262   struct sigevent             notification;
    6363}  POSIX_Message_queue_Control;
  • cpukit/posix/include/rtems/posix/mutex.h

    rd2c8693 r97312fcc  
    4343typedef struct {
    4444   Objects_Control     Object;
     45   CORE_mutex_Control  Mutex;
    4546   int                 process_shared;
    46    CORE_mutex_Control  Mutex;
    4747}  POSIX_Mutex_Control;
    4848
  • cpukit/posix/include/rtems/posix/semaphore.h

    rd2c8693 r97312fcc  
    4343typedef struct {
    4444   Objects_Control         Object;
     45   CORE_semaphore_Control  Semaphore;
    4546   int                     process_shared;
    4647   bool                    named;
    4748   bool                    linked;
    4849   uint32_t                open_count;
    49    CORE_semaphore_Control  Semaphore;
    5050   /*
    5151    *  sem_t is 32-bit.  If Object_Id is 16-bit, then they are not
  • cpukit/posix/src/condwaitsupp.c

    rd2c8693 r97312fcc  
    2525#include <rtems/score/watchdog.h>
    2626#include <rtems/score/statesimpl.h>
     27#include <rtems/score/threadimpl.h>
    2728#include <rtems/posix/condimpl.h>
    2829#include <rtems/posix/muteximpl.h>
     30
     31THREAD_WAIT_QUEUE_OBJECT_ASSERT(
     32  POSIX_Condition_variables_Control,
     33  Wait_queue
     34);
    2935
    3036int _POSIX_Condition_variables_Wait_support(
     
    7682        executing = _Thread_Executing;
    7783        executing->Wait.return_code = 0;
    78         executing->Wait.id          = *cond;
    7984
    8085        _Thread_queue_Enqueue(
  • cpukit/posix/src/mqueuerecvsupp.c

    rd2c8693 r97312fcc  
    2929#include <rtems/system.h>
    3030#include <rtems/score/watchdog.h>
     31#include <rtems/score/threadimpl.h>
    3132#include <rtems/seterr.h>
    3233#include <rtems/posix/mqueueimpl.h>
     34
     35THREAD_WAIT_QUEUE_OBJECT_ASSERT(
     36  POSIX_Message_queue_Control,
     37  Message_queue.Wait_queue
     38);
    3339
    3440/*
  • cpukit/posix/src/mutexlocksupp.c

    rd2c8693 r97312fcc  
    2525#include <rtems/score/coremuteximpl.h>
    2626#include <rtems/score/watchdog.h>
     27#include <rtems/score/threadimpl.h>
    2728#include <rtems/posix/muteximpl.h>
    2829#include <rtems/posix/priorityimpl.h>
     30
     31THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_Mutex_Control, Mutex.Wait_queue );
    2932
    3033/*
  • cpukit/posix/src/pbarrierwait.c

    rd2c8693 r97312fcc  
    2323
    2424#include <rtems/posix/barrierimpl.h>
    25 #include <rtems/score/thread.h>
     25#include <rtems/score/threadimpl.h>
     26
     27THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_Barrier_Control, Barrier.Wait_queue );
    2628
    2729/**
  • cpukit/posix/src/prwlockwrlock.c

    rd2c8693 r97312fcc  
    2525
    2626#include <rtems/posix/rwlockimpl.h>
    27 #include <rtems/score/thread.h>
     27#include <rtems/score/threadimpl.h>
     28
     29THREAD_WAIT_QUEUE_OBJECT_ASSERT( POSIX_RWLock_Control, RWLock.Wait_queue );
    2830
    2931/*
  • cpukit/posix/src/semaphorewaitsupp.c

    rd2c8693 r97312fcc  
    2828
    2929#include <rtems/system.h>
     30#include <rtems/score/threadimpl.h>
    3031#include <rtems/posix/semaphoreimpl.h>
    3132#include <rtems/seterr.h>
     33
     34THREAD_WAIT_QUEUE_OBJECT_ASSERT(
     35  POSIX_Semaphore_Control,
     36  Semaphore.Wait_queue
     37);
    3238
    3339int _POSIX_Semaphore_Wait_support(
  • cpukit/rtems/include/rtems/rtems/barrier.h

    rd2c8693 r97312fcc  
    5656  /** This is used to manage a barrier as an object. */
    5757  Objects_Control          Object;
     58  /** This is used to implement the barrier. */
     59  CORE_barrier_Control     Barrier;
    5860  /** This is used to specify the attributes of a barrier. */
    5961  rtems_attribute          attribute_set;
    60   /** This is used to implement the barrier. */
    61   CORE_barrier_Control     Barrier;
    6262}   Barrier_Control;
    6363
  • cpukit/rtems/include/rtems/rtems/message.h

    rd2c8693 r97312fcc  
    5454  /** This field is the inherited object characteristics. */
    5555  Objects_Control             Object;
     56  /** This field is the instance of the SuperCore Message Queue. */
     57  CORE_message_queue_Control  message_queue;
    5658  /** This field is the attribute set as defined by the API. */
    5759  rtems_attribute             attribute_set;
    58   /** This field is the instance of the SuperCore Message Queue. */
    59   CORE_message_queue_Control  message_queue;
    6060}   Message_queue_Control;
    6161
  • cpukit/rtems/include/rtems/rtems/sem.h

    rd2c8693 r97312fcc  
    6464  /** This field is the object management portion of a Semaphore instance. */
    6565  Objects_Control          Object;
    66 
    67   /**
    68    *  This is the Classic API attribute provided to the create directive.
    69    *  It is translated into behavioral attributes on the SuperCore Semaphore
    70    *  or Mutex instance.
    71    */
    72   rtems_attribute          attribute_set;
    7366
    7467  /**
     
    9891#endif
    9992  } Core_control;
     93
     94  /**
     95   *  This is the Classic API attribute provided to the create directive.
     96   *  It is translated into behavioral attributes on the SuperCore Semaphore
     97   *  or Mutex instance.
     98   */
     99  rtems_attribute          attribute_set;
    100100}   Semaphore_Control;
    101101
  • cpukit/rtems/src/barrierwait.c

    rd2c8693 r97312fcc  
    2323#include <rtems/rtems/support.h>
    2424#include <rtems/rtems/barrierimpl.h>
    25 #include <rtems/score/thread.h>
     25#include <rtems/score/threadimpl.h>
     26
     27THREAD_WAIT_QUEUE_OBJECT_ASSERT( Barrier_Control, Barrier.Wait_queue );
    2628
    2729rtems_status_code rtems_barrier_wait(
  • cpukit/rtems/src/msgqreceive.c

    rd2c8693 r97312fcc  
    2323#include <rtems/score/isr.h>
    2424#include <rtems/score/coremsgimpl.h>
    25 #include <rtems/score/thread.h>
     25#include <rtems/score/threadimpl.h>
    2626#include <rtems/score/wkspace.h>
    2727#include <rtems/rtems/status.h>
     
    3030#include <rtems/rtems/optionsimpl.h>
    3131#include <rtems/rtems/support.h>
     32
     33THREAD_WAIT_QUEUE_OBJECT_ASSERT(
     34  Message_queue_Control,
     35  message_queue.Wait_queue
     36);
    3237
    3338rtems_status_code rtems_message_queue_receive(
  • cpukit/rtems/src/regiongetsegment.c

    rd2c8693 r97312fcc  
    7676            _RTEMS_Unlock_allocator();
    7777
    78             executing->Wait.id              = id;
    7978            executing->Wait.count           = size;
    8079            executing->Wait.return_argument = segment;
  • cpukit/rtems/src/semobtain.c

    rd2c8693 r97312fcc  
    2828#include <rtems/score/coremuteximpl.h>
    2929#include <rtems/score/coresemimpl.h>
    30 #include <rtems/score/thread.h>
     30#include <rtems/score/threadimpl.h>
    3131
    3232#include <rtems/score/interr.h>
     33
     34THREAD_WAIT_QUEUE_OBJECT_ASSERT(
     35  Semaphore_Control,
     36  Core_control.mutex.Wait_queue
     37);
     38
     39THREAD_WAIT_QUEUE_OBJECT_ASSERT(
     40  Semaphore_Control,
     41  Core_control.semaphore.Wait_queue
     42);
    3343
    3444rtems_status_code rtems_semaphore_obtain(
  • cpukit/score/Makefile.am

    rd2c8693 r97312fcc  
    309309libscore_a_SOURCES += src/threadglobalconstruction.c
    310310libscore_a_SOURCES += src/threadtimeout.c
     311libscore_a_SOURCES += src/threadwaitgetid.c
    311312libscore_a_SOURCES += src/threadyield.c
    312313
  • cpukit/score/include/rtems/score/coremuteximpl.h

    rd2c8693 r97312fcc  
    266266        CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT;
    267267    } else {
    268       executing->Wait.id = id;
    269268      _CORE_mutex_Seize_interrupt_blocking(
    270269        the_mutex,
  • cpukit/score/include/rtems/score/coresemimpl.h

    rd2c8693 r97312fcc  
    252252  }
    253253
    254   executing->Wait.id = id;
    255254  _Thread_queue_Enqueue_critical(
    256255    &the_semaphore->Wait_queue.Queue,
  • cpukit/score/include/rtems/score/thread.h

    rd2c8693 r97312fcc  
    292292  } Node;
    293293
    294   /** This field is the Id of the object this thread is waiting upon. */
    295   Objects_Id            id;
     294#if defined(RTEMS_MULTIPROCESSING)
     295  /*
     296   * @brief This field is the identifier of the remote object this thread is
     297   * waiting upon.
     298   */
     299  Objects_Id            remote_id;
     300#endif
    296301  /** This field is used to return an integer while when blocked. */
    297302  uint32_t              count;
  • cpukit/score/include/rtems/score/threadimpl.h

    rd2c8693 r97312fcc  
    14501450
    14511451/**
     1452 * @brief Helper structure to ensure that all objects containing a thread queue
     1453 * have the right layout.
     1454 *
     1455 * @see _Thread_Wait_get_id() and THREAD_WAIT_QUEUE_OBJECT_ASSERT().
     1456 */
     1457typedef struct {
     1458  Objects_Control      Object;
     1459  Thread_queue_Control Wait_queue;
     1460} Thread_Wait_queue_object;
     1461
     1462#define THREAD_WAIT_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member ) \
     1463  RTEMS_STATIC_ASSERT( \
     1464    offsetof( object_type, wait_queue_member ) \
     1465      == offsetof( Thread_Wait_queue_object, Wait_queue ) \
     1466    && ( &( ( (object_type *) 0 )->wait_queue_member ) \
     1467      == ( &( (Thread_Wait_queue_object *) 0 )->Wait_queue ) ), \
     1468    object_type \
     1469  )
     1470
     1471/**
     1472 * @brief Returns the object identifier of the object containing the current
     1473 * thread wait queue.
     1474 *
     1475 * This function may be used for debug and system information purposes.  The
     1476 * caller must be the owner of the thread lock.
     1477 *
     1478 * @retval 0 The thread waits on no thread queue currently, the thread wait
     1479 *   queue is not contained in an object, or the current thread state provides
     1480 *   insufficient information, e.g. the thread is in the middle of a blocking
     1481 *   operation.
     1482 * @retval other The object identifier of the object containing the thread wait
     1483 *   queue.
     1484 */
     1485Objects_Id _Thread_Wait_get_id( const Thread_Control *the_thread );
     1486
     1487/**
    14521488 * @brief General purpose thread wait timeout.
    14531489 *
  • cpukit/score/src/corebarrierwait.c

    rd2c8693 r97312fcc  
    4848  }
    4949
    50   executing->Wait.id = id;
    51 
    5250  _Thread_queue_Enqueue_critical(
    5351    &the_barrier->Wait_queue.Queue,
  • cpukit/score/src/coremsgseize.c

    rd2c8693 r97312fcc  
    128128  }
    129129
    130   executing->Wait.id = id;
    131130  executing->Wait.return_argument_second.mutable_object = buffer;
    132131  executing->Wait.return_argument = size_p;
  • cpukit/score/src/coremsgsubmit.c

    rd2c8693 r97312fcc  
    127127     *  would be to use this variable prior to here.
    128128     */
    129     executing->Wait.id = id;
    130129    executing->Wait.return_argument_second.immutable_object = buffer;
    131130    executing->Wait.option = (uint32_t) size;
  • cpukit/score/src/corerwlockobtainread.c

    rd2c8693 r97312fcc  
    8282     */
    8383
    84     executing->Wait.id          = id;
    8584    executing->Wait.option      = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
    8685    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
  • cpukit/score/src/corerwlockobtainwrite.c

    rd2c8693 r97312fcc  
    6969     */
    7070
    71     executing->Wait.id          = id;
    7271    executing->Wait.option      = CORE_RWLOCK_THREAD_WAITING_FOR_WRITE;
    7372    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
  • cpukit/score/src/mpci.c

    rd2c8693 r97312fcc  
    243243       ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) / sizeof(uint32_t);
    244244
    245     executing->Wait.id = the_packet->id;
     245    executing->Wait.remote_id = the_packet->id;
    246246
    247247    (*_MPCI_table->send_packet)( destination, the_packet );
  • cpukit/score/src/threadmp.c

    rd2c8693 r97312fcc  
    9696    the_proxy->current_state = _States_Set( STATES_DORMANT, the_state );
    9797
    98     the_proxy->Wait.id                      = executing->Wait.id;
    9998    the_proxy->Wait.count                   = executing->Wait.count;
    10099    the_proxy->Wait.return_argument         = executing->Wait.return_argument;
  • cpukit/score/src/threadqextractwithproxy.c

    rd2c8693 r97312fcc  
    4242      Objects_Thread_queue_Extract_callout  proxy_extract_callout;
    4343
    44       id = the_thread->Wait.id;
     44      id = the_thread->Wait.remote_id;
    4545      the_information = _Objects_Get_information_id( id );
    4646      proxy_extract_callout = the_information->extract;
  • testsuites/sptests/spthreadq01/init.c

    rd2c8693 r97312fcc  
    22 *  COPYRIGHT (c) 1989-2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2016 embedded brains GmbH.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#include <tmacros.h>
    1517
    16 #include <sys/types.h>
    17 #include <rtems/score/threadqimpl.h>
     18#include <rtems.h>
     19
     20#include <rtems/score/threadimpl.h>
     21
     22#if defined(RTEMS_POSIX_API)
     23  #include <fcntl.h>
     24  #include <mqueue.h>
     25  #include <semaphore.h>
     26  #include <string.h>
     27  #include <pthread.h>
     28
     29  #include <rtems/posix/mqueueimpl.h>
     30#endif
    1831
    1932const char rtems_test_name[] = "SPTHREADQ 1";
    2033
    2134static Thread_queue_Control queue = THREAD_QUEUE_INITIALIZER( "Queue" );
     35
     36typedef struct {
     37  Thread_Control *master;
     38  rtems_id master_id;
     39  rtems_id worker_id;
     40  rtems_id sem;
     41  rtems_id mtx;
     42  rtems_id mq;
     43  rtems_id br;
     44#if defined(RTEMS_POSIX_API)
     45  sem_t psem;
     46  pthread_mutex_t pmtx;
     47  pthread_cond_t pcv;
     48  pthread_rwlock_t prw;
     49  mqd_t pmq;
     50#endif
     51} test_context;
     52
     53static test_context test_instance;
     54
     55static void wait_for_worker(test_context *ctx)
     56{
     57  rtems_status_code sc;
     58
     59  sc = rtems_event_transient_receive(RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     60  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     61}
     62
     63static void wake_up_master(test_context *ctx)
     64{
     65  rtems_status_code sc;
     66
     67  sc = rtems_event_transient_send(ctx->master_id);
     68  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     69}
     70
     71static rtems_id get_wait_id(test_context *ctx)
     72{
     73  ISR_lock_Context lock_context;
     74  void *lock;
     75  rtems_id id;
     76
     77  lock = _Thread_Lock_acquire(ctx->master, &lock_context);
     78  id = _Thread_Wait_get_id(ctx->master);
     79  _Thread_Lock_release(lock, &lock_context);
     80
     81  return id;
     82}
     83
     84static void classic_worker(test_context *ctx)
     85{
     86  rtems_status_code sc;
     87  char buf[1];
     88
     89  wake_up_master(ctx);
     90  rtems_test_assert(get_wait_id(ctx) == ctx->sem);
     91
     92  sc = rtems_semaphore_release(ctx->sem);
     93  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     94
     95  sc = rtems_semaphore_obtain(ctx->mtx, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     96  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     97
     98  wake_up_master(ctx);
     99  rtems_test_assert(get_wait_id(ctx) == ctx->mtx);
     100
     101  sc = rtems_semaphore_release(ctx->mtx);
     102  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     103
     104  wake_up_master(ctx);
     105  rtems_test_assert(get_wait_id(ctx) == ctx->mq);
     106
     107  buf[0] = 'X';
     108  sc = rtems_message_queue_send(ctx->mq, &buf[0], sizeof(buf));
     109  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     110
     111  wake_up_master(ctx);
     112  rtems_test_assert(get_wait_id(ctx) == ctx->br);
     113
     114  sc = rtems_barrier_wait(ctx->br, RTEMS_NO_TIMEOUT);
     115  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     116}
     117
     118static void posix_worker(test_context *ctx)
     119{
     120#if defined(RTEMS_POSIX_API)
     121  int rv;
     122  int eno;
     123  char buf[1];
     124  POSIX_Message_queue_Control_fd *the_mq_fd;
     125  Objects_Locations location;
     126  ISR_lock_Context lock_context;
     127
     128  wake_up_master(ctx);
     129  rtems_test_assert(get_wait_id(ctx) == ctx->psem);
     130
     131  rv = sem_post(&ctx->psem);
     132  rtems_test_assert(rv == 0);
     133
     134  eno = pthread_mutex_lock(&ctx->pmtx);
     135  rtems_test_assert(eno == 0);
     136
     137  wake_up_master(ctx);
     138  rtems_test_assert(get_wait_id(ctx) == ctx->pmtx);
     139
     140  eno = pthread_mutex_unlock(&ctx->pmtx);
     141  rtems_test_assert(eno == 0);
     142
     143  eno = pthread_mutex_lock(&ctx->pmtx);
     144  rtems_test_assert(eno == 0);
     145
     146  rtems_test_assert(get_wait_id(ctx) == ctx->pcv);
     147
     148  eno = pthread_cond_signal(&ctx->pcv);
     149  rtems_test_assert(eno == 0);
     150
     151  eno = pthread_mutex_unlock(&ctx->pmtx);
     152  rtems_test_assert(eno == 0);
     153
     154  eno = pthread_rwlock_wrlock(&ctx->prw);
     155  rtems_test_assert(eno == 0);
     156
     157  wake_up_master(ctx);
     158  rtems_test_assert(get_wait_id(ctx) == ctx->prw);
     159
     160  eno = pthread_rwlock_unlock(&ctx->prw);
     161  rtems_test_assert(eno == 0);
     162
     163  wake_up_master(ctx);
     164  the_mq_fd = _POSIX_Message_queue_Get_fd_interrupt_disable(
     165    ctx->pmq,
     166    &location,
     167    &lock_context
     168  );
     169  _ISR_lock_ISR_enable(&lock_context);
     170  rtems_test_assert(the_mq_fd != NULL);
     171  rtems_test_assert(location == OBJECTS_LOCAL);
     172  rtems_test_assert(get_wait_id(ctx) == the_mq_fd->Queue->Object.id);
     173
     174  buf[0] = 'x';
     175  rv = mq_send(ctx->pmq, &buf[0], sizeof(buf), 0);
     176  rtems_test_assert(rv == 0);
     177#endif
     178}
     179
     180static rtems_task worker(rtems_task_argument arg)
     181{
     182  test_context *ctx = (test_context *) arg;
     183
     184  rtems_test_assert(get_wait_id(ctx) == 0);
     185
     186  classic_worker(ctx);
     187  posix_worker(ctx);
     188}
     189
     190static void test_classic_init(test_context *ctx)
     191{
     192  rtems_status_code sc;
     193
     194  sc = rtems_semaphore_create(
     195    rtems_build_name('S', 'E', 'M', ' '),
     196    0,
     197    RTEMS_COUNTING_SEMAPHORE,
     198    0,
     199    &ctx->sem
     200  );
     201  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     202
     203  sc = rtems_semaphore_create(
     204    rtems_build_name('M', 'T', 'X', ' '),
     205    1,
     206    RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
     207    0,
     208    &ctx->mtx
     209  );
     210  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     211
     212  sc = rtems_message_queue_create(
     213    rtems_build_name('M', 'Q', ' ', ' '),
     214    1,
     215    1,
     216    RTEMS_DEFAULT_ATTRIBUTES,
     217    &ctx->mq
     218  );
     219  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     220
     221  sc = rtems_barrier_create(
     222    rtems_build_name('B', 'R', ' ', ' '),
     223    RTEMS_BARRIER_AUTOMATIC_RELEASE,
     224    2,
     225    &ctx->br
     226  );
     227  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     228}
     229
     230static void test_posix_init(test_context *ctx)
     231{
     232#if defined(RTEMS_POSIX_API)
     233  int rv;
     234  int eno;
     235  struct mq_attr attr;
     236
     237  rv = sem_init(&ctx->psem, 0, 0);
     238  rtems_test_assert(rv == 0);
     239
     240  eno = pthread_mutex_init(&ctx->pmtx, NULL);
     241  rtems_test_assert(eno == 0);
     242
     243  eno = pthread_cond_init(&ctx->pcv, NULL);
     244  rtems_test_assert(eno == 0);
     245
     246  eno = pthread_rwlock_init(&ctx->prw, NULL);
     247  rtems_test_assert(eno == 0);
     248
     249  memset(&attr, 0, sizeof(attr));
     250  attr.mq_maxmsg = 1;
     251  attr.mq_msgsize = sizeof(char);
     252
     253  ctx->pmq = mq_open("mq", O_CREAT | O_RDWR, 0x777, &attr);
     254  rtems_test_assert(ctx->mq != -1);
     255#endif
     256}
     257
     258static void test_context_init(test_context *ctx)
     259{
     260  rtems_status_code sc;
     261
     262  ctx->master = _Thread_Get_executing();
     263  ctx->master_id = rtems_task_self();
     264
     265  test_classic_init(ctx);
     266  test_posix_init(ctx);
     267
     268  sc = rtems_task_create(
     269    rtems_build_name('W', 'O', 'R', 'K'),
     270    2,
     271    RTEMS_MINIMUM_STACK_SIZE,
     272    RTEMS_DEFAULT_MODES,
     273    RTEMS_DEFAULT_ATTRIBUTES,
     274    &ctx->worker_id
     275  );
     276  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     277
     278  sc = rtems_task_start(ctx->worker_id, worker, (rtems_task_argument) ctx);
     279  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     280}
     281
     282static void test_classic_obj(test_context *ctx)
     283{
     284  rtems_status_code sc;
     285  char buf[1];
     286  size_t n;
     287
     288  wait_for_worker(ctx);
     289
     290  sc = rtems_semaphore_obtain(ctx->sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     291  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     292
     293  wait_for_worker(ctx);
     294
     295  sc = rtems_semaphore_obtain(ctx->mtx, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     296  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     297
     298  wait_for_worker(ctx);
     299
     300  buf[0] = 'Y';
     301  n = 123;
     302  sc = rtems_message_queue_receive(
     303    ctx->mq,
     304    &buf[0],
     305    &n,
     306    RTEMS_WAIT,
     307    RTEMS_NO_TIMEOUT
     308  );
     309  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     310  rtems_test_assert(buf[0] == 'X');
     311  rtems_test_assert(n == sizeof(buf));
     312
     313  wait_for_worker(ctx);
     314
     315  sc = rtems_barrier_wait(ctx->br, RTEMS_NO_TIMEOUT);
     316  rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     317}
     318
     319static void test_posix_obj(test_context *ctx)
     320{
     321#if defined(RTEMS_POSIX_API)
     322  int rv;
     323  int eno;
     324  char buf[1];
     325  unsigned prio;
     326  ssize_t n;
     327
     328  wait_for_worker(ctx);
     329
     330  rv = sem_wait(&ctx->psem);
     331  rtems_test_assert(rv == 0);
     332
     333  wait_for_worker(ctx);
     334
     335  eno = pthread_mutex_lock(&ctx->pmtx);
     336  rtems_test_assert(eno == 0);
     337
     338  eno = pthread_cond_wait(&ctx->pcv, &ctx->pmtx);
     339  rtems_test_assert(eno == 0);
     340
     341  eno = pthread_mutex_unlock(&ctx->pmtx);
     342  rtems_test_assert(eno == 0);
     343
     344  wait_for_worker(ctx);
     345
     346  eno = pthread_rwlock_wrlock(&ctx->prw);
     347  rtems_test_assert(eno == 0);
     348
     349  wait_for_worker(ctx);
     350
     351  buf[0] = 'y';
     352  prio = 1;
     353  n = mq_receive(ctx->pmq, &buf[0], sizeof(buf), &prio);
     354  rtems_test_assert(n == (ssize_t) sizeof(buf));
     355  rtems_test_assert(buf[0] == 'x');
     356  rtems_test_assert(prio == 0);
     357#endif
     358}
    22359
    23360static rtems_task Init(
     
    25362)
    26363{
     364  test_context *ctx = &test_instance;
     365
    27366  TEST_BEGIN();
    28367
     
    33372  /* is there more to check? */
    34373
     374  test_context_init(ctx);
     375  test_classic_obj(ctx);
     376  test_posix_obj(ctx);
     377
    35378  rtems_test_assert( queue.Queue.heads == NULL );
    36379
     
    44387#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
    45388
    46 #define CONFIGURE_MAXIMUM_TASKS  1
     389#define CONFIGURE_MAXIMUM_TASKS  2
     390#define CONFIGURE_MAXIMUM_SEMAPHORES  2
     391#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES  1
     392#define CONFIGURE_MAXIMUM_BARRIERS  1
     393
     394#if defined(RTEMS_POSIX_API)
     395  #define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1
     396  #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 1
     397  #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 1
     398  #define CONFIGURE_MAXIMUM_POSIX_RWLOCKS 1
     399  #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 1
     400  #define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUE_DESCRIPTORS 1
     401  #define CONFIGURE_MESSAGE_BUFFER_MEMORY \
     402    (2 * CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, 1))
     403#else
     404  #define CONFIGURE_MESSAGE_BUFFER_MEMORY \
     405    CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, 1)
     406#endif
     407
    47408#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    48409
Note: See TracChangeset for help on using the changeset viewer.