-
Notifications
You must be signed in to change notification settings - Fork 302
/
Copy pathCAtomics.h
73 lines (58 loc) · 2.02 KB
/
CAtomics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SOURCEKITLSP_CATOMICS_H
#define SOURCEKITLSP_CATOMICS_H
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <stdlib.h>
typedef struct {
_Atomic(uint32_t) value;
} CAtomicUInt32;
static inline CAtomicUInt32 *_Nonnull atomic_uint32_create(uint32_t initialValue) {
CAtomicUInt32 *atomic = malloc(sizeof(CAtomicUInt32));
atomic->value = initialValue;
return atomic;
}
static inline uint32_t atomic_uint32_get(CAtomicUInt32 *_Nonnull atomic) {
return atomic->value;
}
static inline void atomic_uint32_set(CAtomicUInt32 *_Nonnull atomic, uint32_t newValue) {
atomic->value = newValue;
}
static inline uint32_t atomic_uint32_fetch_and_increment(CAtomicUInt32 *_Nonnull atomic) {
return atomic->value++;
}
static inline void atomic_uint32_destroy(CAtomicUInt32 *_Nonnull atomic) {
free(atomic);
}
typedef struct {
_Atomic(int32_t) value;
} CAtomicInt32;
static inline CAtomicInt32 *_Nonnull atomic_int32_create(int32_t initialValue) {
CAtomicInt32 *atomic = malloc(sizeof(CAtomicInt32));
atomic->value = initialValue;
return atomic;
}
static inline int32_t atomic_int32_get(CAtomicInt32 *_Nonnull atomic) {
return atomic->value;
}
static inline void atomic_int32_set(CAtomicInt32 *_Nonnull atomic, int32_t newValue) {
atomic->value = newValue;
}
static inline int32_t atomic_int32_fetch_and_increment(CAtomicInt32 *_Nonnull atomic) {
return atomic->value++;
}
static inline void atomic_int32_destroy(CAtomicInt32 *_Nonnull atomic) {
free(atomic);
}
#endif // SOURCEKITLSP_CATOMICS_H