1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#include "apr_atomic.h"
19
#include "apr_thread_mutex.h"
21
APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
27
* Remapping function pointer type to accept apr_uint32_t's type-safely
28
* as the arguments for as our apr_atomic_foo32 Functions
30
typedef WINBASEAPI apr_uint32_t (WINAPI * apr_atomic_win32_ptr_fn)
31
(apr_uint32_t volatile *);
32
typedef WINBASEAPI apr_uint32_t (WINAPI * apr_atomic_win32_ptr_val_fn)
33
(apr_uint32_t volatile *,
35
typedef WINBASEAPI apr_uint32_t (WINAPI * apr_atomic_win32_ptr_val_val_fn)
36
(apr_uint32_t volatile *,
37
apr_uint32_t, apr_uint32_t);
38
typedef WINBASEAPI void * (WINAPI * apr_atomic_win32_ptr_ptr_ptr_fn)
40
void *, const void *);
42
APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
44
#if (defined(_M_IA64) || defined(_M_AMD64))
45
return InterlockedExchangeAdd(mem, val);
47
return ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem, val);
51
/* Of course we want the 2's compliment of the unsigned value, val */
52
#pragma warning(disable: 4146)
54
APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
56
#if (defined(_M_IA64) || defined(_M_AMD64))
57
InterlockedExchangeAdd(mem, -val);
59
((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem, -val);
63
APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
65
/* we return old value, win32 returns new value :( */
66
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
67
return InterlockedIncrement(mem) - 1;
69
return ((apr_atomic_win32_ptr_fn)InterlockedIncrement)(mem) - 1;
73
APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
75
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
76
return InterlockedDecrement(mem);
78
return ((apr_atomic_win32_ptr_fn)InterlockedDecrement)(mem);
82
APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
84
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
85
InterlockedExchange(mem, val);
87
((apr_atomic_win32_ptr_val_fn)InterlockedExchange)(mem, val);
91
APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
96
APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
99
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
100
return InterlockedCompareExchange(mem, with, cmp);
102
return ((apr_atomic_win32_ptr_val_val_fn)InterlockedCompareExchange)(mem, with, cmp);
106
APR_DECLARE(void *) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
108
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
109
return InterlockedCompareExchangePointer(mem, with, cmp);
111
/* Too many VC6 users have stale win32 API files, stub this */
112
return ((apr_atomic_win32_ptr_ptr_ptr_fn)InterlockedCompareExchange)(mem, with, cmp);
116
APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
118
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
119
return InterlockedExchange(mem, val);
121
return ((apr_atomic_win32_ptr_val_fn)InterlockedExchange)(mem, val);