Changeset 7237b3e in rtems


Ignore:
Timestamp:
Jul 2, 2015, 11:12:38 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
40188718
Parents:
214d8ed
git-author:
Sebastian Huber <sebastian.huber@…> (07/02/15 11:12:38)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/30/15 07:11:18)
Message:

score: Add self-contained semaphore implementation

Files:
1 added
5 edited

Legend:

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

    r214d8ed r7237b3e  
    136136    { "Wsig",   STATES_WAITING_FOR_SIGNAL, 0 },
    137137    { "Wslmtx", STATES_WAITING_FOR_SYS_LOCK_MUTEX, 0 },
     138    { "Wslsem", STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE, 0 },
    138139    { "Wsysev", STATES_WAITING_FOR_SYSTEM_EVENT, 0 },
    139140    { "Wterm",  STATES_WAITING_FOR_TERMINATION, 0 },
  • cpukit/score/Makefile.am

    r214d8ed r7237b3e  
    350350libscore_a_SOURCES += src/once.c
    351351libscore_a_SOURCES += src/resourceiterate.c
     352libscore_a_SOURCES += src/semaphore.c
    352353libscore_a_SOURCES += src/smpbarrierwait.c
    353354libscore_a_SOURCES += src/kern_tc.c
  • cpukit/score/include/rtems/score/statesimpl.h

    r214d8ed r7237b3e  
    8989/** This macro corresponds to a task waiting for a <sys/lock.h> mutex. */
    9090#define STATES_WAITING_FOR_SYS_LOCK_MUTEX      0x2000000
     91/** This macro corresponds to a task waiting for a <sys/lock.h> semaphore. */
     92#define STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE  0x4000000
    9193
    9294/** This macro corresponds to a task which is in an interruptible
     
    107109                                 STATES_WAITING_FOR_BSD_WAKEUP         | \
    108110                                 STATES_WAITING_FOR_SYS_LOCK_MUTEX     | \
     111                                 STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE | \
    109112                                 STATES_WAITING_FOR_RWLOCK             )
    110113
  • testsuites/sptests/spsyslock01/init.c

    r214d8ed r7237b3e  
    4141#define EVENT_REC_MTX_PRIO_INV RTEMS_EVENT_6
    4242
     43#define EVENT_SEM_WAIT RTEMS_EVENT_7
     44
    4345typedef struct {
    4446  rtems_id high[2];
     
    4749  struct _Mutex_Control mtx;
    4850  struct _Mutex_recursive_Control rec_mtx;
     51  struct _Semaphore_Control sem;
    4952  int generation[2];
    5053  int current_generation[2];
     
    8487  struct _Mutex_Control mtx = _MUTEX_INITIALIZER;
    8588  struct _Mutex_recursive_Control rec_mtx = _MUTEX_RECURSIVE_INITIALIZER;
     89  struct _Semaphore_Control sem = _SEMAPHORE_INITIALIZER(1);
    8690
    8791  _Mutex_Initialize(&ctx->mtx);
    8892  _Mutex_recursive_Initialize(&ctx->rec_mtx);
     93  _Semaphore_Initialize(&ctx->sem, 1);
    8994
    9095  rtems_test_assert(memcmp(&mtx, &ctx->mtx, sizeof(mtx)) == 0);
    9196  rtems_test_assert(memcmp(&rec_mtx, &ctx->rec_mtx, sizeof(rec_mtx)) == 0);
     97  rtems_test_assert(memcmp(&sem, &ctx->sem, sizeof(sem)) == 0);
    9298
    9399  _Mutex_Destroy(&mtx);
    94100  _Mutex_recursive_Destroy(&rec_mtx);
     101  _Semaphore_Destroy(&sem);
    95102}
    96103
     
    270277}
    271278
     279static void test_sem(test_context *ctx)
     280{
     281  struct _Semaphore_Control *sem = &ctx->sem;
     282  size_t idx = 0;
     283  int gen;
     284
     285  _Semaphore_Wait(sem);
     286  gen = ctx->generation[idx];
     287  send_event(ctx, idx, EVENT_SEM_WAIT);
     288  rtems_test_assert(ctx->generation[idx] == gen);
     289  _Semaphore_Post(sem);
     290  rtems_test_assert(ctx->generation[idx] == gen + 1);
     291  _Semaphore_Post(sem);
     292}
     293
     294static void test_sem_prio_wait_order(test_context *ctx)
     295{
     296  struct _Semaphore_Control *sem = &ctx->sem;
     297  size_t a = 0;
     298  size_t b = 1;
     299  int gen_a;
     300  int gen_b;
     301
     302  _Semaphore_Wait(sem);
     303
     304  gen_a = ctx->generation[a];
     305  gen_b = ctx->generation[b];
     306
     307  send_event(ctx, b, EVENT_SEM_WAIT);
     308  send_event(ctx, a, EVENT_SEM_WAIT);
     309
     310  rtems_test_assert(ctx->generation[a] == gen_a);
     311  rtems_test_assert(ctx->generation[b] == gen_b);
     312
     313  _Semaphore_Post(sem);
     314
     315  rtems_test_assert(ctx->generation[a] == gen_a + 1);
     316  rtems_test_assert(ctx->generation[b] == gen_b);
     317
     318  _Semaphore_Post(sem);
     319
     320  rtems_test_assert(ctx->generation[a] == gen_a + 1);
     321  rtems_test_assert(ctx->generation[b] == gen_b + 1);
     322}
     323
    272324static void mid_task(rtems_task_argument arg)
    273325{
     
    345397      sc = rtems_task_suspend(ctx->mid);
    346398      rtems_test_assert(sc == RTEMS_SUCCESSFUL);
     399    }
     400
     401    if ((events & EVENT_SEM_WAIT) != 0) {
     402      _Semaphore_Wait(&ctx->sem);
     403      ctx->generation[idx] = generation(ctx, idx);
    347404    }
    348405  }
     
    401458  test_mtx_timeout_normal(ctx);
    402459  test_mtx_timeout_recursive(ctx);
     460  test_sem(ctx);
     461  test_sem_prio_wait_order(ctx);
    403462
    404463  send_event(ctx, 0, EVENT_MTX_DEADLOCK);
     
    406465  _Mutex_Destroy(&ctx->mtx);
    407466  _Mutex_recursive_Destroy(&ctx->rec_mtx);
     467  _Semaphore_Destroy(&ctx->sem);
    408468}
    409469
Note: See TracChangeset for help on using the changeset viewer.