Changeset 9e9e61d in rtems


Ignore:
Timestamp:
Jul 28, 2015, 11:46:56 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
d0733bb
Parents:
a1b4af4b
git-author:
Sebastian Huber <sebastian.huber@…> (07/28/15 11:46:56)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/30/15 07:11:18)
Message:

score: Add self-contained condition implementation

Files:
1 added
5 edited

Legend:

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

    ra1b4af4b r9e9e61d  
    135135    { "Wsem",   STATES_WAITING_FOR_SEMAPHORE, 0 },
    136136    { "Wsig",   STATES_WAITING_FOR_SIGNAL, 0 },
     137    { "Wslcnd", STATES_WAITING_FOR_SYS_LOCK_CONDITION, 0 },
    137138    { "Wslftx", STATES_WAITING_FOR_SYS_LOCK_FUTEX, 0 },
    138139    { "Wslmtx", STATES_WAITING_FOR_SYS_LOCK_MUTEX, 0 },
  • cpukit/score/Makefile.am

    ra1b4af4b r9e9e61d  
    345345    src/interr.c src/isr.c src/wkspace.c src/wkstringduplicate.c
    346346libscore_a_SOURCES += src/isrisinprogress.c
     347libscore_a_SOURCES += src/condition.c
    347348libscore_a_SOURCES += src/debugisownerofallocator.c
    348349libscore_a_SOURCES += src/futex.c
  • cpukit/score/include/rtems/score/statesimpl.h

    ra1b4af4b r9e9e61d  
    9898 */
    9999#define STATES_INTERRUPTIBLE_BY_SIGNAL         0x10000000
     100/** This macro corresponds to a task waiting for a <sys/lock.h> condition. */
     101#define STATES_WAITING_FOR_SYS_LOCK_CONDITION  0x20000000
    100102
    101103/** This macro corresponds to a task waiting for a local object operation. */
     
    113115                                 STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE | \
    114116                                 STATES_WAITING_FOR_SYS_LOCK_FUTEX     | \
     117                                 STATES_WAITING_FOR_SYS_LOCK_CONDITION | \
    115118                                 STATES_WAITING_FOR_RWLOCK             )
    116119
  • testsuites/sptests/spsyslock01/init.c

    ra1b4af4b r9e9e61d  
    4747#define EVENT_FUTEX_WAIT RTEMS_EVENT_8
    4848
     49#define EVENT_CONDITION_WAIT RTEMS_EVENT_9
     50
     51#define EVENT_CONDITION_WAIT_REC RTEMS_EVENT_10
     52
    4953typedef struct {
    5054  rtems_id high[2];
     
    5357  struct _Mutex_Control mtx;
    5458  struct _Mutex_recursive_Control rec_mtx;
     59  struct _Condition_Control cond;
    5560  struct _Semaphore_Control sem;
    5661  struct _Futex_Control futex;
     
    9499  struct _Mutex_Control mtx = _MUTEX_INITIALIZER;
    95100  struct _Mutex_recursive_Control rec_mtx = _MUTEX_RECURSIVE_INITIALIZER;
     101  struct _Condition_Control cond = _CONDITION_INITIALIZER;
    96102  struct _Semaphore_Control sem = _SEMAPHORE_INITIALIZER(1);
    97103  struct _Futex_Control futex = _FUTEX_INITIALIZER;
     
    99105  _Mutex_Initialize(&ctx->mtx);
    100106  _Mutex_recursive_Initialize(&ctx->rec_mtx);
     107  _Condition_Initialize(&ctx->cond);
    101108  _Semaphore_Initialize(&ctx->sem, 1);
    102109  _Futex_Initialize(&ctx->futex);
     
    104111  rtems_test_assert(memcmp(&mtx, &ctx->mtx, sizeof(mtx)) == 0);
    105112  rtems_test_assert(memcmp(&rec_mtx, &ctx->rec_mtx, sizeof(rec_mtx)) == 0);
     113  rtems_test_assert(memcmp(&cond, &ctx->cond, sizeof(cond)) == 0);
    106114  rtems_test_assert(memcmp(&sem, &ctx->sem, sizeof(sem)) == 0);
    107115  rtems_test_assert(memcmp(&futex, &ctx->futex, sizeof(futex)) == 0);
     
    109117  _Mutex_Destroy(&mtx);
    110118  _Mutex_recursive_Destroy(&rec_mtx);
     119  _Condition_Destroy(&cond);
    111120  _Semaphore_Destroy(&sem);
    112121  _Futex_Destroy(&futex);
     
    286295
    287296  send_event(ctx, idx, EVENT_REC_MTX_RELEASE);
     297}
     298
     299static void test_condition(test_context *ctx)
     300{
     301  struct _Condition_Control *cond = &ctx->cond;
     302  size_t a = 0;
     303  size_t b = 1;
     304  int gen_a;
     305  int gen_b;
     306
     307  gen_a = ctx->generation[a];
     308  gen_b = ctx->generation[b];
     309
     310  _Condition_Signal(cond);
     311  _Condition_Broadcast(cond);
     312
     313  send_event(ctx, a, EVENT_CONDITION_WAIT);
     314  send_event(ctx, b, EVENT_CONDITION_WAIT_REC);
     315
     316  rtems_test_assert(ctx->generation[a] == gen_a + 1);
     317  rtems_test_assert(ctx->generation[b] == gen_b + 1);
     318
     319  _Condition_Signal(cond);
     320
     321  rtems_test_assert(ctx->generation[a] == gen_a + 2);
     322  rtems_test_assert(ctx->generation[b] == gen_b + 1);
     323
     324  _Condition_Signal(cond);
     325
     326  rtems_test_assert(ctx->generation[a] == gen_a + 2);
     327  rtems_test_assert(ctx->generation[b] == gen_b + 2);
     328
     329  send_event(ctx, a, EVENT_CONDITION_WAIT);
     330  send_event(ctx, b, EVENT_CONDITION_WAIT_REC);
     331
     332  rtems_test_assert(ctx->generation[a] == gen_a + 3);
     333  rtems_test_assert(ctx->generation[b] == gen_b + 3);
     334
     335  _Condition_Broadcast(cond);
     336
     337  rtems_test_assert(ctx->generation[a] == gen_a + 4);
     338  rtems_test_assert(ctx->generation[b] == gen_b + 4);
     339}
     340
     341static void test_condition_timeout(test_context *ctx)
     342{
     343  struct timespec to;
     344  int eno;
     345
     346  _Mutex_Acquire(&ctx->mtx);
     347  memset(&to, 0x00, sizeof(to));
     348  eno = _Condition_Wait_timed(&ctx->cond, &ctx->mtx, &to);
     349  rtems_test_assert(eno == ETIMEDOUT);
     350  memset(&to, 0xff, sizeof(to));
     351  eno = _Condition_Wait_timed(&ctx->cond, &ctx->mtx, &to);
     352  rtems_test_assert(eno == EINVAL);
     353  get_abs_timeout(&to);
     354  eno = _Condition_Wait_timed(&ctx->cond, &ctx->mtx, &to);
     355  rtems_test_assert(eno == ETIMEDOUT);
     356  _Mutex_Release(&ctx->mtx);
     357
     358  _Mutex_recursive_Acquire(&ctx->rec_mtx);
     359  _Mutex_recursive_Acquire(&ctx->rec_mtx);
     360  memset(&to, 0x00, sizeof(to));
     361  eno = _Condition_Wait_recursive_timed(&ctx->cond, &ctx->rec_mtx, &to);
     362  rtems_test_assert(eno == ETIMEDOUT);
     363  memset(&to, 0xff, sizeof(to));
     364  eno = _Condition_Wait_recursive_timed(&ctx->cond, &ctx->rec_mtx, &to);
     365  rtems_test_assert(eno == EINVAL);
     366  get_abs_timeout(&to);
     367  eno = _Condition_Wait_recursive_timed(&ctx->cond, &ctx->rec_mtx, &to);
     368  rtems_test_assert(eno == ETIMEDOUT);
     369  _Mutex_recursive_Release(&ctx->rec_mtx);
     370  _Mutex_recursive_Release(&ctx->rec_mtx);
    288371}
    289372
     
    489572      ctx->eno[idx] = _Futex_Wait(&ctx->futex, &ctx->val, 1);
    490573    }
     574
     575    if ((events & EVENT_CONDITION_WAIT) != 0) {
     576      _Mutex_Acquire(&ctx->mtx);
     577      ctx->generation[idx] = generation(ctx, idx);
     578      _Condition_Wait(&ctx->cond, &ctx->mtx);
     579      ctx->generation[idx] = generation(ctx, idx);
     580      _Mutex_Release(&ctx->mtx);
     581    }
     582
     583    if ((events & EVENT_CONDITION_WAIT_REC) != 0) {
     584      _Mutex_recursive_Acquire(&ctx->rec_mtx);
     585      _Mutex_recursive_Acquire(&ctx->rec_mtx);
     586      ctx->generation[idx] = generation(ctx, idx);
     587      _Condition_Wait_recursive(&ctx->cond, &ctx->rec_mtx);
     588      ctx->generation[idx] = generation(ctx, idx);
     589      _Mutex_recursive_Release(&ctx->rec_mtx);
     590      _Mutex_recursive_Release(&ctx->rec_mtx);
     591    }
    491592  }
    492593}
     
    544645  test_mtx_timeout_normal(ctx);
    545646  test_mtx_timeout_recursive(ctx);
     647  test_condition(ctx);
     648  test_condition_timeout(ctx);
    546649  test_sem(ctx);
    547650  test_sem_prio_wait_order(ctx);
     
    553656  _Mutex_Destroy(&ctx->mtx);
    554657  _Mutex_recursive_Destroy(&ctx->rec_mtx);
     658  _Condition_Destroy(&ctx->cond);
    555659  _Semaphore_Destroy(&ctx->sem);
    556660  _Futex_Destroy(&ctx->futex);
Note: See TracChangeset for help on using the changeset viewer.