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