~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/atomic/win32/apr_atomic.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
 
 
17
#include "apr.h"
 
18
#include "apr_atomic.h"
 
19
#include "apr_thread_mutex.h"
 
20
 
 
21
APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
 
22
{
 
23
    return APR_SUCCESS;
 
24
}
 
25
 
 
26
/* 
 
27
 * Remapping function pointer type to accept apr_uint32_t's type-safely
 
28
 * as the arguments for as our apr_atomic_foo32 Functions
 
29
 */
 
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 *, 
 
34
     apr_uint32_t);
 
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)
 
39
    (volatile void **, 
 
40
     void *, const void *);
 
41
 
 
42
APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
 
43
{
 
44
#if (defined(_M_IA64) || defined(_M_AMD64))
 
45
    return InterlockedExchangeAdd(mem, val);
 
46
#else
 
47
    return ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem, val);
 
48
#endif
 
49
}
 
50
 
 
51
/* Of course we want the 2's compliment of the unsigned value, val */
 
52
#pragma warning(disable: 4146)
 
53
 
 
54
APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
 
55
{
 
56
#if (defined(_M_IA64) || defined(_M_AMD64))
 
57
    InterlockedExchangeAdd(mem, -val);
 
58
#else
 
59
    ((apr_atomic_win32_ptr_val_fn)InterlockedExchangeAdd)(mem, -val);
 
60
#endif
 
61
}
 
62
 
 
63
APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
 
64
{
 
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;
 
68
#else
 
69
    return ((apr_atomic_win32_ptr_fn)InterlockedIncrement)(mem) - 1;
 
70
#endif
 
71
}
 
72
 
 
73
APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
 
74
{
 
75
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
 
76
    return InterlockedDecrement(mem);
 
77
#else
 
78
    return ((apr_atomic_win32_ptr_fn)InterlockedDecrement)(mem);
 
79
#endif
 
80
}
 
81
 
 
82
APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
 
83
{
 
84
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
 
85
    InterlockedExchange(mem, val);
 
86
#else
 
87
    ((apr_atomic_win32_ptr_val_fn)InterlockedExchange)(mem, val);
 
88
#endif
 
89
}
 
90
 
 
91
APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
 
92
{
 
93
    return *mem;
 
94
}
 
95
 
 
96
APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
 
97
                                           apr_uint32_t cmp)
 
98
{
 
99
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
 
100
    return InterlockedCompareExchange(mem, with, cmp);
 
101
#else
 
102
    return ((apr_atomic_win32_ptr_val_val_fn)InterlockedCompareExchange)(mem, with, cmp);
 
103
#endif
 
104
}
 
105
 
 
106
APR_DECLARE(void *) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
 
107
{
 
108
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
 
109
    return InterlockedCompareExchangePointer(mem, with, cmp);
 
110
#else
 
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);
 
113
#endif
 
114
}
 
115
 
 
116
APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
 
117
{
 
118
#if (defined(_M_IA64) || defined(_M_AMD64)) && !defined(RC_INVOKED)
 
119
    return InterlockedExchange(mem, val);
 
120
#else
 
121
    return ((apr_atomic_win32_ptr_val_fn)InterlockedExchange)(mem, val);
 
122
#endif
 
123
}