2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: rwlock.h,v 1.18.2.3.2.1 2004/03/06 08:14:47 marka Exp $ */
21 #define ISC_RWLOCK_H 1
23 #include <isc/condition.h>
25 #include <isc/platform.h>
26 #include <isc/types.h>
31 isc_rwlocktype_none = 0,
36 #ifdef ISC_PLATFORM_USETHREADS
42 isc_condition_t readable;
43 isc_condition_t writeable;
44 isc_rwlocktype_t type;
46 /* The number of threads that have the lock. */
50 * The number of lock grants made since the lock was last switched
51 * from reading to writing or vice versa; used in determining
52 * when the quota is reached and it is time to switch.
56 unsigned int readers_waiting;
57 unsigned int writers_waiting;
58 unsigned int read_quota;
59 unsigned int write_quota;
60 isc_rwlocktype_t original;
62 #else /* ISC_PLATFORM_USETHREADS */
65 isc_rwlocktype_t type;
68 #endif /* ISC_PLATFORM_USETHREADS */
72 isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota,
73 unsigned int write_quota);
76 isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type);
79 isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type);
82 isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type);
85 isc_rwlock_tryupgrade(isc_rwlock_t *rwl);
88 isc_rwlock_downgrade(isc_rwlock_t *rwl);
91 isc_rwlock_destroy(isc_rwlock_t *rwl);
95 #endif /* ISC_RWLOCK_H */