diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2003-10-15 21:33:22 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2003-10-15 21:33:22 +0000 |
commit | da96700c9d7ba5aebddd6a107681e471f5e1d602 (patch) | |
tree | 7cea7c9056ca1be433c29f12b691c4ce585bad00 /include | |
parent | 01ae57b9fb3862c75621391de87e3094ffe903fe (diff) | |
download | libapr-da96700c9d7ba5aebddd6a107681e471f5e1d602.tar.gz |
Use function overrides to provide the correct argument types for our
macro'ized atomic transliterations.
This code is 100% safer than the equivilant argument and return value
casts, because the user's first arg can't be forced from a value to
a pointer, and conversly for more than one argument.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64689 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'include')
-rw-r--r-- | include/apr_atomic.h | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/include/apr_atomic.h b/include/apr_atomic.h index 8aa95249c..c06ffd70f 100644 --- a/include/apr_atomic.h +++ b/include/apr_atomic.h @@ -239,13 +239,42 @@ void *apr_atomic_casptr(volatile void **mem, void *with, const void *cmp); #define apr_atomic_init(pool) APR_SUCCESS #define apr_atomic_add(mem, val) InterlockedExchangeAdd(mem,val) -#define apr_atomic_dec(mem) InterlockedDecrement(mem) #define apr_atomic_inc(mem) InterlockedIncrement(mem) +#define apr_atomic_dec(mem) InterlockedDecrement(mem) #define apr_atomic_set(mem, val) InterlockedExchange(mem, val) #define apr_atomic_read(mem) (*mem) #define apr_atomic_cas(mem,with,cmp) InterlockedCompareExchange(mem,with,cmp) #define apr_atomic_casptr(mem,with,cmp) InterlockedCompareExchangePointer(mem,with,cmp) +/* + * Remapping function pointer type to accept apr_uint32_t's type-safely + * as the arguments for as our apr_atomic_foo32 Functions + */ +typedef WINBASEAPI apr_uint32_t (WINAPI apr_atomic_win32_ptr_fn) + (apr_uint32_t volatile *); +typedef WINBASEAPI apr_uint32_t (WINAPI apr_atomic_win32_ptr_val_fn) + (apr_uint32_t volatile *, + apr_uint32_t); +typedef WINBASEAPI apr_uint32_t (WINAPI apr_atomic_win32_ptr_val_val_fn) + (apr_uint32_t volatile *, + apr_uint32_t, apr_uint32_t); + +#define apr_atomic_add32(mem, val) \ + ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem,val) +#define apr_atomic_sub32(mem, val) \ + ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeSub)(mem,val) +#define apr_atomic_inc32(mem) \ + ((apr_atomic_win32_ptr_fn)InterlockedIncrement)(mem) +#define apr_atomic_dec32(mem) \ + ((apr_atomic_win32_ptr_fn)InterlockedDecrement)(mem) +#define apr_atomic_set32(mem, val) \ + ((apr_atomic_win32_ptr_val_fn)InterlockedExchange)(mem,val) +#define apr_atomic_read32(mem) (*mem) +#define apr_atomic_cas32(mem,with,cmp) \ + ((apr_atomic_win32_ptr_val_val_fn)InterlockedCompareExchange)(mem,val) +#define apr_atomic_xchg32(mem,val) \ + ((apr_atomic_win32_ptr_val_fn)InterlockedExchange)(mem,val) + #elif defined(NETWARE) #define apr_atomic_init(pool) APR_SUCCESS @@ -507,7 +536,7 @@ void *apr_atomic_casptr(volatile void **mem, void *with, const void *cmp); */ #if APR_ATOMIC_NEED_DEFAULT_INIT #if defined(apr_atomic_init) || defined(APR_OVERRIDE_ATOMIC_INIT) -#error Platform has redefined apr_atomic_init, but other default default atomics require a default apr_atomic_init +#error Platform has redefined apr_atomic_init, but other default atomics require a default apr_atomic_init #endif #endif /* APR_ATOMIC_NEED_DEFAULT_INIT */ |