Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/fibril_synch.h

    rf787c8e r2965d18  
    4141#include <sys/time.h>
    4242#include <stdbool.h>
     43#include <futex.h>
     44
     45/**
     46 * "Restricted" fibril mutex.
     47 *
     48 * Similar to `fibril_mutex_t`, but has a set of restrictions placed on its
     49 * use. Within a rmutex critical section, you
     50 *         - may not use any other synchronization primitive,
     51 *           save for another `fibril_rmutex_t`. This includes nonblocking
     52 *           operations like cvar signal and mutex unlock.
     53 *         - may not read IPC messages
     54 *         - may not start a new thread/fibril
     55 *           (creating fibril without starting is fine)
     56 *
     57 * Additionally, locking with a timeout is not possible on this mutex,
     58 * and there is no associated condition variable type.
     59 * This is a design constraint, not a lack of implementation effort.
     60 */
     61typedef struct {
     62        // TODO: At this point, this is just silly handwaving to hide current
     63        //       futex use behind a fibril based abstraction. Later, the imple-
     64        //       mentation will change, but the restrictions placed on this type
     65        //       will allow it to be simpler and faster than a regular mutex.
     66        //       There might also be optional debug checking of the assumptions.
     67        //
     68        //       Note that a consequence of the restrictions is that if we are
     69        //       running on a single thread, no other fibril can ever get to run
     70        //       while a fibril has a rmutex locked. That means that for
     71        //       single-threaded programs, we can reduce all rmutex locks and
     72        //       unlocks to simple branches on a global bool variable.
     73
     74        futex_t futex;
     75} fibril_rmutex_t;
     76
     77#define FIBRIL_RMUTEX_INITIALIZER(name) \
     78        { .futex = FUTEX_INITIALIZE(1) }
     79
     80#define FIBRIL_RMUTEX_INITIALIZE(name) \
     81        fibril_rmutex_t name = FIBRIL_RMUTEX_INITIALIZER(name)
    4382
    4483typedef struct {
     
    147186        long int count;
    148187        list_t waiters;
    149         bool closed;
    150188} fibril_semaphore_t;
    151189
     
    163201#define FIBRIL_SEMAPHORE_INITIALIZE(name, cnt) \
    164202        fibril_semaphore_t name = FIBRIL_SEMAPHORE_INITIALIZER(name, cnt)
     203
     204extern void fibril_rmutex_initialize(fibril_rmutex_t *);
     205extern void fibril_rmutex_lock(fibril_rmutex_t *);
     206extern bool fibril_rmutex_trylock(fibril_rmutex_t *);
     207extern void fibril_rmutex_unlock(fibril_rmutex_t *);
    165208
    166209extern void fibril_mutex_initialize(fibril_mutex_t *);
     
    198241extern void fibril_semaphore_up(fibril_semaphore_t *);
    199242extern void fibril_semaphore_down(fibril_semaphore_t *);
    200 extern errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *, suseconds_t);
    201 extern void fibril_semaphore_close(fibril_semaphore_t *);
    202 
    203 typedef struct mpsc mpsc_t;
    204 extern mpsc_t *mpsc_create(size_t);
    205 extern void mpsc_destroy(mpsc_t *);
    206 extern errno_t mpsc_send(mpsc_t *, const void *);
    207 extern errno_t mpsc_receive(mpsc_t *, void *, const struct timeval *);
    208 extern void mpsc_close(mpsc_t *);
    209243
    210244#endif
Note: See TracChangeset for help on using the changeset viewer.