]> git.saurik.com Git - apple/libdispatch.git/blob - src/semaphore_internal.h
libdispatch-703.30.5.tar.gz
[apple/libdispatch.git] / src / semaphore_internal.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 /*
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
25 */
26
27 #ifndef __DISPATCH_SEMAPHORE_INTERNAL__
28 #define __DISPATCH_SEMAPHORE_INTERNAL__
29
30 struct dispatch_queue_s;
31
32 #if USE_MACH_SEM
33 #define DISPATCH_OS_SEMA_FIELD(base) semaphore_t base##_port
34 #elif USE_POSIX_SEM
35 #define DISPATCH_OS_SEMA_FIELD(base) sem_t base##_sem
36 #elif USE_WIN32_SEM
37 #define DISPATCH_OS_SEMA_FIELD(base) HANDLE base##_handle
38 #else
39 #error "No supported semaphore type"
40 #endif
41
42 #define DISPATCH_SEMAPHORE_HEADER(cls, ns) \
43 DISPATCH_OBJECT_HEADER(cls); \
44 long volatile ns##_value; \
45 DISPATCH_OS_SEMA_FIELD(ns)
46
47 struct dispatch_semaphore_header_s {
48 DISPATCH_SEMAPHORE_HEADER(semaphore, dsema);
49 };
50
51 DISPATCH_CLASS_DECL(semaphore);
52 struct dispatch_semaphore_s {
53 DISPATCH_SEMAPHORE_HEADER(semaphore, dsema);
54 long dsema_orig;
55 };
56
57 DISPATCH_CLASS_DECL(group);
58 struct dispatch_group_s {
59 DISPATCH_SEMAPHORE_HEADER(group, dg);
60 int volatile dg_waiters;
61 struct dispatch_continuation_s *volatile dg_notify_head;
62 struct dispatch_continuation_s *volatile dg_notify_tail;
63 };
64
65 typedef union {
66 struct dispatch_semaphore_header_s *_dsema_hdr;
67 struct dispatch_semaphore_s *_dsema;
68 struct dispatch_group_s *_dg;
69 #if USE_OBJC
70 dispatch_semaphore_t _objc_dsema;
71 dispatch_group_t _objc_dg;
72 #endif
73 } dispatch_semaphore_class_t __attribute__((__transparent_union__));
74
75 dispatch_group_t _dispatch_group_create_and_enter(void);
76 void _dispatch_group_dispose(dispatch_object_t dou);
77 size_t _dispatch_group_debug(dispatch_object_t dou, char *buf,
78 size_t bufsiz);
79
80 void _dispatch_semaphore_dispose(dispatch_object_t dou);
81 size_t _dispatch_semaphore_debug(dispatch_object_t dou, char *buf,
82 size_t bufsiz);
83
84 #endif