]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | * | |
28 | */ | |
29 | /* | |
30 | * File: kern/sync_lock.h | |
31 | * Author: Joseph CaraDonna | |
32 | * | |
33 | * Contains RT distributed lock synchronization service definitions. | |
34 | */ | |
35 | ||
36 | #ifndef _KERN_SYNC_LOCK_H_ | |
37 | #define _KERN_SYNC_LOCK_H_ | |
38 | ||
39 | #include <mach/mach_types.h> | |
40 | ||
9bccf70c A |
41 | #include <sys/appleapiopts.h> |
42 | ||
43 | #ifdef __APPLE_API_PRIVATE | |
44 | ||
45 | #ifdef MACH_KERNEL_PRIVATE | |
1c79356b A |
46 | |
47 | #include <kern/wait_queue.h> | |
48 | #include <kern/macro_help.h> | |
49 | #include <kern/queue.h> | |
50 | #include <kern/lock.h> | |
51 | ||
52 | typedef struct ulock { | |
53 | queue_chain_t thread_link; /* ulocks owned by a thread */ | |
54 | queue_chain_t held_link; /* ulocks held in the lock set */ | |
55 | queue_chain_t handoff_link; /* ulocks w/ active handoffs */ | |
56 | ||
57 | decl_mutex_data(,lock) /* ulock lock */ | |
58 | ||
59 | struct lock_set *lock_set; /* the retaining lock set */ | |
60 | thread_act_t holder; /* thread_act that holds the lock */ | |
61 | unsigned int /* flags */ | |
62 | /* boolean_t */ blocked:1, /* did threads block waiting? */ | |
63 | /* boolean_t */ unstable:1, /* unstable? (holder died) */ | |
64 | /* boolean_t */ ho_wait:1, /* handoff thread waiting? */ | |
65 | /* boolean_t */ accept_wait:1, /* accepting thread waiting? */ | |
66 | :0; /* force to long boundary */ | |
67 | ||
68 | struct wait_queue wait_queue; /* queue of blocked threads */ | |
69 | } Ulock; | |
70 | ||
71 | typedef struct ulock *ulock_t; | |
72 | ||
73 | typedef struct lock_set { | |
74 | queue_chain_t task_link; /* chain of lock sets owned by a task */ | |
75 | decl_mutex_data(,lock) /* lock set lock */ | |
76 | task_t owner; /* task that owns the lock set */ | |
77 | ipc_port_t port; /* lock set port */ | |
78 | int ref_count; /* reference count */ | |
79 | ||
80 | boolean_t active; /* active status */ | |
81 | int n_ulocks; /* number of ulocks in the lock set */ | |
82 | ||
83 | struct ulock ulock_list[1]; /* ulock group list place holder */ | |
84 | } Lock_Set; | |
85 | ||
86 | #define ULOCK_NULL ((ulock_t) 0) | |
87 | ||
88 | #define ULOCK_FREE 0 | |
89 | #define ULOCK_HELD 1 | |
90 | ||
1c79356b A |
91 | /* |
92 | * Data structure internal lock macros | |
93 | */ | |
94 | ||
95 | #define lock_set_lock_init(ls) mutex_init(&(ls)->lock, \ | |
96 | ETAP_THREAD_LOCK_SET) | |
97 | #define lock_set_lock(ls) mutex_lock(&(ls)->lock) | |
98 | #define lock_set_unlock(ls) mutex_unlock(&(ls)->lock) | |
99 | ||
100 | #define ulock_lock_init(ul) mutex_init(&(ul)->lock, \ | |
101 | ETAP_THREAD_ULOCK) | |
102 | #define ulock_lock(ul) mutex_lock(&(ul)->lock) | |
103 | #define ulock_unlock(ul) mutex_unlock(&(ul)->lock) | |
104 | ||
105 | extern void lock_set_init(void); | |
106 | ||
9bccf70c A |
107 | extern kern_return_t lock_release_internal (ulock_t ulock, |
108 | thread_act_t thr_act); | |
109 | ||
110 | #endif /* MACH_KERNEL_PRIVATE */ | |
111 | ||
112 | #endif /* __APPLE_API_PRIVATE */ | |
113 | ||
1c79356b A |
114 | |
115 | /* | |
116 | * Forward Declarations | |
117 | */ | |
118 | ||
119 | extern kern_return_t lock_set_create (task_t task, | |
120 | lock_set_t *new_lock_set, | |
121 | int n_ulocks, | |
122 | int policy); | |
123 | ||
124 | extern kern_return_t lock_set_destroy (task_t task, | |
125 | lock_set_t lock_set); | |
126 | ||
127 | extern kern_return_t lock_acquire (lock_set_t lock_set, | |
128 | int lock_id); | |
129 | ||
130 | extern kern_return_t lock_release (lock_set_t lock_set, | |
131 | int lock_id); | |
132 | ||
133 | extern kern_return_t lock_try (lock_set_t lock_set, | |
134 | int lock_id); | |
135 | ||
136 | extern kern_return_t lock_make_stable (lock_set_t lock_set, | |
137 | int lock_id); | |
138 | ||
139 | extern kern_return_t lock_make_unstable (ulock_t ulock, | |
140 | thread_act_t thr_act); | |
141 | ||
1c79356b A |
142 | extern kern_return_t lock_handoff (lock_set_t lock_set, |
143 | int lock_id); | |
144 | ||
145 | extern kern_return_t lock_handoff_accept (lock_set_t lock_set, | |
146 | int lock_id); | |
147 | ||
148 | extern void lock_set_reference (lock_set_t lock_set); | |
149 | extern void lock_set_dereference (lock_set_t lock_set); | |
150 | ||
151 | #endif /* _KERN_SYNC_LOCK_H_ */ |