PageRenderTime 16ms CodeModel.GetById 13ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/External/Mysql-5.0/include/atomic/rwlock.h

http://awoe.googlecode.com/
C++ Header | 57 lines | 28 code | 4 blank | 25 comment | 3 complexity | 78f69a499291ff47fdacc6eda0f7a5e0 MD5 | raw file
 1/* Copyright (C) 2006 MySQL AB
 2
 3   This program is free software; you can redistribute it and/or modify
 4   it under the terms of the GNU General Public License as published by
 5   the Free Software Foundation; version 2 of the License.
 6
 7   This program is distributed in the hope that it will be useful,
 8   but WITHOUT ANY WARRANTY; without even the implied warranty of
 9   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10   GNU General Public License for more details.
11
12   You should have received a copy of the GNU General Public License
13   along with this program; if not, write to the Free Software
14   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16typedef struct {pthread_mutex_t rw;} my_atomic_rwlock_t;
17#define MY_ATOMIC_MODE_RWLOCKS 1
18
19#ifdef MY_ATOMIC_MODE_DUMMY
20/*
21  the following can never be enabled by ./configure, one need to put #define in
22  a source to trigger the following warning. The resulting code will be broken,
23  it only makes sense to do it to see now test_atomic detects broken
24  implementations (another way is to run a UP build on an SMP box).
25*/
26#warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible
27#define my_atomic_rwlock_destroy(name)
28#define my_atomic_rwlock_init(name)
29#define my_atomic_rwlock_rdlock(name)
30#define my_atomic_rwlock_wrlock(name)
31#define my_atomic_rwlock_rdunlock(name)
32#define my_atomic_rwlock_wrunlock(name)
33#define MY_ATOMIC_MODE "dummy (non-atomic)"
34#else
35/*
36  we're using read-write lock macros but map them to mutex locks, and they're
37  faster. Still, having semantically rich API we can change the
38  underlying implementation, if necessary.
39*/
40#define my_atomic_rwlock_destroy(name)     pthread_mutex_destroy(& (name)->rw)
41#define my_atomic_rwlock_init(name)        pthread_mutex_init(& (name)->rw, 0)
42#define my_atomic_rwlock_rdlock(name)      pthread_mutex_lock(& (name)->rw)
43#define my_atomic_rwlock_wrlock(name)      pthread_mutex_lock(& (name)->rw)
44#define my_atomic_rwlock_rdunlock(name)    pthread_mutex_unlock(& (name)->rw)
45#define my_atomic_rwlock_wrunlock(name)    pthread_mutex_unlock(& (name)->rw)
46#define MY_ATOMIC_MODE "mutex"
47#ifndef MY_ATOMIC_MODE_RWLOCKS
48#define MY_ATOMIC_MODE_RWLOCKS 1
49#endif
50#endif
51
52#define make_atomic_add_body(S)     int ## S sav; sav= *a; *a+= v; v=sav;
53#define make_atomic_fas_body(S)     int ## S sav; sav= *a; *a= v; v=sav;
54#define make_atomic_cas_body(S)     if ((ret= (*a == *cmp))) *a= set; else *cmp=*a;
55#define make_atomic_load_body(S)    ret= *a;
56#define make_atomic_store_body(S)   *a= v;
57