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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 12f9f0d0 was b72efe8, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Separate list_t typedef from link_t (user-space part).

  • list_t represents lists
  • Use list_first(), list_last(), list_empty() where appropriate
  • Use list_foreach() where possible
  • assert_link_not_used()
  • usb_hid_report_path_free() shall not unlink the path, caller must do it
  • Property mode set to 100644
File size: 3.9 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 <fibril.h>
39#include <adt/list.h>
40#include <libarch/tls.h>
41#include <sys/time.h>
42#include <bool.h>
43
44typedef struct {
45 fibril_owner_info_t oi; /**< Keep this the first thing. */
46 int counter;
47 list_t waiters;
48} fibril_mutex_t;
49
50#define FIBRIL_MUTEX_INITIALIZER(name) \
51 { \
52 .oi = { \
53 .owned_by = NULL \
54 }, \
55 .counter = 1, \
56 .waiters = { \
57 .head = { \
58 .prev = &(name).waiters.head, \
59 .next = &(name).waiters.head, \
60 } \
61 } \
62 }
63
64#define FIBRIL_MUTEX_INITIALIZE(name) \
65 fibril_mutex_t name = FIBRIL_MUTEX_INITIALIZER(name)
66
67typedef struct {
68 fibril_owner_info_t oi; /**< Keep this the first thing. */
69 unsigned writers;
70 unsigned readers;
71 list_t waiters;
72} fibril_rwlock_t;
73
74#define FIBRIL_RWLOCK_INITIALIZER(name) \
75 { \
76 .oi = { \
77 .owned_by = NULL \
78 }, \
79 .readers = 0, \
80 .writers = 0, \
81 .waiters = { \
82 .head = { \
83 .prev = &(name).waiters.head, \
84 .next = &(name).waiters.head, \
85 } \
86 } \
87 }
88
89#define FIBRIL_RWLOCK_INITIALIZE(name) \
90 fibril_rwlock_t name = FIBRIL_RWLOCK_INITIALIZER(name)
91
92typedef struct {
93 list_t waiters;
94} fibril_condvar_t;
95
96#define FIBRIL_CONDVAR_INITIALIZER(name) \
97 { \
98 .waiters = { \
99 .head = { \
100 .next = &(name).waiters.head, \
101 .prev = &(name).waiters.head, \
102 } \
103 } \
104 }
105
106#define FIBRIL_CONDVAR_INITIALIZE(name) \
107 fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name)
108
109extern void fibril_mutex_initialize(fibril_mutex_t *);
110extern void fibril_mutex_lock(fibril_mutex_t *);
111extern bool fibril_mutex_trylock(fibril_mutex_t *);
112extern void fibril_mutex_unlock(fibril_mutex_t *);
113extern bool fibril_mutex_is_locked(fibril_mutex_t *);
114
115extern void fibril_rwlock_initialize(fibril_rwlock_t *);
116extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
117extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
118extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
119extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
120extern bool fibril_rwlock_is_read_locked(fibril_rwlock_t *);
121extern bool fibril_rwlock_is_write_locked(fibril_rwlock_t *);
122extern bool fibril_rwlock_is_locked(fibril_rwlock_t *);
123
124extern void fibril_condvar_initialize(fibril_condvar_t *);
125extern int fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
126 suseconds_t);
127extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
128extern void fibril_condvar_signal(fibril_condvar_t *);
129extern void fibril_condvar_broadcast(fibril_condvar_t *);
130
131#endif
132
133/** @}
134 */
Note: See TracBrowser for help on using the repository browser.