2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
30 * File: kern/sync_lock.h
31 * Author: Joseph CaraDonna
33 * Contains RT distributed lock synchronization service definitions.
36 #ifndef _KERN_SYNC_LOCK_H_
37 #define _KERN_SYNC_LOCK_H_
39 #include <mach/mach_types.h>
41 #include <sys/appleapiopts.h>
43 #ifdef __APPLE_API_PRIVATE
45 #ifdef MACH_KERNEL_PRIVATE
47 #include <kern/wait_queue.h>
48 #include <kern/macro_help.h>
49 #include <kern/queue.h>
50 #include <kern/lock.h>
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 */
57 decl_mutex_data(,lock
) /* ulock lock */
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 */
68 struct wait_queue wait_queue
; /* queue of blocked threads */
71 typedef struct ulock
*ulock_t
;
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 */
80 boolean_t active
; /* active status */
81 int n_ulocks
; /* number of ulocks in the lock set */
83 struct ulock ulock_list
[1]; /* ulock group list place holder */
86 #define ULOCK_NULL ((ulock_t) 0)
92 * Data structure internal lock macros
95 #define lock_set_lock_init(ls) mutex_init(&(ls)->lock, \
97 #define lock_set_lock(ls) mutex_lock(&(ls)->lock)
98 #define lock_set_unlock(ls) mutex_unlock(&(ls)->lock)
100 #define ulock_lock_init(ul) mutex_init(&(ul)->lock, \
102 #define ulock_lock(ul) mutex_lock(&(ul)->lock)
103 #define ulock_unlock(ul) mutex_unlock(&(ul)->lock)
105 extern void lock_set_init(void);
107 extern kern_return_t
lock_release_internal (ulock_t ulock
,
108 thread_act_t thr_act
);
110 #endif /* MACH_KERNEL_PRIVATE */
112 #endif /* __APPLE_API_PRIVATE */
116 * Forward Declarations
119 extern kern_return_t
lock_set_create (task_t task
,
120 lock_set_t
*new_lock_set
,
124 extern kern_return_t
lock_set_destroy (task_t task
,
125 lock_set_t lock_set
);
127 extern kern_return_t
lock_acquire (lock_set_t lock_set
,
130 extern kern_return_t
lock_release (lock_set_t lock_set
,
133 extern kern_return_t
lock_try (lock_set_t lock_set
,
136 extern kern_return_t
lock_make_stable (lock_set_t lock_set
,
139 extern kern_return_t
lock_make_unstable (ulock_t ulock
,
140 thread_act_t thr_act
);
142 extern kern_return_t
lock_handoff (lock_set_t lock_set
,
145 extern kern_return_t
lock_handoff_accept (lock_set_t lock_set
,
148 extern void lock_set_reference (lock_set_t lock_set
);
149 extern void lock_set_dereference (lock_set_t lock_set
);
151 #endif /* _KERN_SYNC_LOCK_H_ */