Apache HTTPD
framework
httpd-2.4.62
srclib
apr
atomic
win32
apr_atomic64.c
Go to the documentation of this file.
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
* contributor license agreements. See the NOTICE file distributed with
3
* this work for additional information regarding copyright ownership.
4
* The ASF licenses this file to You under the Apache License, Version 2.0
5
* (the "License"); you may not use this file except in compliance with
6
* the License. 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
/* Of course we want the 2's compliment of the unsigned value, val */
22
#ifdef _MSC_VER
23
#pragma warning(disable: 4146)
24
#endif
25
26
APR_DECLARE
(
apr_uint64_t
)
apr_atomic_add64
(
volatile
apr_uint64_t
*
mem
,
apr_uint64_t
val
)
27
{
28
return
InterlockedExchangeAdd64
((
volatile
LONG64
*)
mem
,
val
);
29
}
30
31
APR_DECLARE
(
void
)
apr_atomic_sub64
(
volatile
apr_uint64_t
*
mem
,
apr_uint64_t
val
)
32
{
33
InterlockedExchangeAdd64
((
volatile
LONG64
*)
mem
, -
val
);
34
}
35
36
APR_DECLARE
(
apr_uint64_t
)
apr_atomic_inc64
(
volatile
apr_uint64_t
*
mem
)
37
{
38
/* we return old value, win64 returns new value :( */
39
return
InterlockedIncrement64
((
volatile
LONG64
*)
mem
) - 1;
40
}
41
42
APR_DECLARE
(
int
)
apr_atomic_dec64
(
volatile
apr_uint64_t
*
mem
)
43
{
44
return
!!
InterlockedDecrement64
((
volatile
LONG64
*)
mem
);
45
}
46
47
APR_DECLARE
(
void
)
apr_atomic_set64
(
volatile
apr_uint64_t
*
mem
,
apr_uint64_t
val
)
48
{
49
#if defined(_M_X64)
50
/* https://docs.microsoft.com/en-us/windows/win32/sync/interlocked-variable-access
51
* "Simple reads and writes to properly aligned 64-bit variables are atomic
52
* on 64-bit Windows."*/
53
*
mem
=
val
;
54
#else
55
InterlockedExchange64
((
volatile
LONG64
*)
mem
,
val
);
56
#endif
57
}
58
59
APR_DECLARE
(
apr_uint64_t
)
apr_atomic_read64
(
volatile
apr_uint64_t
*
mem
)
60
{
61
#if defined(_M_X64)
62
/* https://docs.microsoft.com/en-us/windows/win32/sync/interlocked-variable-access
63
* "Simple reads and writes to properly aligned 64-bit variables are atomic
64
* on 64-bit Windows."*/
65
return
*
mem
;
66
#else
67
/* 64-bit read is not atomic on 32-bit platform: use InterlockedCompareExchange
68
to perform atomic read. */
69
return
InterlockedCompareExchange64
((
volatile
LONG64
*)
mem
, 0, 0);
70
#endif
71
}
72
73
APR_DECLARE
(
apr_uint64_t
)
apr_atomic_cas64
(
volatile
apr_uint64_t
*
mem
,
apr_uint64_t
with
,
74
apr_uint64_t
cmp
)
75
{
76
return
InterlockedCompareExchange64
((
volatile
LONG64
*)
mem
,
with
,
cmp
);
77
}
78
79
APR_DECLARE
(
apr_uint64_t
)
apr_atomic_xchg64
(
volatile
apr_uint64_t
*
mem
,
apr_uint64_t
val
)
80
{
81
return
InterlockedExchange64
((
volatile
LONG64
*)
mem
,
val
);
82
}
apr_atomic.h
APR Atomic Operations.
apr_thread_mutex.h
APR Thread Mutex Routines.
size
apr_size_t size
Definition
apr_allocator.h:115
cmp
apr_uint32_t apr_uint32_t cmp
Definition
apr_atomic.h:106
with
apr_uint32_t with
Definition
apr_atomic.h:105
val
apr_uint32_t val
Definition
apr_atomic.h:66
APR_DECLARE
APR_DECLARE(void)
Definition
apr_atomic64.c:31
mem
void * mem
Definition
apr_skiplist.h:88
Generated by
1.9.8