View | Details | Raw Unified | Return to bug 42806
Collapse All | Expand All

(-)apr/atomic/unix/builtins.c (+74 lines)
Line 0 Link Here
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_arch_atomic.h"
18
19
#ifdef USE_ATOMICS_BUILTINS
20
21
APR_DECLARE(apr_status_t) apr_atomic_init(apr_pool_t *p)
22
{
23
    return APR_SUCCESS;
24
}
25
26
APR_DECLARE(apr_uint32_t) apr_atomic_read32(volatile apr_uint32_t *mem)
27
{
28
    return *mem;
29
}
30
31
APR_DECLARE(void) apr_atomic_set32(volatile apr_uint32_t *mem, apr_uint32_t val)
32
{
33
    *mem = val;
34
}
35
36
APR_DECLARE(apr_uint32_t) apr_atomic_add32(volatile apr_uint32_t *mem, apr_uint32_t val)
37
{
38
    return __sync_fetch_and_add(mem, val);
39
}
40
41
APR_DECLARE(void) apr_atomic_sub32(volatile apr_uint32_t *mem, apr_uint32_t val)
42
{
43
    __sync_fetch_and_sub(mem, val);
44
}
45
46
APR_DECLARE(apr_uint32_t) apr_atomic_inc32(volatile apr_uint32_t *mem)
47
{
48
    return __sync_fetch_and_add(mem, 1);
49
}
50
51
APR_DECLARE(int) apr_atomic_dec32(volatile apr_uint32_t *mem)
52
{
53
    return __sync_sub_and_fetch(mem, 1);
54
}
55
56
APR_DECLARE(apr_uint32_t) apr_atomic_cas32(volatile apr_uint32_t *mem, apr_uint32_t with,
57
                                           apr_uint32_t cmp)
58
{
59
    return __sync_val_compare_and_swap(mem, cmp, with);
60
}
61
62
APR_DECLARE(apr_uint32_t) apr_atomic_xchg32(volatile apr_uint32_t *mem, apr_uint32_t val)
63
{
64
    __sync_synchronize();
65
66
    return __sync_lock_test_and_set(mem, val);
67
}
68
69
APR_DECLARE(void*) apr_atomic_casptr(volatile void **mem, void *with, const void *cmp)
70
{
71
    return (void*) __sync_val_compare_and_swap(mem, cmp, with);
72
}
73
74
#endif /* USE_ATOMICS_BUILTINS */
(-)apr/configure.in (+42 lines)
Lines 350-355 case "$host:$CC" in Link Here
350
	;;
350
	;;
351
esac
351
esac
352
352
353
AC_CACHE_CHECK([whether the compiler provides atomic builtins], [atomic_builtins],
354
[AC_TRY_RUN([
355
int main()
356
{
357
    unsigned long val = 1010, tmp, *mem = &val;
358
359
    if (__sync_fetch_and_add(&val, 1010) != 1010 || val != 2020)
360
        return 1;
361
362
    tmp = val;
363
364
    if (__sync_fetch_and_sub(mem, 1010) != tmp || val != 1010)
365
        return 1;
366
367
    if (__sync_sub_and_fetch(&val, 1010) != 0 || val != 0)
368
        return 1;
369
370
    tmp = 3030;
371
372
    if (__sync_val_compare_and_swap(mem, 0, tmp) != 0 || val != tmp)
373
        return 1;
374
375
    if (__sync_lock_test_and_set(&val, 4040) != 3030)
376
        return 1;
377
378
    mem = &tmp;
379
380
    if (__sync_val_compare_and_swap(&mem, &tmp, &val) != &tmp)
381
        return 1;
382
383
    __sync_synchronize();
384
385
    if (mem != &val)
386
        return 1;
387
388
    return 0;
389
}], [atomic_builtins=yes], [atomic_builtins=no], [atomic_builtins=no])])
390
391
if test "$atomic_builtins" = "yes"; then
392
    AC_DEFINE(HAVE_ATOMIC_BUILTINS, 1, [Define if compiler provides atomic builtins])
393
fi
394
353
dnl Check the depend program we can use
395
dnl Check the depend program we can use
354
APR_CHECK_DEPEND
396
APR_CHECK_DEPEND
355
397
(-)apr/include/arch/unix/apr_arch_atomic.h (+2 lines)
Lines 28-33 Link Here
28
/* force use of generic atomics if building e.g. with -std=c89, which
28
/* force use of generic atomics if building e.g. with -std=c89, which
29
 * doesn't allow inline asm */
29
 * doesn't allow inline asm */
30
#   define USE_ATOMICS_GENERIC
30
#   define USE_ATOMICS_GENERIC
31
#elif HAVE_ATOMIC_BUILTINS
32
#   define USE_ATOMICS_BUILTINS
31
#else
33
#else
32
#   define USE_ATOMICS_GENERIC
34
#   define USE_ATOMICS_GENERIC
33
#endif
35
#endif

Return to bug 42806