]> git.saurik.com Git - apple/libplatform.git/blame - private/os/semaphore_private.h
libplatform-254.40.4.tar.gz
[apple/libplatform.git] / private / os / semaphore_private.h
CommitLineData
ada7c492
A
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
29OS_ASSUME_NONNULL_BEGIN
30
31__BEGIN_DECLS
32
33#define OS_SEMAPHORE_SPI_VERSION 20130313
34
35typedef uintptr_t os_semaphore_t;
36
37__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
38OS_EXPORT OS_WARN_RESULT OS_NOTHROW
39os_semaphore_t _os_semaphore_create(void);
40
41__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
42OS_EXPORT OS_NOTHROW
43void _os_semaphore_dispose(os_semaphore_t);
44
45__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
46OS_EXPORT OS_NOTHROW
47void _os_semaphore_wait(os_semaphore_t);
48
49__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
50OS_EXPORT OS_NOTHROW
51void _os_semaphore_signal(os_semaphore_t);
52
53OS_WARN_RESULT OS_NOTHROW
54__header_always_inline os_semaphore_t
55os_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
66OS_NOTHROW
67__header_always_inline void
68os_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
78OS_NOTHROW
79__header_always_inline void
80os_semaphore_wait(os_semaphore_t sema)
81{
82 return _os_semaphore_wait(sema);
83}
84
85OS_NOTHROW
86__header_always_inline void
87os_semaphore_signal(os_semaphore_t sema)
88{
89 return _os_semaphore_signal(sema);
90}
91
92__END_DECLS
93
94OS_ASSUME_NONNULL_END
95
96#endif // __OS_SEMAPHORE_PRIVATE__