]> git.saurik.com Git - apple/libplatform.git/blame_incremental - private/os/once_private.h
libplatform-254.40.4.tar.gz
[apple/libplatform.git] / private / os / once_private.h
... / ...
CommitLineData
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
27OS_ASSUME_NONNULL_BEGIN
28
29__BEGIN_DECLS
30
31#define OS_ONCE_SPI_VERSION 20130313
32
33OS_SWIFT_UNAVAILABLE("Swift has lazy init")
34typedef long os_once_t;
35
36__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
37OS_EXPORT OS_NONNULL1 OS_NONNULL3 OS_NOTHROW
38OS_SWIFT_UNAVAILABLE("Swift has lazy init")
39void
40_os_once(os_once_t *predicate, void *_Nullable context, os_function_t function);
41
42OS_NONNULL1 OS_NONNULL3 OS_NOTHROW
43__header_always_inline void
44os_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)
58OS_EXPORT OS_NONNULL1 OS_NOTHROW
59OS_SWIFT_UNAVAILABLE("Swift has lazy init")
60void
61__os_once_reset(os_once_t *val);
62
63__END_DECLS
64
65OS_ASSUME_NONNULL_END
66
67#endif // __OS_ONCE_PRIVATE__