acl  3.5.3.0
acl_pthread_rwlock.h
浏览该文件的文档.
1 /*
2 Copyright (C) 1999, 2000 Igor Khasilev, igor@paco.net
3 Copyright (C) 2000 Andrey Igoshin, ai@vsu.ru
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 
21 /*-
22  * Copyright (c) 1998 Alex Nash
23  * All rights reserved.
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
35  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
38  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44  * SUCH DAMAGE.
45  */
46 
47 #ifndef ACL_PTHREAD_RWLOCK_H
48 #define ACL_PTHREAD_RWLOCK_H
49 
50 #include "../stdlib/acl_define.h"
51 #include "../thread/acl_pthread.h"
52 #if defined(_WIN32) || defined(_WIN64)
53 # define ACL_HAVE_NO_RWLOCK
54 #endif
55 
56 #ifdef ACL_HAVE_NO_RWLOCK
57 
58 #if !defined(ACL_PTHREAD_PROCESS_PRIVATE)
59 #define ACL_PTHREAD_PROCESS_PRIVATE 0
60 #endif
61 #if !defined(ACL_PTHREAD_PROCESS_SHARED)
62 #define ACL_PTHREAD_PROCESS_SHARED 1
63 #endif
64 
65 #if !defined(ACL_PTHREAD_RWLOCK_INITIALIZER)
66 #define ACL_PTHREAD_RWLOCK_INITIALIZER NULL
67 
68 struct acl_pthread_rwlock {
69  acl_pthread_mutex_t lock; /* monitor lock acl_pthread_mutex_t */
70  int state; /* 0 = idle >0 = # of readers -1 = writer */
71  acl_pthread_cond_t read_signal;
72  acl_pthread_cond_t write_signal;
73  int blocked_writers;
74 };
75 
76 struct acl_pthread_rwlockattr {
77  int pshared;
78 };
79 
80 typedef struct acl_pthread_rwlock *acl_pthread_rwlock_t;
81 typedef struct acl_pthread_rwlockattr *acl_pthread_rwlockattr_t;
82 
83 #if defined(__cplusplus)
84 extern "C" {
85 #endif
86 
87 ACL_API int acl_pthread_rwlock_destroy(acl_pthread_rwlock_t *);
88 ACL_API int acl_pthread_rwlock_init(acl_pthread_rwlock_t *,
89  const acl_pthread_rwlockattr_t *);
90 ACL_API int acl_pthread_rwlock_rdlock(acl_pthread_rwlock_t *);
91 ACL_API int acl_pthread_rwlock_tryrdlock(acl_pthread_rwlock_t *);
92 ACL_API int acl_pthread_rwlock_trywrlock(acl_pthread_rwlock_t *);
93 ACL_API int acl_pthread_rwlock_unlock(acl_pthread_rwlock_t *);
94 ACL_API int acl_pthread_rwlock_wrlock(acl_pthread_rwlock_t *);
95 ACL_API int acl_pthread_rwlockattr_init(acl_pthread_rwlockattr_t *);
96 ACL_API int acl_pthread_rwlockattr_getpshared(const acl_pthread_rwlockattr_t *, int *);
97 ACL_API int acl_pthread_rwlockattr_setpshared(acl_pthread_rwlockattr_t *, int);
98 ACL_API int acl_pthread_rwlockattr_destroy(acl_pthread_rwlockattr_t *);
99 
100 #if defined(__cplusplus)
101 }
102 #endif
103 
104 #endif
105 
106 #endif /* ACL_HAVE_NO_RWLOCK */
107 #endif /* __ACl_THREAD_RWLOCK__ */