The world's most popular open source database
00001 /* Copyright (C) 2006 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 typedef struct {pthread_rwlock_t rw;} my_atomic_rwlock_t; 00018 00019 #ifdef MY_ATOMIC_MODE_DUMMY 00020 /* 00021 the following can never be enabled by ./configure, one need to put #define in 00022 a source to trigger the following warning. The resulting code will be broken, 00023 it only makes sense to do it to see now test_atomic detects broken 00024 implementations (another way is to run a UP build on an SMP box). 00025 */ 00026 #warning MY_ATOMIC_MODE_DUMMY and MY_ATOMIC_MODE_RWLOCKS are incompatible 00027 #define my_atomic_rwlock_destroy(name) 00028 #define my_atomic_rwlock_init(name) 00029 #define my_atomic_rwlock_rdlock(name) 00030 #define my_atomic_rwlock_wrlock(name) 00031 #define my_atomic_rwlock_rdunlock(name) 00032 #define my_atomic_rwlock_wrunlock(name) 00033 #define MY_ATOMIC_MODE "dummy (non-atomic)" 00034 #else 00035 #define my_atomic_rwlock_destroy(name) pthread_rwlock_destroy(& (name)->rw) 00036 #define my_atomic_rwlock_init(name) pthread_rwlock_init(& (name)->rw, 0) 00037 #define my_atomic_rwlock_rdlock(name) pthread_rwlock_rdlock(& (name)->rw) 00038 #define my_atomic_rwlock_wrlock(name) pthread_rwlock_wrlock(& (name)->rw) 00039 #define my_atomic_rwlock_rdunlock(name) pthread_rwlock_unlock(& (name)->rw) 00040 #define my_atomic_rwlock_wrunlock(name) pthread_rwlock_unlock(& (name)->rw) 00041 #define MY_ATOMIC_MODE "rwlocks" 00042 #endif 00043 00044 #define make_atomic_add_body(S) int ## S sav; sav= *a; *a+= v; v=sav; 00045 #define make_atomic_swap_body(S) int ## S sav; sav= *a; *a= v; v=sav; 00046 #define make_atomic_cas_body(S) if ((ret= (*a == *cmp))) *a= set; else *cmp=*a; 00047 #define make_atomic_load_body(S) ret= *a; 00048 #define make_atomic_store_body(S) *a= v; 00049
1.4.7

