summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2014-01-03 23:54:23 +0100
committerRichard Braun <rbraun@sceen.net>2014-01-03 23:54:23 +0100
commitb53c5990ccc688e03d120c87940c7024eaca4813 (patch)
tree31f930608f9f140e6bccc8f2d5285cd3f1fb61f4
parent99cef9617922016bda314a6e21b499e17e1af56e (diff)
Update calls to atomic operations
Make spin locks and mutexes encode their state on an int rather than a long.
-rw-r--r--kern/bitmap.h6
-rw-r--r--kern/condition.c8
-rw-r--r--kern/mutex.c4
-rw-r--r--kern/mutex.h8
-rw-r--r--kern/mutex_i.h24
-rw-r--r--kern/panic.c6
-rw-r--r--kern/spinlock_i.h10
-rw-r--r--kern/thread.h6
8 files changed, 36 insertions, 36 deletions
diff --git a/kern/bitmap.h b/kern/bitmap.h
index 05741b3a..28e51c35 100644
--- a/kern/bitmap.h
+++ b/kern/bitmap.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Richard Braun.
+ * Copyright (c) 2013-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -73,7 +73,7 @@ bitmap_set_atomic(unsigned long *bm, int bit)
if (bit >= LONG_BIT)
bitmap_lookup(bm, bit);
- atomic_or(bm, bitmap_mask(bit));
+ atomic_or_ulong(bm, bitmap_mask(bit));
}
static inline void
@@ -91,7 +91,7 @@ bitmap_clear_atomic(unsigned long *bm, int bit)
if (bit >= LONG_BIT)
bitmap_lookup(bm, bit);
- atomic_and(bm, ~bitmap_mask(bit));
+ atomic_and_ulong(bm, ~bitmap_mask(bit));
}
static inline int
diff --git a/kern/condition.c b/kern/condition.c
index 85fa6106..9faab3c6 100644
--- a/kern/condition.c
+++ b/kern/condition.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Richard Braun.
+ * Copyright (c) 2013-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -35,7 +35,7 @@ void
condition_wait(struct condition *condition, struct mutex *mutex)
{
struct mutex_waiter waiter;
- unsigned long state;
+ unsigned int state;
waiter.thread = thread_self();
@@ -68,7 +68,7 @@ condition_signal(struct condition *condition)
{
struct mutex_waiter *waiter;
struct mutex *mutex;
- unsigned long state;
+ unsigned int state;
spinlock_lock(&condition->lock);
@@ -104,7 +104,7 @@ condition_broadcast(struct condition *condition)
{
struct list waiters;
struct mutex *mutex;
- unsigned long state;
+ unsigned int state;
spinlock_lock(&condition->lock);
diff --git a/kern/mutex.c b/kern/mutex.c
index e49c56c8..58e24513 100644
--- a/kern/mutex.c
+++ b/kern/mutex.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Richard Braun.
+ * Copyright (c) 2013-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@ void
mutex_lock_slow(struct mutex *mutex)
{
struct mutex_waiter waiter;
- unsigned long state;
+ unsigned int state;
spinlock_lock(&mutex->lock);
diff --git a/kern/mutex.h b/kern/mutex.h
index 08d3d304..1ed5234e 100644
--- a/kern/mutex.h
+++ b/kern/mutex.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Richard Braun.
+ * Copyright (c) 2013-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -49,7 +49,7 @@ mutex_init(struct mutex *mutex)
static inline int
mutex_trylock(struct mutex *mutex)
{
- unsigned long state;
+ unsigned int state;
state = mutex_tryacquire(mutex);
@@ -62,7 +62,7 @@ mutex_trylock(struct mutex *mutex)
static inline void
mutex_lock(struct mutex *mutex)
{
- unsigned long state;
+ unsigned int state;
state = mutex_tryacquire(mutex);
@@ -77,7 +77,7 @@ mutex_lock(struct mutex *mutex)
static inline void
mutex_unlock(struct mutex *mutex)
{
- unsigned long state;
+ unsigned int state;
state = mutex_release(mutex);
diff --git a/kern/mutex_i.h b/kern/mutex_i.h
index 2fa5cb42..85b827d8 100644
--- a/kern/mutex_i.h
+++ b/kern/mutex_i.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Richard Braun.
+ * Copyright (c) 2013-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ struct mutex_waiter {
};
struct mutex {
- unsigned long state;
+ unsigned int state;
struct spinlock lock;
struct list waiters;
};
@@ -43,24 +43,24 @@ void mutex_lock_slow(struct mutex *mutex);
void mutex_unlock_slow(struct mutex *mutex);
-static inline unsigned long
+static inline unsigned int
mutex_tryacquire(struct mutex *mutex)
{
- return atomic_cas(&mutex->state, MUTEX_UNLOCKED, MUTEX_LOCKED);
+ return atomic_cas_uint(&mutex->state, MUTEX_UNLOCKED, MUTEX_LOCKED);
}
-static inline unsigned long
+static inline unsigned int
mutex_tryacquire_slow(struct mutex *mutex)
{
- return atomic_swap(&mutex->state, MUTEX_CONTENDED);
+ return atomic_swap_uint(&mutex->state, MUTEX_CONTENDED);
}
-static inline unsigned long
+static inline unsigned int
mutex_release(struct mutex *mutex)
{
- unsigned long state;
+ unsigned int state;
- state = atomic_swap(&mutex->state, MUTEX_UNLOCKED);
+ state = atomic_swap_uint(&mutex->state, MUTEX_UNLOCKED);
assert((state == MUTEX_LOCKED) || (state == MUTEX_CONTENDED));
return state;
}
@@ -80,7 +80,7 @@ mutex_queue_list(struct mutex *mutex, struct list *waiters)
static inline void
mutex_wait(struct mutex *mutex, struct mutex_waiter *waiter)
{
- unsigned long state;
+ unsigned int state;
do {
thread_sleep(&mutex->lock);
@@ -105,9 +105,9 @@ static inline void
mutex_trydowngrade(struct mutex *mutex)
{
if (list_empty(&mutex->waiters)) {
- unsigned long state;
+ unsigned int state;
- state = atomic_swap(&mutex->state, MUTEX_LOCKED);
+ state = atomic_swap_uint(&mutex->state, MUTEX_LOCKED);
assert(state == MUTEX_CONTENDED);
}
}
diff --git a/kern/panic.c b/kern/panic.c
index bccf632b..252c4b68 100644
--- a/kern/panic.c
+++ b/kern/panic.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2012, 2013 Richard Braun.
+ * Copyright (c) 2010-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include <machine/cpu.h>
#include <machine/strace.h>
-static unsigned long panic_done;
+static unsigned int panic_done;
void
panic(const char *format, ...)
@@ -31,7 +31,7 @@ panic(const char *format, ...)
va_list list;
unsigned long already_done;
- already_done = atomic_swap(&panic_done, 1);
+ already_done = atomic_swap_uint(&panic_done, 1);
if (already_done)
for (;;)
diff --git a/kern/spinlock_i.h b/kern/spinlock_i.h
index f4d2578c..63018afa 100644
--- a/kern/spinlock_i.h
+++ b/kern/spinlock_i.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013 Richard Braun.
+ * Copyright (c) 2012-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
#include <machine/cpu.h>
struct spinlock {
- unsigned long locked;
+ unsigned int locked;
};
/*
@@ -32,7 +32,7 @@ struct spinlock {
static inline int
spinlock_tryacquire(struct spinlock *lock)
{
- return atomic_swap(&lock->locked, 1);
+ return atomic_swap_uint(&lock->locked, 1);
}
static inline void
@@ -45,9 +45,9 @@ spinlock_acquire(struct spinlock *lock)
static inline void
spinlock_release(struct spinlock *lock)
{
- unsigned long locked;
+ unsigned int locked;
- locked = atomic_swap(&lock->locked, 0);
+ locked = atomic_swap_uint(&lock->locked, 0);
assert(locked);
}
diff --git a/kern/thread.h b/kern/thread.h
index dca1a698..31e837e5 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2013 Richard Braun.
+ * Copyright (c) 2012-2014 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -273,13 +273,13 @@ thread_self(void)
static inline void
thread_set_flag(struct thread *thread, unsigned long flag)
{
- atomic_or(&thread->flags, flag);
+ atomic_or_ulong(&thread->flags, flag);
}
static inline void
thread_clear_flag(struct thread *thread, unsigned long flag)
{
- atomic_and(&thread->flags, ~flag);
+ atomic_and_ulong(&thread->flags, ~flag);
}
static inline int