]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2008-2013 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_APACHE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
7 | * you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, software | |
13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 | * See the License for the specific language governing permissions and | |
16 | * limitations under the License. | |
17 | * | |
18 | * @APPLE_APACHE_LICENSE_HEADER_END@ | |
19 | */ | |
20 | ||
21 | #ifndef __OS_ONCE_PRIVATE__ | |
22 | #define __OS_ONCE_PRIVATE__ | |
23 | ||
24 | #include <Availability.h> | |
25 | #include <os/base_private.h> | |
26 | ||
27 | OS_ASSUME_NONNULL_BEGIN | |
28 | ||
29 | __BEGIN_DECLS | |
30 | ||
31 | #define OS_ONCE_SPI_VERSION 20130313 | |
32 | ||
33 | OS_SWIFT_UNAVAILABLE("Swift has lazy init") | |
34 | typedef long os_once_t; | |
35 | ||
36 | __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0) | |
37 | OS_EXPORT OS_NONNULL1 OS_NONNULL3 OS_NOTHROW | |
38 | OS_SWIFT_UNAVAILABLE("Swift has lazy init") | |
39 | void | |
40 | _os_once(os_once_t *predicate, void *_Nullable context, os_function_t function); | |
41 | ||
42 | OS_NONNULL1 OS_NONNULL3 OS_NOTHROW | |
43 | __header_always_inline void | |
44 | os_once(os_once_t *predicate, void *_Nullable context, os_function_t function) | |
45 | { | |
46 | if (OS_EXPECT(*predicate, ~0l) != ~0l) { | |
47 | _os_once(predicate, context, function); | |
48 | OS_COMPILER_CAN_ASSUME(*predicate == ~0l); | |
49 | } else { | |
50 | os_compiler_barrier(); | |
51 | } | |
52 | } | |
53 | ||
54 | /* This SPI is *strictly* for the use of pthread_once only. This is not | |
55 | * safe in general use of os_once. | |
56 | */ | |
57 | __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0) | |
58 | OS_EXPORT OS_NONNULL1 OS_NOTHROW | |
59 | OS_SWIFT_UNAVAILABLE("Swift has lazy init") | |
60 | void | |
61 | __os_once_reset(os_once_t *val); | |
62 | ||
63 | __END_DECLS | |
64 | ||
65 | OS_ASSUME_NONNULL_END | |
66 | ||
67 | #endif // __OS_ONCE_PRIVATE__ |