1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
From 96393b1a0885751365781c59cae792897c065c1e Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Sat, 18 Jul 2015 16:55:12 +0200
Subject: [PATCH gnumach 02/10] yyy more general locks, crashes, maybe b/c
interrupt handler
---
device/kmsg.c | 43 +++++++++++++++++++++++--------------------
ipc/ipc_object.h | 10 +++++-----
kern/processor.c | 2 +-
kern/processor.h | 7 ++++---
4 files changed, 33 insertions(+), 29 deletions(-)
diff --git a/device/kmsg.c b/device/kmsg.c
index c80775d..dbf6b8a 100644
--- a/device/kmsg.c
+++ b/device/kmsg.c
@@ -44,7 +44,10 @@ static queue_head_t kmsg_read_queue;
/* Used for exclusive access to the device */
static boolean_t kmsg_in_use;
/* Used for exclusive access to the routines */
-decl_simple_lock_data (static, kmsg_lock);
+static struct lock kmsg_lock_data;
+#define kmsg_lock_init() lock_init (&kmsg_lock_data, FALSE)
+#define kmsg_lock() lock_write (&kmsg_lock_data)
+#define kmsg_unlock() lock_write_done (&kmsg_lock_data)
/* If already initialized or not */
static boolean_t kmsg_init_done = FALSE;
@@ -56,23 +59,23 @@ kmsginit (void)
kmsg_read_offset = 0;
queue_init (&kmsg_read_queue);
kmsg_in_use = FALSE;
- simple_lock_init (&kmsg_lock);
+ kmsg_lock_init ();
}
/* Kernel Message Open Handler */
io_return_t
kmsgopen (dev_t dev, int flag, const io_req_t ior)
{
- simple_lock (&kmsg_lock);
+ kmsg_lock ();
if (kmsg_in_use)
{
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
return D_ALREADY_OPEN;
}
kmsg_in_use = TRUE;
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
return D_SUCCESS;
}
@@ -80,10 +83,10 @@ kmsgopen (dev_t dev, int flag, const io_req_t ior)
void
kmsgclose (dev_t dev, int flag)
{
- simple_lock (&kmsg_lock);
+ kmsg_lock ();
kmsg_in_use = FALSE;
-
- simple_unlock (&kmsg_lock);
+
+ kmsg_unlock ();
}
static boolean_t kmsg_read_done (io_req_t ior);
@@ -99,19 +102,19 @@ kmsgread (dev_t dev, io_req_t ior)
if (err != KERN_SUCCESS)
return err;
- simple_lock (&kmsg_lock);
+ kmsg_lock ();
if (kmsg_read_offset == kmsg_write_offset)
{
/* The queue is empty. */
if (ior->io_mode & D_NOWAIT)
{
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
return D_WOULD_BLOCK;
}
ior->io_done = kmsg_read_done;
enqueue_tail (&kmsg_read_queue, (queue_entry_t) ior);
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
return D_IO_QUEUED;
}
@@ -141,8 +144,8 @@ kmsgread (dev_t dev, io_req_t ior)
kmsg_read_offset -= KMSGBUFSIZE;
ior->io_residual = ior->io_count - amt;
-
- simple_unlock (&kmsg_lock);
+
+ kmsg_unlock ();
return D_SUCCESS;
}
@@ -151,13 +154,13 @@ kmsg_read_done (io_req_t ior)
{
int amt, len;
- simple_lock (&kmsg_lock);
+ kmsg_lock ();
if (kmsg_read_offset == kmsg_write_offset)
{
/* The queue is empty. */
ior->io_done = kmsg_read_done;
enqueue_tail (&kmsg_read_queue, (queue_entry_t) ior);
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
return FALSE;
}
@@ -188,7 +191,7 @@ kmsg_read_done (io_req_t ior)
ior->io_residual = ior->io_count - amt;
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
ds_read_done (ior);
return TRUE;
@@ -226,8 +229,8 @@ kmsg_putchar (int c)
kmsginit ();
kmsg_init_done = TRUE;
}
-
- simple_lock (&kmsg_lock);
+
+ kmsg_lock ();
offset = kmsg_write_offset + 1;
if (offset == KMSGBUFSIZE)
offset = 0;
@@ -235,7 +238,7 @@ kmsg_putchar (int c)
if (offset == kmsg_read_offset)
{
/* Discard C. */
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
return;
}
@@ -246,5 +249,5 @@ kmsg_putchar (int c)
while ((ior = (io_req_t) dequeue_head (&kmsg_read_queue)) != NULL)
iodone (ior);
- simple_unlock (&kmsg_lock);
+ kmsg_unlock ();
}
diff --git a/ipc/ipc_object.h b/ipc/ipc_object.h
index be5bea7..8504a23 100644
--- a/ipc/ipc_object.h
+++ b/ipc/ipc_object.h
@@ -46,7 +46,7 @@ typedef unsigned int ipc_object_bits_t;
typedef unsigned int ipc_object_type_t;
typedef struct ipc_object {
- decl_simple_lock_data(,io_lock_data)
+ struct lock io_lock_data;
ipc_object_refs_t io_references;
ipc_object_bits_t io_bits;
} *ipc_object_t;
@@ -85,10 +85,10 @@ extern struct kmem_cache ipc_object_caches[IOT_NUMBER];
#define io_free(otype, io) \
kmem_cache_free(&ipc_object_caches[(otype)], (vm_offset_t) (io))
-#define io_lock_init(io) simple_lock_init(&(io)->io_lock_data)
-#define io_lock(io) simple_lock(&(io)->io_lock_data)
-#define io_lock_try(io) simple_lock_try(&(io)->io_lock_data)
-#define io_unlock(io) simple_unlock(&(io)->io_lock_data)
+#define io_lock_init(io) lock_init(&(io)->io_lock_data, TRUE)
+#define io_lock(io) lock_write(&(io)->io_lock_data)
+#define io_lock_try(io) lock_try_write(&(io)->io_lock_data)
+#define io_unlock(io) lock_write_done(&(io)->io_lock_data)
#define io_check_unlock(io) \
MACRO_BEGIN \
diff --git a/kern/processor.c b/kern/processor.c
index 48e9273..a7c3fbf 100644
--- a/kern/processor.c
+++ b/kern/processor.c
@@ -155,7 +155,7 @@ void pset_init(
simple_lock_init(&pset->ref_lock);
queue_init(&pset->all_psets);
pset->active = FALSE;
- simple_lock_init(&pset->lock);
+ pset_lock_init (pset);
pset->pset_self = IP_NULL;
pset->pset_name_self = IP_NULL;
pset->max_priority = BASEPRI_USER;
diff --git a/kern/processor.h b/kern/processor.h
index b81526c..69ddf87 100644
--- a/kern/processor.h
+++ b/kern/processor.h
@@ -68,7 +68,7 @@ struct processor_set {
decl_simple_lock_data(, ref_lock) /* lock for ref count */
queue_chain_t all_psets; /* link for all_psets */
boolean_t active; /* is pset in use */
- decl_simple_lock_data(, lock) /* lock for everything else */
+ struct lock lock; /* lock for everything else */
struct ipc_port * pset_self; /* port for operations */
struct ipc_port * pset_name_self; /* port for information */
int max_priority; /* maximum priority */
@@ -216,8 +216,9 @@ extern processor_t processor_ptr[NCPUS];
/* Useful lock macros */
-#define pset_lock(pset) simple_lock(&(pset)->lock)
-#define pset_unlock(pset) simple_unlock(&(pset)->lock)
+#define pset_lock_init(pset) lock_init(&(pset)->lock, FALSE)
+#define pset_lock(pset) lock_write(&(pset)->lock)
+#define pset_unlock(pset) lock_write_done(&(pset)->lock)
#define pset_ref_lock(pset) simple_lock(&(pset)->ref_lock)
#define pset_ref_unlock(pset) simple_unlock(&(pset)->ref_lock)
--
2.1.4
|