source: mainline/uspace/lib/c/include/fibril_synch.h@ c5b59ce

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c5b59ce was 63f8966, checked in by Martin Decky <martin@…>, 15 years ago

rename library directories (the common "lib" prefix is already in the upper directory)

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/*
2 * Copyright (c) 2009 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#ifndef LIBC_FIBRIL_SYNCH_H_
36#define LIBC_FIBRIL_SYNCH_H_
37
38#include <async.h>
39#include <fibril.h>
40#include <adt/list.h>
41#include <libarch/tls.h>
42#include <sys/time.h>
43
44typedef struct {
45 int counter;
46 link_t waiters;
47} fibril_mutex_t;
48
49#define FIBRIL_MUTEX_INITIALIZE(name) \
50 fibril_mutex_t name = { \
51 .counter = 1, \
52 .waiters = { \
53 .prev = &name.waiters, \
54 .next = &name.waiters, \
55 } \
56 }
57
58typedef struct {
59 unsigned writers;
60 unsigned readers;
61 link_t waiters;
62} fibril_rwlock_t;
63
64#define FIBRIL_RWLOCK_INITIALIZE(name) \
65 fibril_rwlock_t name = { \
66 .readers = 0, \
67 .writers = 0, \
68 .waiters = { \
69 .prev = &name.waiters, \
70 .next = &name.waiters, \
71 } \
72 }
73
74typedef struct {
75 link_t waiters;
76} fibril_condvar_t;
77
78#define FIBRIL_CONDVAR_INITIALIZE(name) \
79 fibril_condvar_t name = { \
80 .waiters = { \
81 .next = &name.waiters, \
82 .prev = &name.waiters, \
83 } \
84 }
85
86extern void fibril_mutex_initialize(fibril_mutex_t *);
87extern void fibril_mutex_lock(fibril_mutex_t *);
88extern bool fibril_mutex_trylock(fibril_mutex_t *);
89extern void fibril_mutex_unlock(fibril_mutex_t *);
90
91extern void fibril_rwlock_initialize(fibril_rwlock_t *);
92extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
93extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
94extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
95extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
96
97extern void fibril_condvar_initialize(fibril_condvar_t *);
98extern int fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
99 suseconds_t);
100extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
101extern void fibril_condvar_signal(fibril_condvar_t *);
102extern void fibril_condvar_broadcast(fibril_condvar_t *);
103
104#endif
105
106/** @}
107 */
Note: See TracBrowser for help on using the repository browser.