uts: make emu10k non-verbose
[unleashed.git] / include / sys / rwstlock.h
blobc491aef82a0b86b267afe39d704e7146d46b1499
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _SYS_RWSTLOCK_H
28 #define _SYS_RWSTLOCK_H
31 * Alternate rwlock that is interruptible and can be released by a thread
32 * other than the one that acquired the lock.
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 #include <sys/types.h>
40 #include <sys/ksynch.h>
41 #include <sys/rwlock.h>
43 typedef struct rwstlock {
44 intptr_t rwst_count;
45 kcondvar_t rwst_rcv;
46 kcondvar_t rwst_wcv;
47 kmutex_t rwst_lock;
48 } rwstlock_t;
51 * The interfaces below are private to Sun Microsystems,
52 * and these might change without notice.
55 #define RWST_TRYENTER 0x01
56 #define RWST_SIG 0x02
58 #define RWST_HELD(l) ((l)->rwst_count != 0)
59 #define RWST_READ_HELD(l) ((l)->rwst_count > 0)
60 #define RWST_WRITE_HELD(l) ((l)->rwst_count < 0)
61 #define RWST_WRITE_OWNER(l) \
62 ((l)->rwst_count == (LONG_MIN | (intptr_t)curthread))
63 #define RWST_OWNER(l) (RWST_WRITE_HELD(l) ? \
64 ((struct _kthread *)((l)->rwst_count & ~LONG_MIN)) : NULL)
65 #define RWST_READ_WANTED(l) CV_HAS_WAITERS(&(l)->rwst_rcv)
66 #define RWST_WRITE_WANTED(l) CV_HAS_WAITERS(&(l)->rwst_wcv)
67 #define RWST_WAIT(cv, lock, f) \
68 ((f) & RWST_SIG ? cv_wait_sig(cv, lock) : (cv_wait(cv, lock), 1))
69 #define RWST_READ_WAIT(l, f) RWST_WAIT(&(l)->rwst_rcv, &(l)->rwst_lock, f)
70 #define RWST_WRITE_WAIT(l, f) RWST_WAIT(&(l)->rwst_wcv, &(l)->rwst_lock, f)
71 #define RWST_READ_WAKE_ALL(l) cv_broadcast(&(l)->rwst_rcv)
72 #define RWST_WRITE_WAKE_ONE(l) cv_signal(&(l)->rwst_wcv)
73 #define RWST_READ_ENTER(l) (l)->rwst_count++
74 #define RWST_WRITE_ENTER(l) (l)->rwst_count = LONG_MIN | (intptr_t)curthread
75 #define RWST_READ_EXIT(l) (l)->rwst_count--
76 #define RWST_WRITE_EXIT(l) (l)->rwst_count = 0
78 extern void rwst_enter(rwstlock_t *, krw_t);
79 extern int rwst_enter_sig(rwstlock_t *, krw_t);
80 extern void rwst_exit(rwstlock_t *);
81 extern void rwst_init(rwstlock_t *, char *, krw_type_t, void *);
82 extern void rwst_destroy(rwstlock_t *);
83 extern int rwst_lock_held(rwstlock_t *, krw_t);
84 extern int rwst_tryenter(rwstlock_t *, krw_t);
85 extern struct _kthread *rwst_owner(rwstlock_t *);
87 #ifdef __cplusplus
89 #endif
91 #endif /* _SYS_RWSTLOCK_H */