summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2015-07-18 16:55:12 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2015-09-14 14:45:05 +0200
commitcda08b5e2da61270696b86dad11df281120bf6f6 (patch)
tree36237e273030a1eaf1b0c580381ca7e132dffb21
parent7e8ae7880a9e752884c7bcb674e6d1e7c1f325d4 (diff)
yyy more general locks, crashes, maybe b/c interrupt handler
-rw-r--r--device/kmsg.c43
-rw-r--r--ipc/ipc_object.h10
-rw-r--r--kern/processor.c2
-rw-r--r--kern/processor.h7
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)