Bump year. Change Aps->ApS
[idzebra-moved-to-github.git] / include / zebra-lock.h
1 /* $Id: zebra-lock.h,v 1.8 2005-01-15 19:38:24 adam Exp $
2    Copyright (C) 1995-2005
3    Index Data ApS
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23
24
25 #ifndef ZEBRA_LOCK_H
26 #define ZEBRA_LOCK_H
27
28 #ifdef WIN32
29 #include <windows.h>
30 #endif
31 #if YAZ_POSIX_THREADS
32 #include <pthread.h>
33 #endif
34
35 #include <yaz/yconfig.h>
36
37 YAZ_BEGIN_CDECL
38
39 typedef struct {
40 #ifdef WIN32
41     CRITICAL_SECTION mutex;
42 #else
43 # if YAZ_POSIX_THREADS
44     pthread_mutex_t mutex;
45 # else
46     int dummy;
47 # endif
48 #endif
49     int state;
50 } Zebra_mutex;
51
52 YAZ_EXPORT int zebra_mutex_init (Zebra_mutex *p);
53 YAZ_EXPORT int zebra_mutex_destroy (Zebra_mutex *p);
54 YAZ_EXPORT int zebra_mutex_lock (Zebra_mutex *p);
55 YAZ_EXPORT int zebra_mutex_unlock (Zebra_mutex *p);
56
57 typedef struct {
58     int readers_reading;
59     int writers_writing;
60 #if YAZ_POSIX_THREADS
61     pthread_mutex_t mutex;
62     pthread_cond_t lock_free;
63 #endif
64 } Zebra_lock_rdwr;
65
66 YAZ_EXPORT int zebra_lock_rdwr_init (Zebra_lock_rdwr *p);
67 YAZ_EXPORT int zebra_lock_rdwr_destroy (Zebra_lock_rdwr *p);
68 YAZ_EXPORT int zebra_lock_rdwr_rlock (Zebra_lock_rdwr *p);
69 YAZ_EXPORT int zebra_lock_rdwr_wlock (Zebra_lock_rdwr *p);
70 YAZ_EXPORT int zebra_lock_rdwr_runlock (Zebra_lock_rdwr *p);
71 YAZ_EXPORT int zebra_lock_rdwr_wunlock (Zebra_lock_rdwr *p);
72
73 typedef struct {
74 #if YAZ_POSIX_THREADS
75     pthread_mutex_t mutex;
76     pthread_cond_t cond;
77 #else
78     int dummy;
79 #endif
80 } Zebra_mutex_cond;
81
82 YAZ_EXPORT int zebra_mutex_cond_init (Zebra_mutex_cond *p);
83 YAZ_EXPORT int zebra_mutex_cond_destroy (Zebra_mutex_cond *p);
84 YAZ_EXPORT int zebra_mutex_cond_lock (Zebra_mutex_cond *p);
85 YAZ_EXPORT int zebra_mutex_cond_unlock (Zebra_mutex_cond *p);
86 YAZ_EXPORT int zebra_mutex_cond_wait (Zebra_mutex_cond *p);
87 YAZ_EXPORT int zebra_mutex_cond_signal (Zebra_mutex_cond *p);
88
89 YAZ_END_CDECL
90
91 #endif