MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rwlock.h
1 #ifndef ATOMIC_RWLOCK_INCLUDED
2 #define ATOMIC_RWLOCK_INCLUDED
3 
4 /* Copyright (c) 2006, 2013 Oracle and/or its affiliates. All rights reserved.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
18 
19 #define MY_ATOMIC_MODE_RWLOCKS 1
20 
21 #ifdef MY_ATOMIC_MODE_DUMMY
22 /*
23  the following can never be enabled by ./configure, one need to put #define in
24  a source to trigger the following warning. The resulting code will be broken,
25  it only makes sense to do it to see now test_atomic detects broken
26  implementations (another way is to run a UP build on an SMP box).
27 */
28 #warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible
29 
30 typedef char my_atomic_rwlock_t;
31 
32 #define my_atomic_rwlock_destroy(name)
33 #define my_atomic_rwlock_init(name)
34 #define my_atomic_rwlock_rdlock(name)
35 #define my_atomic_rwlock_wrlock(name)
36 #define my_atomic_rwlock_rdunlock(name)
37 #define my_atomic_rwlock_wrunlock(name)
38 #define MY_ATOMIC_MODE "dummy (non-atomic)"
39 #else /* not MY_ATOMIC_MODE_DUMMY */
40 
41 typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
42 
43 /*
44  we're using read-write lock macros but map them to mutex locks, and they're
45  faster. Still, having semantically rich API we can change the
46  underlying implementation, if necessary.
47 */
48 #define my_atomic_rwlock_destroy(name) pthread_mutex_destroy(& (name)->rw)
49 #define my_atomic_rwlock_init(name) pthread_mutex_init(& (name)->rw, 0)
50 #define my_atomic_rwlock_rdlock(name) pthread_mutex_lock(& (name)->rw)
51 #define my_atomic_rwlock_wrlock(name) pthread_mutex_lock(& (name)->rw)
52 #define my_atomic_rwlock_rdunlock(name) pthread_mutex_unlock(& (name)->rw)
53 #define my_atomic_rwlock_wrunlock(name) pthread_mutex_unlock(& (name)->rw)
54 
55 #define MY_ATOMIC_MODE "mutex"
56 #ifndef MY_ATOMIC_MODE_RWLOCKS
57 #define MY_ATOMIC_MODE_RWLOCKS 1
58 #endif
59 #endif
60 
61 #define make_atomic_add_body(S) int ## S sav; sav= *a; *a+= v; v=sav;
62 #define make_atomic_fas_body(S) int ## S sav; sav= *a; *a= v; v=sav;
63 #define make_atomic_cas_body(S) if ((ret= (*a == *cmp))) *a= set; else *cmp=*a;
64 #define make_atomic_load_body(S) ret= *a;
65 #define make_atomic_store_body(S) *a= v;
66 
67 #endif /* ATOMIC_RWLOCK_INCLUDED */