2 * Copyright (c) 2008-2013 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
21 #ifndef __OS_ONCE_PRIVATE__
22 #define __OS_ONCE_PRIVATE__
24 #include <Availability.h>
25 #include <os/base_private.h>
27 OS_ASSUME_NONNULL_BEGIN
31 #define OS_ONCE_SPI_VERSION 20130313
33 OS_SWIFT_UNAVAILABLE("Swift has lazy init")
34 typedef long os_once_t
;
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")
40 _os_once(os_once_t
*predicate
, void *_Nullable context
, os_function_t function
);
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
)
46 if (OS_EXPECT(*predicate
, ~0l) != ~0l) {
47 _os_once(predicate
, context
, function
);
48 OS_COMPILER_CAN_ASSUME(*predicate
== ~0l);
50 os_compiler_barrier();
54 /* This SPI is *strictly* for the use of pthread_once only. This is not
55 * safe in general use of os_once.
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")
61 __os_once_reset(os_once_t
*val
);
67 #endif // __OS_ONCE_PRIVATE__