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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b14b71e was e9460aa, checked in by Jakub Jermar <jakub@…>, 15 years ago

Need a more flexible way to initialize fibril synchronization primitives.

  • Property mode set to 100644
File size: 3.4 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_INITIALIZER(name) \
50 { \
51 .counter = 1, \
52 .waiters = { \
53 .prev = &name.waiters, \
54 .next = &name.waiters, \
55 } \
56 }
57
58#define FIBRIL_MUTEX_INITIALIZE(name) \
59 fibril_mutex_t name = FIBRIL_MUTEX_INITIALIZER(name)
60
61typedef struct {
62 unsigned writers;
63 unsigned readers;
64 link_t waiters;
65} fibril_rwlock_t;
66
67#define FIBRIL_RWLOCK_INITIALIZER(name) \
68 { \
69 .readers = 0, \
70 .writers = 0, \
71 .waiters = { \
72 .prev = &name.waiters, \
73 .next = &name.waiters, \
74 } \
75 }
76
77#define FIBRIL_RWLOCK_INITIALIZE(name) \
78 fibril_rwlock_t name = FIBRIL_RWLOCK_INITIALIZER(name)
79
80typedef struct {
81 link_t waiters;
82} fibril_condvar_t;
83
84#define FIBRIL_CONDVAR_INITIALIZER(name) \
85 { \
86 .waiters = { \
87 .next = &name.waiters, \
88 .prev = &name.waiters, \
89 } \
90 }
91
92#define FIBRIL_CONDVAR_INITIALIZE(name) \
93 fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
94
95extern void fibril_mutex_initialize(fibril_mutex_t *);
96extern void fibril_mutex_lock(fibril_mutex_t *);
97extern bool fibril_mutex_trylock(fibril_mutex_t *);
98extern void fibril_mutex_unlock(fibril_mutex_t *);
99
100extern void fibril_rwlock_initialize(fibril_rwlock_t *);
101extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
102extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
103extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
104extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
105
106extern void fibril_condvar_initialize(fibril_condvar_t *);
107extern int fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
108 suseconds_t);
109extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
110extern void fibril_condvar_signal(fibril_condvar_t *);
111extern void fibril_condvar_broadcast(fibril_condvar_t *);
112
113#endif
114
115/** @}
116 */
Note: See TracBrowser for help on using the repository browser.