Apache HTTPD
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
30
35
37{
38 /* we return old value, win64 returns new value :( */
39 return InterlockedIncrement64((volatile LONG64 *)mem) - 1;
40}
41
43{
44 return !!InterlockedDecrement64((volatile LONG64 *)mem);
45}
46
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
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
75{
76 return InterlockedCompareExchange64((volatile LONG64 *)mem, with, cmp);
77}
78
80{
81 return InterlockedExchange64((volatile LONG64 *)mem, val);
82}
APR Atomic Operations.
APR Thread Mutex Routines.
apr_size_t size
apr_uint32_t apr_uint32_t cmp
Definition apr_atomic.h:106
apr_uint32_t with
Definition apr_atomic.h:105
apr_uint32_t val
Definition apr_atomic.h:66
APR_DECLARE(void)
void * mem