]> git.saurik.com Git - apple/libplatform.git/blob - private/os/semaphore_private.h
libplatform-254.40.4.tar.gz
[apple/libplatform.git] / private / os / semaphore_private.h
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_SEMAPHORE_PRIVATE__
22 #define __OS_SEMAPHORE_PRIVATE__
23
24 #include <Availability.h>
25 #include <stdint.h>
26 #include <os/base_private.h>
27 #include <os/tsd.h>
28
29 OS_ASSUME_NONNULL_BEGIN
30
31 __BEGIN_DECLS
32
33 #define OS_SEMAPHORE_SPI_VERSION 20130313
34
35 typedef uintptr_t os_semaphore_t;
36
37 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
38 OS_EXPORT OS_WARN_RESULT OS_NOTHROW
39 os_semaphore_t _os_semaphore_create(void);
40
41 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
42 OS_EXPORT OS_NOTHROW
43 void _os_semaphore_dispose(os_semaphore_t);
44
45 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
46 OS_EXPORT OS_NOTHROW
47 void _os_semaphore_wait(os_semaphore_t);
48
49 __OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
50 OS_EXPORT OS_NOTHROW
51 void _os_semaphore_signal(os_semaphore_t);
52
53 OS_WARN_RESULT OS_NOTHROW
54 __header_always_inline os_semaphore_t
55 os_get_cached_semaphore(void)
56 {
57 os_semaphore_t sema;
58 sema = (os_semaphore_t)_os_tsd_get_direct(__TSD_SEMAPHORE_CACHE);
59 if (os_unlikely(!sema)) {
60 return _os_semaphore_create();
61 }
62 _os_tsd_set_direct(__TSD_SEMAPHORE_CACHE, 0);
63 return sema;
64 }
65
66 OS_NOTHROW
67 __header_always_inline void
68 os_put_cached_semaphore(os_semaphore_t sema)
69 {
70 os_semaphore_t old_sema;
71 old_sema = (os_semaphore_t)_os_tsd_get_direct(__TSD_SEMAPHORE_CACHE);
72 _os_tsd_set_direct(__TSD_SEMAPHORE_CACHE, (void*)sema);
73 if (os_unlikely(old_sema)) {
74 return _os_semaphore_dispose(old_sema);
75 }
76 }
77
78 OS_NOTHROW
79 __header_always_inline void
80 os_semaphore_wait(os_semaphore_t sema)
81 {
82 return _os_semaphore_wait(sema);
83 }
84
85 OS_NOTHROW
86 __header_always_inline void
87 os_semaphore_signal(os_semaphore_t sema)
88 {
89 return _os_semaphore_signal(sema);
90 }
91
92 __END_DECLS
93
94 OS_ASSUME_NONNULL_END
95
96 #endif // __OS_SEMAPHORE_PRIVATE__