]> git.saurik.com Git - apple/libplatform.git/blob - src/os/lock_internal.h
libplatform-126.50.8.tar.gz
[apple/libplatform.git] / src / os / lock_internal.h
1 /*
2 * Copyright (c) 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_LOCK_INTERNAL__
22 #define __OS_LOCK_INTERNAL__
23
24 #define OS_LOCK_S_INTERNAL(type) _os_lock_##type##_s
25 #define OS_LOCK_T_INTERNAL(type) _os_lock_##type##_t
26 #define OS_LOCK_STRUCT_INTERNAL(type) struct OS_LOCK_S_INTERNAL(type)
27 #define OS_LOCK_T_MEMBER(type) \
28 OS_LOCK_STRUCT(type) *_osl_opaque_##type; \
29 OS_LOCK_STRUCT_INTERNAL(type) *_osl_##type
30
31 #define OS_LOCK_STRUCT_DECL_INTERNAL(type, ...) \
32 typedef struct OS_LOCK_S_INTERNAL(type) { \
33 OS_LOCK_TYPE_STRUCT(type) * const osl_type; \
34 __VA_ARGS__ \
35 } OS_LOCK_S_INTERNAL(type); \
36 typedef OS_LOCK_STRUCT_INTERNAL(type) *OS_LOCK_T_INTERNAL(type)
37
38 #define OS_LOCK_METHODS_DECL(type) \
39 void _os_lock_##type##_lock(OS_LOCK_T_INTERNAL(type)); \
40 bool _os_lock_##type##_trylock(OS_LOCK_T_INTERNAL(type)); \
41 void _os_lock_##type##_unlock(OS_LOCK_T_INTERNAL(type))
42
43 #define OS_LOCK_TYPE_STRUCT_DECL(type) \
44 OS_LOCK_TYPE_STRUCT(type) { \
45 const char *osl_kind; \
46 void (*osl_lock)(os_lock_t); \
47 bool (*osl_trylock)(os_lock_t); \
48 void (*osl_unlock)(os_lock_t); \
49 } OS_LOCK_TYPE_REF(type)
50
51 #define OS_LOCK_TYPE_INSTANCE(type) \
52 OS_LOCK_TYPE_STRUCT_DECL(type) = { \
53 .osl_kind = #type, \
54 .osl_lock = _os_lock_##type##_lock, \
55 .osl_trylock = _os_lock_##type##_trylock, \
56 .osl_unlock = _os_lock_##type##_unlock, \
57 }
58
59 #include "os/internal.h"
60
61 #endif // __OS_LOCK_INTERNAL__