Changeset 40188718 in rtems


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

score: Add self-contained futex implementation

Files:
1 added
5 edited

Legend:

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

    r7237b3e r40188718  
    135135    { "Wsem",   STATES_WAITING_FOR_SEMAPHORE, 0 },
    136136    { "Wsig",   STATES_WAITING_FOR_SIGNAL, 0 },
     137    { "Wslftx", STATES_WAITING_FOR_SYS_LOCK_FUTEX, 0 },
    137138    { "Wslmtx", STATES_WAITING_FOR_SYS_LOCK_MUTEX, 0 },
    138139    { "Wslsem", STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE, 0 },
  • cpukit/score/Makefile.am

    r7237b3e r40188718  
    346346libscore_a_SOURCES += src/isrisinprogress.c
    347347libscore_a_SOURCES += src/debugisownerofallocator.c
     348libscore_a_SOURCES += src/futex.c
    348349libscore_a_SOURCES += src/profilingisrentryexit.c
    349350libscore_a_SOURCES += src/mutex.c
  • cpukit/score/include/rtems/score/statesimpl.h

    r7237b3e r40188718  
    9191/** This macro corresponds to a task waiting for a <sys/lock.h> semaphore. */
    9292#define STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE  0x4000000
     93/** This macro corresponds to a task waiting for a <sys/lock.h> futex. */
     94#define STATES_WAITING_FOR_SYS_LOCK_FUTEX      0x8000000
    9395
    9496/** This macro corresponds to a task which is in an interruptible
     
    110112                                 STATES_WAITING_FOR_SYS_LOCK_MUTEX     | \
    111113                                 STATES_WAITING_FOR_SYS_LOCK_SEMAPHORE | \
     114                                 STATES_WAITING_FOR_SYS_LOCK_FUTEX     | \
    112115                                 STATES_WAITING_FOR_RWLOCK             )
    113116
  • testsuites/sptests/spsyslock01/init.c

    r7237b3e r40188718  
    2020
    2121#include <sys/lock.h>
     22#include <errno.h>
     23#include <limits.h>
    2224#include <string.h>
    2325#include <time.h>
     
    4244
    4345#define EVENT_SEM_WAIT RTEMS_EVENT_7
     46
     47#define EVENT_FUTEX_WAIT RTEMS_EVENT_8
    4448
    4549typedef struct {
     
    5054  struct _Mutex_recursive_Control rec_mtx;
    5155  struct _Semaphore_Control sem;
     56  struct _Futex_Control futex;
     57  int val;
     58  int eno[2];
    5259  int generation[2];
    5360  int current_generation[2];
     
    8895  struct _Mutex_recursive_Control rec_mtx = _MUTEX_RECURSIVE_INITIALIZER;
    8996  struct _Semaphore_Control sem = _SEMAPHORE_INITIALIZER(1);
     97  struct _Futex_Control futex = _FUTEX_INITIALIZER;
    9098
    9199  _Mutex_Initialize(&ctx->mtx);
    92100  _Mutex_recursive_Initialize(&ctx->rec_mtx);
    93101  _Semaphore_Initialize(&ctx->sem, 1);
     102  _Futex_Initialize(&ctx->futex);
    94103
    95104  rtems_test_assert(memcmp(&mtx, &ctx->mtx, sizeof(mtx)) == 0);
    96105  rtems_test_assert(memcmp(&rec_mtx, &ctx->rec_mtx, sizeof(rec_mtx)) == 0);
    97106  rtems_test_assert(memcmp(&sem, &ctx->sem, sizeof(sem)) == 0);
     107  rtems_test_assert(memcmp(&futex, &ctx->futex, sizeof(futex)) == 0);
    98108
    99109  _Mutex_Destroy(&mtx);
    100110  _Mutex_recursive_Destroy(&rec_mtx);
    101111  _Semaphore_Destroy(&sem);
     112  _Futex_Destroy(&futex);
    102113}
    103114
     
    322333}
    323334
     335static void test_futex(test_context *ctx)
     336{
     337  struct _Futex_Control *futex = &ctx->futex;
     338  size_t a = 0;
     339  size_t b = 1;
     340  int eno;
     341  int woken;
     342
     343  eno = _Futex_Wait(futex, &ctx->val, 1);
     344  rtems_test_assert(eno == EWOULDBLOCK);
     345
     346  woken = _Futex_Wake(futex, 0);
     347  rtems_test_assert(woken == 0);
     348
     349  woken = _Futex_Wake(futex, 1);
     350  rtems_test_assert(woken == 0);
     351
     352  ctx->val = 1;
     353
     354  ctx->eno[a] = -1;
     355  send_event(ctx, a, EVENT_FUTEX_WAIT);
     356  rtems_test_assert(ctx->eno[a] == -1);
     357
     358  woken = _Futex_Wake(futex, INT_MAX);
     359  rtems_test_assert(woken == 1);
     360  rtems_test_assert(ctx->eno[a] == 0);
     361
     362  ctx->eno[a] = -1;
     363  ctx->eno[b] = -1;
     364  send_event(ctx, a, EVENT_FUTEX_WAIT);
     365  send_event(ctx, b, EVENT_FUTEX_WAIT);
     366  rtems_test_assert(ctx->eno[a] == -1);
     367  rtems_test_assert(ctx->eno[b] == -1);
     368
     369  woken = _Futex_Wake(futex, 1);
     370  rtems_test_assert(woken == 1);
     371  rtems_test_assert(ctx->eno[a] == 0);
     372  rtems_test_assert(ctx->eno[b] == -1);
     373
     374  woken = _Futex_Wake(futex, 1);
     375  rtems_test_assert(woken == 1);
     376  rtems_test_assert(ctx->eno[a] == 0);
     377  rtems_test_assert(ctx->eno[b] == 0);
     378
     379  ctx->eno[a] = -1;
     380  ctx->eno[b] = -1;
     381  send_event(ctx, a, EVENT_FUTEX_WAIT);
     382  send_event(ctx, b, EVENT_FUTEX_WAIT);
     383  rtems_test_assert(ctx->eno[a] == -1);
     384  rtems_test_assert(ctx->eno[b] == -1);
     385
     386  woken = _Futex_Wake(futex, 2);
     387  rtems_test_assert(woken == 2);
     388  rtems_test_assert(ctx->eno[a] == 0);
     389  rtems_test_assert(ctx->eno[b] == 0);
     390}
     391
    324392static void mid_task(rtems_task_argument arg)
    325393{
     
    402470      _Semaphore_Wait(&ctx->sem);
    403471      ctx->generation[idx] = generation(ctx, idx);
     472    }
     473
     474    if ((events & EVENT_FUTEX_WAIT) != 0) {
     475      ctx->eno[idx] = _Futex_Wait(&ctx->futex, &ctx->val, 1);
    404476    }
    405477  }
     
    460532  test_sem(ctx);
    461533  test_sem_prio_wait_order(ctx);
     534  test_futex(ctx);
    462535
    463536  send_event(ctx, 0, EVENT_MTX_DEADLOCK);
     
    466539  _Mutex_recursive_Destroy(&ctx->rec_mtx);
    467540  _Semaphore_Destroy(&ctx->sem);
     541  _Futex_Destroy(&ctx->futex);
    468542}
    469543
Note: See TracChangeset for help on using the changeset viewer.