diff options
author | unknown <serg@serg.mylan> | 2004-11-04 22:55:47 +0100 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2004-11-04 22:55:47 +0100 |
commit | bda90564dbebc111047f1db78cdff5fb96c9d1e9 (patch) | |
tree | 456c036521147621fa4c793dba96906b5aca5102 /include/my_pthread.h | |
parent | 4553cc91cdc387660817fbd511d338d9a915ec07 (diff) | |
download | mariadb-git-bda90564dbebc111047f1db78cdff5fb96c9d1e9.tar.gz |
mmap portability layer, mmap for Windows
new macro: thread_safe_decrement, thread_safe_dec_and_test, statistic_decrement
mysys/my_chsize.c:
cleanup
include/config-win.h:
mmap portability layer, mmap for Windows
include/my_pthread.h:
thread_safe_decrement, thread_safe_dec_and_test, statistic_decrement
include/my_sys.h:
mmap portability layer, mmap for Windows
mysys/Makefile.am:
mmap portability layer, mmap for Windows
Diffstat (limited to 'include/my_pthread.h')
-rw-r--r-- | include/my_pthread.h | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/include/my_pthread.h b/include/my_pthread.h index cd0cf49a891..b47cf64aa12 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -674,21 +674,43 @@ extern pthread_t shutdown_th, main_th, signal_th; #ifndef thread_safe_increment #ifdef HAVE_ATOMIC_ADD -#define thread_safe_increment(V,L) atomic_add(1,(atomic_t*) &V); +#define thread_safe_increment(V,L) atomic_inc((atomic_t*) &V); +#define thread_safe_decrement(V,L) atomic_dec((atomic_t*) &V); +#define thread_safe_dec_and_test(V, L) atomic_dec_and_test((atomic_t*) &V); #define thread_safe_add(V,C,L) atomic_add((C),(atomic_t*) &V); #define thread_safe_sub(V,C,L) atomic_sub((C),(atomic_t*) &V); #else #define thread_safe_increment(V,L) \ - pthread_mutex_lock((L)); (V)++; pthread_mutex_unlock((L)); -#define thread_safe_add(V,C,L) \ - pthread_mutex_lock((L)); (V)+=(C); pthread_mutex_unlock((L)); + (pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L))) +#define thread_safe_decrement(V,L) \ + (pthread_mutex_lock((L)), (V)--, pthread_mutex_unlock((L))) +#define thread_safe_add(V,C,L) (pthread_mutex_lock((L)), (V)+=(C), pthread_mutex_unlock((L))) #define thread_safe_sub(V,C,L) \ - pthread_mutex_lock((L)); (V)-=(C); pthread_mutex_unlock((L)); + (pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L))) +#if defined (__GNUC__) || defined (__cplusplus) +static inline bool thread_safe_dec_and_test(ulong V, pthread_mutex_t *L) +{ + ulong res; + pthread_mutex_lock(L); + res=V--; + pthread_mutex_unlock(L); + return res==0; +} +#else +/* + what should we do ? define it as static ? + a regular function somewhere in mysys/ ? + for now it's only used in c++ code, so there's no need to bother +*/ +#warning "No thread_safe_dec_and_test() for this architecture" +#endif #endif /* HAVE_ATOMIC_ADD */ #ifdef SAFE_STATISTICS #define statistic_increment(V,L) thread_safe_increment((V),(L)) +#define statistic_decrement(V,L) thread_safe_decrement((V),(L)) #define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) #else +#define statistic_decrement(V,L) (V)-- #define statistic_increment(V,L) (V)++ #define statistic_add(V,C,L) (V)+=(C) #endif /* SAFE_STATISTICS */ |