New PHP5 APC - version 3.0.19, using PHP5 5.2.0-8+etch11,
[php5-apc.git] / apc_lock.h
1 /*
2   +----------------------------------------------------------------------+
3   | APC                                                                  |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 2008 The PHP Group                                     |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: George Schlossnagle <george@omniti.com>                     |
16   |          Rasmus Lerdorf <rasmus@php.net>                             |
17   +----------------------------------------------------------------------+
18
19    This software was contributed to PHP by Community Connect Inc. in 2002
20    and revised in 2005 by Yahoo! Inc. to add support for PHP 5.1.
21    Future revisions and derivatives of this source code must acknowledge
22    Community Connect Inc. as the original contributor of this module by
23    leaving this note intact in the source code.
24
25    All other licensing and usage conditions are those of the PHP Group.
26
27  */
28
29 /* $Id: apc_lock.h,v 3.20.2.1 2008/05/11 18:57:00 rasmus Exp $ */
30
31 #ifndef APC_LOCK
32 #define APC_LOCK
33
34 #include "apc_sem.h"
35 #include "apc_fcntl.h"
36 #include "apc_pthreadmutex.h"
37 #include "apc_futex.h"
38 #include "apc_spin.h"
39 #ifdef HAVE_CONFIG_H
40 #include <config.h>
41 #endif
42
43 #ifdef TSRM_LOCKS
44 #define RDLOCK_AVAILABLE 0
45 #define NONBLOCKING_LOCK_AVAILABLE 0
46 /* quick & dirty: use TSRM mutex locks for now */
47 #define apc_lck_create(a,b,c,d) d=(int)tsrm_mutex_alloc()
48 #define apc_lck_destroy(a)    tsrm_mutex_free((MUTEX_T)a)
49 #define apc_lck_lock(a)       tsrm_mutex_lock((MUTEX_T)a)
50 #define apc_lck_rdlock(a)     tsrm_mutex_lock((MUTEX_T)a)
51 #define apc_lck_unlock(a)     tsrm_mutex_unlock((MUTEX_T)a)
52 #elif defined(APC_SEM_LOCKS)
53 #define RDLOCK_AVAILABLE 0
54 #define NONBLOCKING_LOCK_AVAILABLE 0
55 #define apc_lck_t int
56 #define apc_lck_create(a,b,c,d) d=apc_sem_create(NULL,(b),(c))
57 #define apc_lck_destroy(a)    apc_sem_destroy(a)
58 #define apc_lck_lock(a)       apc_sem_lock(a)
59 #define apc_lck_rdlock(a)     apc_sem_lock(a)
60 #define apc_lck_unlock(a)     apc_sem_unlock(a)
61 #elif defined(APC_PTHREADMUTEX_LOCKS)
62 #define RDLOCK_AVAILABLE 0
63 #define NONBLOCKING_LOCK_AVAILABLE 1
64 #define apc_lck_t pthread_mutex_t 
65 #define apc_lck_create(a,b,c,d) apc_pthreadmutex_create((pthread_mutex_t*)&d)
66 #define apc_lck_destroy(a)    apc_pthreadmutex_destroy(&a)
67 #define apc_lck_lock(a)       apc_pthreadmutex_lock(&a)
68 #define apc_lck_nb_lock(a)    apc_pthreadmutex_nonblocking_lock(&a)
69 #define apc_lck_rdlock(a)     apc_pthreadmutex_lock(&a)
70 #define apc_lck_unlock(a)     apc_pthreadmutex_unlock(&a)
71 #elif defined(APC_FUTEX_LOCKS)
72 #define NONBLOCKING_LOCK_AVAILABLE 1 
73 #define apc_lck_t int 
74 #define apc_lck_create(a,b,c,d) d=apc_futex_create()
75 #define apc_lck_destroy(a)    apc_futex_destroy(&a)
76 #define apc_lck_lock(a)       apc_futex_lock(&a)
77 #define apc_lck_nb_lock(a)    apc_futex_nonblocking_lock(&a)
78 #define apc_lck_rdlock(a)     apc_futex_lock(&a)
79 #define apc_lck_unlock(a)     apc_futex_unlock(&a)
80 #elif defined(APC_SPIN_LOCKS)
81 #define NONBLOCKING_LOCK_AVAILABLE APC_SLOCK_NONBLOCKING_LOCK_AVAILABLE
82 #define apc_lck_t slock_t 
83 #define apc_lck_create(a,b,c,d) apc_slock_create((slock_t*)&(d))
84 #define apc_lck_destroy(a)    apc_slock_destroy(&a)
85 #define apc_lck_lock(a)       apc_slock_lock(&a)
86 #define apc_lck_nb_lock(a)    apc_slock_nonblocking_lock(&a)
87 #define apc_lck_rdlock(a)     apc_slock_lock(&a)
88 #define apc_lck_unlock(a)     apc_slock_unlock(&a)
89 #else
90 #define RDLOCK_AVAILABLE 1
91 #ifdef PHP_WIN32
92 #define NONBLOCKING_LOCK_AVAILABLE 0
93 #else
94 #define NONBLOCKING_LOCK_AVAILABLE 1
95 #endif
96 #define apc_lck_t int
97 #define apc_lck_create(a,b,c,d) d=apc_fcntl_create((a))
98 #define apc_lck_destroy(a)    apc_fcntl_destroy(a)
99 #define apc_lck_lock(a)       apc_fcntl_lock(a)
100 #define apc_lck_nb_lock(a)    apc_fcntl_nonblocking_lock(a)
101 #define apc_lck_rdlock(a)     apc_fcntl_rdlock(a)
102 #define apc_lck_unlock(a)     apc_fcntl_unlock(a)
103 #endif
104
105 #endif