clang-format
This commit is contained in:
@@ -50,8 +50,8 @@
|
||||
* Timing constants. These should be tuned along with any work done on
|
||||
* the scheduler.
|
||||
*/
|
||||
#define SCHEDULE_HARDCLOCKS 4 /* Reschedule every 4 hardclocks. */
|
||||
#define MIGRATE_HARDCLOCKS 16 /* Migrate every 16 hardclocks. */
|
||||
#define SCHEDULE_HARDCLOCKS 4 /* Reschedule every 4 hardclocks. */
|
||||
#define MIGRATE_HARDCLOCKS 16 /* Migrate every 16 hardclocks. */
|
||||
|
||||
/*
|
||||
* Once a second, everything waiting on lbolt is awakened by CPU 0.
|
||||
@@ -62,60 +62,52 @@ static struct spinlock lbolt_lock;
|
||||
/*
|
||||
* Setup.
|
||||
*/
|
||||
void
|
||||
hardclock_bootstrap(void)
|
||||
{
|
||||
spinlock_init(&lbolt_lock);
|
||||
lbolt = wchan_create("lbolt");
|
||||
if (lbolt == NULL) {
|
||||
panic("Couldn't create lbolt\n");
|
||||
}
|
||||
void hardclock_bootstrap(void) {
|
||||
spinlock_init(&lbolt_lock);
|
||||
lbolt = wchan_create("lbolt");
|
||||
if (lbolt == NULL) {
|
||||
panic("Couldn't create lbolt\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called once per second, on one processor, by the timer
|
||||
* code.
|
||||
*/
|
||||
void
|
||||
timerclock(void)
|
||||
{
|
||||
/* Just broadcast on lbolt */
|
||||
spinlock_acquire(&lbolt_lock);
|
||||
wchan_wakeall(lbolt, &lbolt_lock);
|
||||
spinlock_release(&lbolt_lock);
|
||||
void timerclock(void) {
|
||||
/* Just broadcast on lbolt */
|
||||
spinlock_acquire(&lbolt_lock);
|
||||
wchan_wakeall(lbolt, &lbolt_lock);
|
||||
spinlock_release(&lbolt_lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is called HZ times a second (on each processor) by the timer
|
||||
* code.
|
||||
*/
|
||||
void
|
||||
hardclock(void)
|
||||
{
|
||||
/*
|
||||
* Collect statistics here as desired.
|
||||
*/
|
||||
void hardclock(void) {
|
||||
/*
|
||||
* Collect statistics here as desired.
|
||||
*/
|
||||
|
||||
curcpu->c_hardclocks++;
|
||||
if ((curcpu->c_hardclocks % MIGRATE_HARDCLOCKS) == 0) {
|
||||
thread_consider_migration();
|
||||
}
|
||||
if ((curcpu->c_hardclocks % SCHEDULE_HARDCLOCKS) == 0) {
|
||||
schedule();
|
||||
}
|
||||
thread_yield();
|
||||
curcpu->c_hardclocks++;
|
||||
if ((curcpu->c_hardclocks % MIGRATE_HARDCLOCKS) == 0) {
|
||||
thread_consider_migration();
|
||||
}
|
||||
if ((curcpu->c_hardclocks % SCHEDULE_HARDCLOCKS) == 0) {
|
||||
schedule();
|
||||
}
|
||||
thread_yield();
|
||||
}
|
||||
|
||||
/*
|
||||
* Suspend execution for n seconds.
|
||||
*/
|
||||
void
|
||||
clocksleep(int num_secs)
|
||||
{
|
||||
spinlock_acquire(&lbolt_lock);
|
||||
while (num_secs > 0) {
|
||||
wchan_sleep(lbolt, &lbolt_lock);
|
||||
num_secs--;
|
||||
}
|
||||
spinlock_release(&lbolt_lock);
|
||||
void clocksleep(int num_secs) {
|
||||
spinlock_acquire(&lbolt_lock);
|
||||
while (num_secs > 0) {
|
||||
wchan_sleep(lbolt, &lbolt_lock);
|
||||
num_secs--;
|
||||
}
|
||||
spinlock_release(&lbolt_lock);
|
||||
}
|
||||
|
||||
@@ -47,50 +47,47 @@ static struct spinlock hangman_lock = SPINLOCK_INITIALIZER;
|
||||
* only be waiting for one thing at a time, this turns out to be
|
||||
* quite simple.
|
||||
*/
|
||||
static
|
||||
void
|
||||
hangman_check(const struct hangman_lockable *start,
|
||||
const struct hangman_actor *target)
|
||||
{
|
||||
const struct hangman_actor *cur;
|
||||
static void hangman_check(const struct hangman_lockable *start,
|
||||
const struct hangman_actor *target) {
|
||||
const struct hangman_actor *cur;
|
||||
|
||||
cur = start->l_holding;
|
||||
while (cur != NULL) {
|
||||
if (cur == target) {
|
||||
goto found;
|
||||
}
|
||||
if (cur->a_waiting == NULL) {
|
||||
break;
|
||||
}
|
||||
cur = cur->a_waiting->l_holding;
|
||||
}
|
||||
return;
|
||||
cur = start->l_holding;
|
||||
while (cur != NULL) {
|
||||
if (cur == target) {
|
||||
goto found;
|
||||
}
|
||||
if (cur->a_waiting == NULL) {
|
||||
break;
|
||||
}
|
||||
cur = cur->a_waiting->l_holding;
|
||||
}
|
||||
return;
|
||||
|
||||
found:
|
||||
/*
|
||||
* None of this can change while we print it (that's the point
|
||||
* of it being a deadlock) so drop hangman_lock while
|
||||
* printing; otherwise we can come back via kprintf_spinlock
|
||||
* and that makes a mess. But force splhigh() explicitly so
|
||||
* the console prints in polled mode and to discourage other
|
||||
* things from running in the middle of the printout.
|
||||
*/
|
||||
splhigh();
|
||||
spinlock_release(&hangman_lock);
|
||||
found:
|
||||
/*
|
||||
* None of this can change while we print it (that's the point
|
||||
* of it being a deadlock) so drop hangman_lock while
|
||||
* printing; otherwise we can come back via kprintf_spinlock
|
||||
* and that makes a mess. But force splhigh() explicitly so
|
||||
* the console prints in polled mode and to discourage other
|
||||
* things from running in the middle of the printout.
|
||||
*/
|
||||
splhigh();
|
||||
spinlock_release(&hangman_lock);
|
||||
|
||||
kprintf("hangman: Detected lock cycle!\n");
|
||||
kprintf("hangman: in %s (%p);\n", target->a_name, target);
|
||||
kprintf("hangman: waiting for %s (%p), but:\n", start->l_name, start);
|
||||
kprintf(" lockable %s (%p)\n", start->l_name, start);
|
||||
cur = start->l_holding;
|
||||
while (cur != target) {
|
||||
kprintf(" held by actor %s (%p)\n", cur->a_name, cur);
|
||||
kprintf(" waiting for lockable %s (%p)\n",
|
||||
cur->a_waiting->l_name, cur->a_waiting);
|
||||
cur = cur->a_waiting->l_holding;
|
||||
}
|
||||
kprintf(" held by actor %s (%p)\n", cur->a_name, cur);
|
||||
panic("Deadlock.\n");
|
||||
kprintf("hangman: Detected lock cycle!\n");
|
||||
kprintf("hangman: in %s (%p);\n", target->a_name, target);
|
||||
kprintf("hangman: waiting for %s (%p), but:\n", start->l_name, start);
|
||||
kprintf(" lockable %s (%p)\n", start->l_name, start);
|
||||
cur = start->l_holding;
|
||||
while (cur != target) {
|
||||
kprintf(" held by actor %s (%p)\n", cur->a_name, cur);
|
||||
kprintf(" waiting for lockable %s (%p)\n", cur->a_waiting->l_name,
|
||||
cur->a_waiting);
|
||||
cur = cur->a_waiting->l_holding;
|
||||
}
|
||||
kprintf(" held by actor %s (%p)\n", cur->a_name, cur);
|
||||
panic("Deadlock.\n");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -106,77 +103,67 @@ hangman_check(const struct hangman_lockable *start,
|
||||
* tricky and problematic. For now we'll settle for just detecting and
|
||||
* reporting deadlocks that do happen.
|
||||
*/
|
||||
void
|
||||
hangman_wait(struct hangman_actor *a,
|
||||
struct hangman_lockable *l)
|
||||
{
|
||||
if (l == &hangman_lock.splk_hangman) {
|
||||
/* don't recurse */
|
||||
return;
|
||||
}
|
||||
void hangman_wait(struct hangman_actor *a, struct hangman_lockable *l) {
|
||||
if (l == &hangman_lock.splk_hangman) {
|
||||
/* don't recurse */
|
||||
return;
|
||||
}
|
||||
|
||||
spinlock_acquire(&hangman_lock);
|
||||
spinlock_acquire(&hangman_lock);
|
||||
|
||||
if (a->a_waiting != NULL) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_wait: already waiting for something?\n");
|
||||
}
|
||||
if (a->a_waiting != NULL) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_wait: already waiting for something?\n");
|
||||
}
|
||||
|
||||
hangman_check(l, a);
|
||||
a->a_waiting = l;
|
||||
hangman_check(l, a);
|
||||
a->a_waiting = l;
|
||||
|
||||
spinlock_release(&hangman_lock);
|
||||
spinlock_release(&hangman_lock);
|
||||
}
|
||||
|
||||
void
|
||||
hangman_acquire(struct hangman_actor *a,
|
||||
struct hangman_lockable *l)
|
||||
{
|
||||
if (l == &hangman_lock.splk_hangman) {
|
||||
/* don't recurse */
|
||||
return;
|
||||
}
|
||||
void hangman_acquire(struct hangman_actor *a, struct hangman_lockable *l) {
|
||||
if (l == &hangman_lock.splk_hangman) {
|
||||
/* don't recurse */
|
||||
return;
|
||||
}
|
||||
|
||||
spinlock_acquire(&hangman_lock);
|
||||
spinlock_acquire(&hangman_lock);
|
||||
|
||||
if (a->a_waiting != l) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_acquire: not waiting for lock %s (%p)\n",
|
||||
l->l_name, l);
|
||||
}
|
||||
if (l->l_holding != NULL) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_acquire: lock %s (%p) still held by %s (%p)\n",
|
||||
l->l_name, l, a->a_name, a);
|
||||
}
|
||||
if (a->a_waiting != l) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_acquire: not waiting for lock %s (%p)\n", l->l_name, l);
|
||||
}
|
||||
if (l->l_holding != NULL) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_acquire: lock %s (%p) still held by %s (%p)\n", l->l_name, l,
|
||||
a->a_name, a);
|
||||
}
|
||||
|
||||
l->l_holding = a;
|
||||
a->a_waiting = NULL;
|
||||
l->l_holding = a;
|
||||
a->a_waiting = NULL;
|
||||
|
||||
spinlock_release(&hangman_lock);
|
||||
spinlock_release(&hangman_lock);
|
||||
}
|
||||
|
||||
void
|
||||
hangman_release(struct hangman_actor *a,
|
||||
struct hangman_lockable *l)
|
||||
{
|
||||
if (l == &hangman_lock.splk_hangman) {
|
||||
/* don't recurse */
|
||||
return;
|
||||
}
|
||||
void hangman_release(struct hangman_actor *a, struct hangman_lockable *l) {
|
||||
if (l == &hangman_lock.splk_hangman) {
|
||||
/* don't recurse */
|
||||
return;
|
||||
}
|
||||
|
||||
spinlock_acquire(&hangman_lock);
|
||||
spinlock_acquire(&hangman_lock);
|
||||
|
||||
if (a->a_waiting != NULL) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_release: waiting for something?\n");
|
||||
}
|
||||
if (l->l_holding != a) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_release: not the holder\n");
|
||||
}
|
||||
if (a->a_waiting != NULL) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_release: waiting for something?\n");
|
||||
}
|
||||
if (l->l_holding != a) {
|
||||
spinlock_release(&hangman_lock);
|
||||
panic("hangman_release: not the holder\n");
|
||||
}
|
||||
|
||||
l->l_holding = NULL;
|
||||
l->l_holding = NULL;
|
||||
|
||||
spinlock_release(&hangman_lock);
|
||||
spinlock_release(&hangman_lock);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
*/
|
||||
|
||||
/* Make sure to build out-of-line versions of inline functions */
|
||||
#define SPINLOCK_INLINE /* empty */
|
||||
#define MEMBAR_INLINE /* empty */
|
||||
#define SPINLOCK_INLINE /* empty */
|
||||
#define MEMBAR_INLINE /* empty */
|
||||
|
||||
#include <types.h>
|
||||
#include <lib.h>
|
||||
@@ -37,32 +37,27 @@
|
||||
#include <spl.h>
|
||||
#include <spinlock.h>
|
||||
#include <membar.h>
|
||||
#include <current.h> /* for curcpu */
|
||||
#include <current.h> /* for curcpu */
|
||||
|
||||
/*
|
||||
* Spinlocks.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Initialize spinlock.
|
||||
*/
|
||||
void
|
||||
spinlock_init(struct spinlock *splk)
|
||||
{
|
||||
spinlock_data_set(&splk->splk_lock, 0);
|
||||
splk->splk_holder = NULL;
|
||||
HANGMAN_LOCKABLEINIT(&splk->splk_hangman, "spinlock");
|
||||
void spinlock_init(struct spinlock *splk) {
|
||||
spinlock_data_set(&splk->splk_lock, 0);
|
||||
splk->splk_holder = NULL;
|
||||
HANGMAN_LOCKABLEINIT(&splk->splk_hangman, "spinlock");
|
||||
}
|
||||
|
||||
/*
|
||||
* Clean up spinlock.
|
||||
*/
|
||||
void
|
||||
spinlock_cleanup(struct spinlock *splk)
|
||||
{
|
||||
KASSERT(splk->splk_holder == NULL);
|
||||
KASSERT(spinlock_data_get(&splk->splk_lock) == 0);
|
||||
void spinlock_cleanup(struct spinlock *splk) {
|
||||
KASSERT(splk->splk_holder == NULL);
|
||||
KASSERT(spinlock_data_get(&splk->splk_lock) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -72,85 +67,78 @@ spinlock_cleanup(struct spinlock *splk)
|
||||
* might come back to this lock and deadlock), then use a machine-level
|
||||
* atomic operation to wait for the lock to be free.
|
||||
*/
|
||||
void
|
||||
spinlock_acquire(struct spinlock *splk)
|
||||
{
|
||||
struct cpu *mycpu;
|
||||
void spinlock_acquire(struct spinlock *splk) {
|
||||
struct cpu *mycpu;
|
||||
|
||||
splraise(IPL_NONE, IPL_HIGH);
|
||||
splraise(IPL_NONE, IPL_HIGH);
|
||||
|
||||
/* this must work before curcpu initialization */
|
||||
if (CURCPU_EXISTS()) {
|
||||
mycpu = curcpu->c_self;
|
||||
if (splk->splk_holder == mycpu) {
|
||||
panic("Deadlock on spinlock %p\n", splk);
|
||||
}
|
||||
mycpu->c_spinlocks++;
|
||||
/* this must work before curcpu initialization */
|
||||
if (CURCPU_EXISTS()) {
|
||||
mycpu = curcpu->c_self;
|
||||
if (splk->splk_holder == mycpu) {
|
||||
panic("Deadlock on spinlock %p\n", splk);
|
||||
}
|
||||
mycpu->c_spinlocks++;
|
||||
|
||||
HANGMAN_WAIT(&curcpu->c_hangman, &splk->splk_hangman);
|
||||
}
|
||||
else {
|
||||
mycpu = NULL;
|
||||
}
|
||||
HANGMAN_WAIT(&curcpu->c_hangman, &splk->splk_hangman);
|
||||
} else {
|
||||
mycpu = NULL;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
/*
|
||||
* Do test-test-and-set, that is, read first before
|
||||
* doing test-and-set, to reduce bus contention.
|
||||
*
|
||||
* Test-and-set is a machine-level atomic operation
|
||||
* that writes 1 into the lock word and returns the
|
||||
* previous value. If that value was 0, the lock was
|
||||
* previously unheld and we now own it. If it was 1,
|
||||
* we don't.
|
||||
*/
|
||||
if (spinlock_data_get(&splk->splk_lock) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (spinlock_data_testandset(&splk->splk_lock) != 0) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
while (1) {
|
||||
/*
|
||||
* Do test-test-and-set, that is, read first before
|
||||
* doing test-and-set, to reduce bus contention.
|
||||
*
|
||||
* Test-and-set is a machine-level atomic operation
|
||||
* that writes 1 into the lock word and returns the
|
||||
* previous value. If that value was 0, the lock was
|
||||
* previously unheld and we now own it. If it was 1,
|
||||
* we don't.
|
||||
*/
|
||||
if (spinlock_data_get(&splk->splk_lock) != 0) {
|
||||
continue;
|
||||
}
|
||||
if (spinlock_data_testandset(&splk->splk_lock) != 0) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
membar_store_any();
|
||||
splk->splk_holder = mycpu;
|
||||
membar_store_any();
|
||||
splk->splk_holder = mycpu;
|
||||
|
||||
if (CURCPU_EXISTS()) {
|
||||
HANGMAN_ACQUIRE(&curcpu->c_hangman, &splk->splk_hangman);
|
||||
}
|
||||
if (CURCPU_EXISTS()) {
|
||||
HANGMAN_ACQUIRE(&curcpu->c_hangman, &splk->splk_hangman);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Release the lock.
|
||||
*/
|
||||
void
|
||||
spinlock_release(struct spinlock *splk)
|
||||
{
|
||||
/* this must work before curcpu initialization */
|
||||
if (CURCPU_EXISTS()) {
|
||||
KASSERT(splk->splk_holder == curcpu->c_self);
|
||||
KASSERT(curcpu->c_spinlocks > 0);
|
||||
curcpu->c_spinlocks--;
|
||||
HANGMAN_RELEASE(&curcpu->c_hangman, &splk->splk_hangman);
|
||||
}
|
||||
void spinlock_release(struct spinlock *splk) {
|
||||
/* this must work before curcpu initialization */
|
||||
if (CURCPU_EXISTS()) {
|
||||
KASSERT(splk->splk_holder == curcpu->c_self);
|
||||
KASSERT(curcpu->c_spinlocks > 0);
|
||||
curcpu->c_spinlocks--;
|
||||
HANGMAN_RELEASE(&curcpu->c_hangman, &splk->splk_hangman);
|
||||
}
|
||||
|
||||
splk->splk_holder = NULL;
|
||||
membar_any_store();
|
||||
spinlock_data_set(&splk->splk_lock, 0);
|
||||
spllower(IPL_HIGH, IPL_NONE);
|
||||
splk->splk_holder = NULL;
|
||||
membar_any_store();
|
||||
spinlock_data_set(&splk->splk_lock, 0);
|
||||
spllower(IPL_HIGH, IPL_NONE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the current cpu holds the lock.
|
||||
*/
|
||||
bool
|
||||
spinlock_do_i_hold(struct spinlock *splk)
|
||||
{
|
||||
if (!CURCPU_EXISTS()) {
|
||||
return true;
|
||||
}
|
||||
bool spinlock_do_i_hold(struct spinlock *splk) {
|
||||
if (!CURCPU_EXISTS()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Assume we can read splk_holder atomically enough for this to work */
|
||||
return (splk->splk_holder == curcpu->c_self);
|
||||
/* Assume we can read splk_holder atomically enough for this to work */
|
||||
return (splk->splk_holder == curcpu->c_self);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
/* Make sure to build out-of-line versions of spl inline functions */
|
||||
#define SPL_INLINE /* empty */
|
||||
#define SPL_INLINE /* empty */
|
||||
|
||||
#include <types.h>
|
||||
#include <lib.h>
|
||||
@@ -54,7 +54,6 @@
|
||||
* complicated -- but nearly all of this code could remain MI.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Raise and lower the interrupt priority level.
|
||||
*
|
||||
@@ -83,78 +82,69 @@
|
||||
*
|
||||
* curthread->t_iplhigh_count is used to track this.
|
||||
*/
|
||||
void
|
||||
splraise(int oldspl, int newspl)
|
||||
{
|
||||
struct thread *cur = curthread;
|
||||
void splraise(int oldspl, int newspl) {
|
||||
struct thread *cur = curthread;
|
||||
|
||||
/* only one priority level, only one valid args configuration */
|
||||
KASSERT(oldspl == IPL_NONE);
|
||||
KASSERT(newspl == IPL_HIGH);
|
||||
/* only one priority level, only one valid args configuration */
|
||||
KASSERT(oldspl == IPL_NONE);
|
||||
KASSERT(newspl == IPL_HIGH);
|
||||
|
||||
if (!CURCPU_EXISTS()) {
|
||||
/* before curcpu initialization; interrupts are off anyway */
|
||||
return;
|
||||
}
|
||||
if (!CURCPU_EXISTS()) {
|
||||
/* before curcpu initialization; interrupts are off anyway */
|
||||
return;
|
||||
}
|
||||
|
||||
if (cur->t_iplhigh_count == 0) {
|
||||
cpu_irqoff();
|
||||
}
|
||||
cur->t_iplhigh_count++;
|
||||
if (cur->t_iplhigh_count == 0) {
|
||||
cpu_irqoff();
|
||||
}
|
||||
cur->t_iplhigh_count++;
|
||||
}
|
||||
|
||||
void
|
||||
spllower(int oldspl, int newspl)
|
||||
{
|
||||
struct thread *cur = curthread;
|
||||
void spllower(int oldspl, int newspl) {
|
||||
struct thread *cur = curthread;
|
||||
|
||||
/* only one priority level, only one valid args configuration */
|
||||
KASSERT(oldspl == IPL_HIGH);
|
||||
KASSERT(newspl == IPL_NONE);
|
||||
/* only one priority level, only one valid args configuration */
|
||||
KASSERT(oldspl == IPL_HIGH);
|
||||
KASSERT(newspl == IPL_NONE);
|
||||
|
||||
if (!CURCPU_EXISTS()) {
|
||||
/* before curcpu initialization; interrupts are off anyway */
|
||||
return;
|
||||
}
|
||||
if (!CURCPU_EXISTS()) {
|
||||
/* before curcpu initialization; interrupts are off anyway */
|
||||
return;
|
||||
}
|
||||
|
||||
cur->t_iplhigh_count--;
|
||||
if (cur->t_iplhigh_count == 0) {
|
||||
cpu_irqon();
|
||||
}
|
||||
cur->t_iplhigh_count--;
|
||||
if (cur->t_iplhigh_count == 0) {
|
||||
cpu_irqon();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Disable or enable interrupts and adjust curspl setting. Return old
|
||||
* spl level.
|
||||
*/
|
||||
int
|
||||
splx(int spl)
|
||||
{
|
||||
struct thread *cur = curthread;
|
||||
int ret;
|
||||
int splx(int spl) {
|
||||
struct thread *cur = curthread;
|
||||
int ret;
|
||||
|
||||
if (!CURCPU_EXISTS()) {
|
||||
/* before curcpu initialization; interrupts are off anyway */
|
||||
return spl;
|
||||
}
|
||||
if (!CURCPU_EXISTS()) {
|
||||
/* before curcpu initialization; interrupts are off anyway */
|
||||
return spl;
|
||||
}
|
||||
|
||||
if (cur->t_curspl < spl) {
|
||||
/* turning interrupts off */
|
||||
splraise(cur->t_curspl, spl);
|
||||
ret = cur->t_curspl;
|
||||
cur->t_curspl = spl;
|
||||
}
|
||||
else if (cur->t_curspl > spl) {
|
||||
/* turning interrupts on */
|
||||
ret = cur->t_curspl;
|
||||
cur->t_curspl = spl;
|
||||
spllower(ret, spl);
|
||||
}
|
||||
else {
|
||||
/* do nothing */
|
||||
ret = spl;
|
||||
}
|
||||
if (cur->t_curspl < spl) {
|
||||
/* turning interrupts off */
|
||||
splraise(cur->t_curspl, spl);
|
||||
ret = cur->t_curspl;
|
||||
cur->t_curspl = spl;
|
||||
} else if (cur->t_curspl > spl) {
|
||||
/* turning interrupts on */
|
||||
ret = cur->t_curspl;
|
||||
cur->t_curspl = spl;
|
||||
spllower(ret, spl);
|
||||
} else {
|
||||
/* do nothing */
|
||||
ret = spl;
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -44,226 +44,197 @@
|
||||
//
|
||||
// Semaphore.
|
||||
|
||||
struct semaphore *
|
||||
sem_create(const char *name, unsigned initial_count)
|
||||
{
|
||||
struct semaphore *sem;
|
||||
struct semaphore *sem_create(const char *name, unsigned initial_count) {
|
||||
struct semaphore *sem;
|
||||
|
||||
sem = kmalloc(sizeof(*sem));
|
||||
if (sem == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
sem = kmalloc(sizeof(*sem));
|
||||
if (sem == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sem->sem_name = kstrdup(name);
|
||||
if (sem->sem_name == NULL) {
|
||||
kfree(sem);
|
||||
return NULL;
|
||||
}
|
||||
sem->sem_name = kstrdup(name);
|
||||
if (sem->sem_name == NULL) {
|
||||
kfree(sem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sem->sem_wchan = wchan_create(sem->sem_name);
|
||||
if (sem->sem_wchan == NULL) {
|
||||
kfree(sem->sem_name);
|
||||
kfree(sem);
|
||||
return NULL;
|
||||
}
|
||||
sem->sem_wchan = wchan_create(sem->sem_name);
|
||||
if (sem->sem_wchan == NULL) {
|
||||
kfree(sem->sem_name);
|
||||
kfree(sem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
spinlock_init(&sem->sem_lock);
|
||||
sem->sem_count = initial_count;
|
||||
spinlock_init(&sem->sem_lock);
|
||||
sem->sem_count = initial_count;
|
||||
|
||||
return sem;
|
||||
return sem;
|
||||
}
|
||||
|
||||
void
|
||||
sem_destroy(struct semaphore *sem)
|
||||
{
|
||||
KASSERT(sem != NULL);
|
||||
void sem_destroy(struct semaphore *sem) {
|
||||
KASSERT(sem != NULL);
|
||||
|
||||
/* wchan_cleanup will assert if anyone's waiting on it */
|
||||
spinlock_cleanup(&sem->sem_lock);
|
||||
wchan_destroy(sem->sem_wchan);
|
||||
kfree(sem->sem_name);
|
||||
kfree(sem);
|
||||
/* wchan_cleanup will assert if anyone's waiting on it */
|
||||
spinlock_cleanup(&sem->sem_lock);
|
||||
wchan_destroy(sem->sem_wchan);
|
||||
kfree(sem->sem_name);
|
||||
kfree(sem);
|
||||
}
|
||||
|
||||
void
|
||||
P(struct semaphore *sem)
|
||||
{
|
||||
KASSERT(sem != NULL);
|
||||
void P(struct semaphore *sem) {
|
||||
KASSERT(sem != NULL);
|
||||
|
||||
/*
|
||||
* May not block in an interrupt handler.
|
||||
*
|
||||
* For robustness, always check, even if we can actually
|
||||
* complete the P without blocking.
|
||||
*/
|
||||
KASSERT(curthread->t_in_interrupt == false);
|
||||
/*
|
||||
* May not block in an interrupt handler.
|
||||
*
|
||||
* For robustness, always check, even if we can actually
|
||||
* complete the P without blocking.
|
||||
*/
|
||||
KASSERT(curthread->t_in_interrupt == false);
|
||||
|
||||
/* Use the semaphore spinlock to protect the wchan as well. */
|
||||
spinlock_acquire(&sem->sem_lock);
|
||||
while (sem->sem_count == 0) {
|
||||
/*
|
||||
*
|
||||
* Note that we don't maintain strict FIFO ordering of
|
||||
* threads going through the semaphore; that is, we
|
||||
* might "get" it on the first try even if other
|
||||
* threads are waiting. Apparently according to some
|
||||
* textbooks semaphores must for some reason have
|
||||
* strict ordering. Too bad. :-)
|
||||
*
|
||||
* Exercise: how would you implement strict FIFO
|
||||
* ordering?
|
||||
*/
|
||||
wchan_sleep(sem->sem_wchan, &sem->sem_lock);
|
||||
}
|
||||
KASSERT(sem->sem_count > 0);
|
||||
sem->sem_count--;
|
||||
spinlock_release(&sem->sem_lock);
|
||||
/* Use the semaphore spinlock to protect the wchan as well. */
|
||||
spinlock_acquire(&sem->sem_lock);
|
||||
while (sem->sem_count == 0) {
|
||||
/*
|
||||
*
|
||||
* Note that we don't maintain strict FIFO ordering of
|
||||
* threads going through the semaphore; that is, we
|
||||
* might "get" it on the first try even if other
|
||||
* threads are waiting. Apparently according to some
|
||||
* textbooks semaphores must for some reason have
|
||||
* strict ordering. Too bad. :-)
|
||||
*
|
||||
* Exercise: how would you implement strict FIFO
|
||||
* ordering?
|
||||
*/
|
||||
wchan_sleep(sem->sem_wchan, &sem->sem_lock);
|
||||
}
|
||||
KASSERT(sem->sem_count > 0);
|
||||
sem->sem_count--;
|
||||
spinlock_release(&sem->sem_lock);
|
||||
}
|
||||
|
||||
void
|
||||
V(struct semaphore *sem)
|
||||
{
|
||||
KASSERT(sem != NULL);
|
||||
void V(struct semaphore *sem) {
|
||||
KASSERT(sem != NULL);
|
||||
|
||||
spinlock_acquire(&sem->sem_lock);
|
||||
spinlock_acquire(&sem->sem_lock);
|
||||
|
||||
sem->sem_count++;
|
||||
KASSERT(sem->sem_count > 0);
|
||||
wchan_wakeone(sem->sem_wchan, &sem->sem_lock);
|
||||
sem->sem_count++;
|
||||
KASSERT(sem->sem_count > 0);
|
||||
wchan_wakeone(sem->sem_wchan, &sem->sem_lock);
|
||||
|
||||
spinlock_release(&sem->sem_lock);
|
||||
spinlock_release(&sem->sem_lock);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Lock.
|
||||
|
||||
struct lock *
|
||||
lock_create(const char *name)
|
||||
{
|
||||
struct lock *lock;
|
||||
struct lock *lock_create(const char *name) {
|
||||
struct lock *lock;
|
||||
|
||||
lock = kmalloc(sizeof(*lock));
|
||||
if (lock == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
lock = kmalloc(sizeof(*lock));
|
||||
if (lock == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lock->lk_name = kstrdup(name);
|
||||
if (lock->lk_name == NULL) {
|
||||
kfree(lock);
|
||||
return NULL;
|
||||
}
|
||||
lock->lk_name = kstrdup(name);
|
||||
if (lock->lk_name == NULL) {
|
||||
kfree(lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HANGMAN_LOCKABLEINIT(&lock->lk_hangman, lock->lk_name);
|
||||
HANGMAN_LOCKABLEINIT(&lock->lk_hangman, lock->lk_name);
|
||||
|
||||
// add stuff here as needed
|
||||
// add stuff here as needed
|
||||
|
||||
return lock;
|
||||
return lock;
|
||||
}
|
||||
|
||||
void
|
||||
lock_destroy(struct lock *lock)
|
||||
{
|
||||
KASSERT(lock != NULL);
|
||||
void lock_destroy(struct lock *lock) {
|
||||
KASSERT(lock != NULL);
|
||||
|
||||
// add stuff here as needed
|
||||
// add stuff here as needed
|
||||
|
||||
kfree(lock->lk_name);
|
||||
kfree(lock);
|
||||
kfree(lock->lk_name);
|
||||
kfree(lock);
|
||||
}
|
||||
|
||||
void
|
||||
lock_acquire(struct lock *lock)
|
||||
{
|
||||
/* Call this (atomically) before waiting for a lock */
|
||||
//HANGMAN_WAIT(&curthread->t_hangman, &lock->lk_hangman);
|
||||
void lock_acquire(struct lock *lock) {
|
||||
/* Call this (atomically) before waiting for a lock */
|
||||
// HANGMAN_WAIT(&curthread->t_hangman, &lock->lk_hangman);
|
||||
|
||||
// Write this
|
||||
// Write this
|
||||
|
||||
(void)lock; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
|
||||
/* Call this (atomically) once the lock is acquired */
|
||||
//HANGMAN_ACQUIRE(&curthread->t_hangman, &lock->lk_hangman);
|
||||
/* Call this (atomically) once the lock is acquired */
|
||||
// HANGMAN_ACQUIRE(&curthread->t_hangman, &lock->lk_hangman);
|
||||
}
|
||||
|
||||
void
|
||||
lock_release(struct lock *lock)
|
||||
{
|
||||
/* Call this (atomically) when the lock is released */
|
||||
//HANGMAN_RELEASE(&curthread->t_hangman, &lock->lk_hangman);
|
||||
void lock_release(struct lock *lock) {
|
||||
/* Call this (atomically) when the lock is released */
|
||||
// HANGMAN_RELEASE(&curthread->t_hangman, &lock->lk_hangman);
|
||||
|
||||
// Write this
|
||||
// Write this
|
||||
|
||||
(void)lock; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
}
|
||||
|
||||
bool
|
||||
lock_do_i_hold(struct lock *lock)
|
||||
{
|
||||
// Write this
|
||||
bool lock_do_i_hold(struct lock *lock) {
|
||||
// Write this
|
||||
|
||||
(void)lock; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
|
||||
return true; // dummy until code gets written
|
||||
return true; // dummy until code gets written
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// CV
|
||||
|
||||
struct cv *cv_create(const char *name) {
|
||||
struct cv *cv;
|
||||
|
||||
struct cv *
|
||||
cv_create(const char *name)
|
||||
{
|
||||
struct cv *cv;
|
||||
cv = kmalloc(sizeof(*cv));
|
||||
if (cv == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cv = kmalloc(sizeof(*cv));
|
||||
if (cv == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
cv->cv_name = kstrdup(name);
|
||||
if (cv->cv_name == NULL) {
|
||||
kfree(cv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cv->cv_name = kstrdup(name);
|
||||
if (cv->cv_name==NULL) {
|
||||
kfree(cv);
|
||||
return NULL;
|
||||
}
|
||||
// add stuff here as needed
|
||||
|
||||
// add stuff here as needed
|
||||
|
||||
return cv;
|
||||
return cv;
|
||||
}
|
||||
|
||||
void
|
||||
cv_destroy(struct cv *cv)
|
||||
{
|
||||
KASSERT(cv != NULL);
|
||||
void cv_destroy(struct cv *cv) {
|
||||
KASSERT(cv != NULL);
|
||||
|
||||
// add stuff here as needed
|
||||
// add stuff here as needed
|
||||
|
||||
kfree(cv->cv_name);
|
||||
kfree(cv);
|
||||
kfree(cv->cv_name);
|
||||
kfree(cv);
|
||||
}
|
||||
|
||||
void
|
||||
cv_wait(struct cv *cv, struct lock *lock)
|
||||
{
|
||||
// Write this
|
||||
(void)cv; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
void cv_wait(struct cv *cv, struct lock *lock) {
|
||||
// Write this
|
||||
(void)cv; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
}
|
||||
|
||||
void
|
||||
cv_signal(struct cv *cv, struct lock *lock)
|
||||
{
|
||||
// Write this
|
||||
(void)cv; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
void cv_signal(struct cv *cv, struct lock *lock) {
|
||||
// Write this
|
||||
(void)cv; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
}
|
||||
|
||||
void
|
||||
cv_broadcast(struct cv *cv, struct lock *lock)
|
||||
{
|
||||
// Write this
|
||||
(void)cv; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
void cv_broadcast(struct cv *cv, struct lock *lock) {
|
||||
// Write this
|
||||
(void)cv; // suppress warning until code gets written
|
||||
(void)lock; // suppress warning until code gets written
|
||||
}
|
||||
|
||||
1493
kern/thread/thread.c
1493
kern/thread/thread.c
File diff suppressed because it is too large
Load Diff
@@ -36,64 +36,54 @@
|
||||
#include <thread.h>
|
||||
#include <threadlist.h>
|
||||
|
||||
void
|
||||
threadlistnode_init(struct threadlistnode *tln, struct thread *t)
|
||||
{
|
||||
DEBUGASSERT(tln != NULL);
|
||||
KASSERT(t != NULL);
|
||||
void threadlistnode_init(struct threadlistnode *tln, struct thread *t) {
|
||||
DEBUGASSERT(tln != NULL);
|
||||
KASSERT(t != NULL);
|
||||
|
||||
tln->tln_next = NULL;
|
||||
tln->tln_prev = NULL;
|
||||
tln->tln_self = t;
|
||||
tln->tln_next = NULL;
|
||||
tln->tln_prev = NULL;
|
||||
tln->tln_self = t;
|
||||
}
|
||||
|
||||
void
|
||||
threadlistnode_cleanup(struct threadlistnode *tln)
|
||||
{
|
||||
DEBUGASSERT(tln != NULL);
|
||||
void threadlistnode_cleanup(struct threadlistnode *tln) {
|
||||
DEBUGASSERT(tln != NULL);
|
||||
|
||||
KASSERT(tln->tln_next == NULL);
|
||||
KASSERT(tln->tln_prev == NULL);
|
||||
KASSERT(tln->tln_self != NULL);
|
||||
KASSERT(tln->tln_next == NULL);
|
||||
KASSERT(tln->tln_prev == NULL);
|
||||
KASSERT(tln->tln_self != NULL);
|
||||
}
|
||||
|
||||
void
|
||||
threadlist_init(struct threadlist *tl)
|
||||
{
|
||||
DEBUGASSERT(tl != NULL);
|
||||
void threadlist_init(struct threadlist *tl) {
|
||||
DEBUGASSERT(tl != NULL);
|
||||
|
||||
tl->tl_head.tln_next = &tl->tl_tail;
|
||||
tl->tl_head.tln_prev = NULL;
|
||||
tl->tl_tail.tln_next = NULL;
|
||||
tl->tl_tail.tln_prev = &tl->tl_head;
|
||||
tl->tl_head.tln_self = NULL;
|
||||
tl->tl_tail.tln_self = NULL;
|
||||
tl->tl_count = 0;
|
||||
tl->tl_head.tln_next = &tl->tl_tail;
|
||||
tl->tl_head.tln_prev = NULL;
|
||||
tl->tl_tail.tln_next = NULL;
|
||||
tl->tl_tail.tln_prev = &tl->tl_head;
|
||||
tl->tl_head.tln_self = NULL;
|
||||
tl->tl_tail.tln_self = NULL;
|
||||
tl->tl_count = 0;
|
||||
}
|
||||
|
||||
void
|
||||
threadlist_cleanup(struct threadlist *tl)
|
||||
{
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(tl->tl_head.tln_next == &tl->tl_tail);
|
||||
DEBUGASSERT(tl->tl_head.tln_prev == NULL);
|
||||
DEBUGASSERT(tl->tl_tail.tln_next == NULL);
|
||||
DEBUGASSERT(tl->tl_tail.tln_prev == &tl->tl_head);
|
||||
DEBUGASSERT(tl->tl_head.tln_self == NULL);
|
||||
DEBUGASSERT(tl->tl_tail.tln_self == NULL);
|
||||
void threadlist_cleanup(struct threadlist *tl) {
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(tl->tl_head.tln_next == &tl->tl_tail);
|
||||
DEBUGASSERT(tl->tl_head.tln_prev == NULL);
|
||||
DEBUGASSERT(tl->tl_tail.tln_next == NULL);
|
||||
DEBUGASSERT(tl->tl_tail.tln_prev == &tl->tl_head);
|
||||
DEBUGASSERT(tl->tl_head.tln_self == NULL);
|
||||
DEBUGASSERT(tl->tl_tail.tln_self == NULL);
|
||||
|
||||
KASSERT(threadlist_isempty(tl));
|
||||
KASSERT(tl->tl_count == 0);
|
||||
KASSERT(threadlist_isempty(tl));
|
||||
KASSERT(tl->tl_count == 0);
|
||||
|
||||
/* nothing (else) to do */
|
||||
/* nothing (else) to do */
|
||||
}
|
||||
|
||||
bool
|
||||
threadlist_isempty(struct threadlist *tl)
|
||||
{
|
||||
DEBUGASSERT(tl != NULL);
|
||||
bool threadlist_isempty(struct threadlist *tl) {
|
||||
DEBUGASSERT(tl != NULL);
|
||||
|
||||
return (tl->tl_count == 0);
|
||||
return (tl->tl_count == 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -102,139 +92,118 @@ threadlist_isempty(struct threadlist *tl)
|
||||
/*
|
||||
* Do insertion. Doesn't update tl_count.
|
||||
*/
|
||||
static
|
||||
void
|
||||
threadlist_insertafternode(struct threadlistnode *onlist, struct thread *t)
|
||||
{
|
||||
struct threadlistnode *addee;
|
||||
static void threadlist_insertafternode(struct threadlistnode *onlist,
|
||||
struct thread *t) {
|
||||
struct threadlistnode *addee;
|
||||
|
||||
addee = &t->t_listnode;
|
||||
addee = &t->t_listnode;
|
||||
|
||||
DEBUGASSERT(addee->tln_prev == NULL);
|
||||
DEBUGASSERT(addee->tln_next == NULL);
|
||||
DEBUGASSERT(addee->tln_prev == NULL);
|
||||
DEBUGASSERT(addee->tln_next == NULL);
|
||||
|
||||
addee->tln_prev = onlist;
|
||||
addee->tln_next = onlist->tln_next;
|
||||
addee->tln_prev->tln_next = addee;
|
||||
addee->tln_next->tln_prev = addee;
|
||||
addee->tln_prev = onlist;
|
||||
addee->tln_next = onlist->tln_next;
|
||||
addee->tln_prev->tln_next = addee;
|
||||
addee->tln_next->tln_prev = addee;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do insertion. Doesn't update tl_count.
|
||||
*/
|
||||
static
|
||||
void
|
||||
threadlist_insertbeforenode(struct thread *t, struct threadlistnode *onlist)
|
||||
{
|
||||
struct threadlistnode *addee;
|
||||
static void threadlist_insertbeforenode(struct thread *t,
|
||||
struct threadlistnode *onlist) {
|
||||
struct threadlistnode *addee;
|
||||
|
||||
addee = &t->t_listnode;
|
||||
addee = &t->t_listnode;
|
||||
|
||||
DEBUGASSERT(addee->tln_prev == NULL);
|
||||
DEBUGASSERT(addee->tln_next == NULL);
|
||||
DEBUGASSERT(addee->tln_prev == NULL);
|
||||
DEBUGASSERT(addee->tln_next == NULL);
|
||||
|
||||
addee->tln_prev = onlist->tln_prev;
|
||||
addee->tln_next = onlist;
|
||||
addee->tln_prev->tln_next = addee;
|
||||
addee->tln_next->tln_prev = addee;
|
||||
addee->tln_prev = onlist->tln_prev;
|
||||
addee->tln_next = onlist;
|
||||
addee->tln_prev->tln_next = addee;
|
||||
addee->tln_next->tln_prev = addee;
|
||||
}
|
||||
|
||||
/*
|
||||
* Do removal. Doesn't update tl_count.
|
||||
*/
|
||||
static
|
||||
void
|
||||
threadlist_removenode(struct threadlistnode *tln)
|
||||
{
|
||||
DEBUGASSERT(tln != NULL);
|
||||
DEBUGASSERT(tln->tln_prev != NULL);
|
||||
DEBUGASSERT(tln->tln_next != NULL);
|
||||
static void threadlist_removenode(struct threadlistnode *tln) {
|
||||
DEBUGASSERT(tln != NULL);
|
||||
DEBUGASSERT(tln->tln_prev != NULL);
|
||||
DEBUGASSERT(tln->tln_next != NULL);
|
||||
|
||||
tln->tln_prev->tln_next = tln->tln_next;
|
||||
tln->tln_next->tln_prev = tln->tln_prev;
|
||||
tln->tln_prev = NULL;
|
||||
tln->tln_next = NULL;
|
||||
tln->tln_prev->tln_next = tln->tln_next;
|
||||
tln->tln_next->tln_prev = tln->tln_prev;
|
||||
tln->tln_prev = NULL;
|
||||
tln->tln_next = NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// public
|
||||
|
||||
void
|
||||
threadlist_addhead(struct threadlist *tl, struct thread *t)
|
||||
{
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(t != NULL);
|
||||
void threadlist_addhead(struct threadlist *tl, struct thread *t) {
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(t != NULL);
|
||||
|
||||
threadlist_insertafternode(&tl->tl_head, t);
|
||||
tl->tl_count++;
|
||||
threadlist_insertafternode(&tl->tl_head, t);
|
||||
tl->tl_count++;
|
||||
}
|
||||
|
||||
void
|
||||
threadlist_addtail(struct threadlist *tl, struct thread *t)
|
||||
{
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(t != NULL);
|
||||
void threadlist_addtail(struct threadlist *tl, struct thread *t) {
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(t != NULL);
|
||||
|
||||
threadlist_insertbeforenode(t, &tl->tl_tail);
|
||||
tl->tl_count++;
|
||||
threadlist_insertbeforenode(t, &tl->tl_tail);
|
||||
tl->tl_count++;
|
||||
}
|
||||
|
||||
struct thread *
|
||||
threadlist_remhead(struct threadlist *tl)
|
||||
{
|
||||
struct threadlistnode *tln;
|
||||
struct thread *threadlist_remhead(struct threadlist *tl) {
|
||||
struct threadlistnode *tln;
|
||||
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(tl != NULL);
|
||||
|
||||
tln = tl->tl_head.tln_next;
|
||||
if (tln->tln_next == NULL) {
|
||||
/* list was empty */
|
||||
return NULL;
|
||||
}
|
||||
threadlist_removenode(tln);
|
||||
DEBUGASSERT(tl->tl_count > 0);
|
||||
tl->tl_count--;
|
||||
return tln->tln_self;
|
||||
tln = tl->tl_head.tln_next;
|
||||
if (tln->tln_next == NULL) {
|
||||
/* list was empty */
|
||||
return NULL;
|
||||
}
|
||||
threadlist_removenode(tln);
|
||||
DEBUGASSERT(tl->tl_count > 0);
|
||||
tl->tl_count--;
|
||||
return tln->tln_self;
|
||||
}
|
||||
|
||||
struct thread *
|
||||
threadlist_remtail(struct threadlist *tl)
|
||||
{
|
||||
struct threadlistnode *tln;
|
||||
struct thread *threadlist_remtail(struct threadlist *tl) {
|
||||
struct threadlistnode *tln;
|
||||
|
||||
DEBUGASSERT(tl != NULL);
|
||||
DEBUGASSERT(tl != NULL);
|
||||
|
||||
tln = tl->tl_tail.tln_prev;
|
||||
if (tln->tln_prev == NULL) {
|
||||
/* list was empty */
|
||||
return NULL;
|
||||
}
|
||||
threadlist_removenode(tln);
|
||||
DEBUGASSERT(tl->tl_count > 0);
|
||||
tl->tl_count--;
|
||||
return tln->tln_self;
|
||||
tln = tl->tl_tail.tln_prev;
|
||||
if (tln->tln_prev == NULL) {
|
||||
/* list was empty */
|
||||
return NULL;
|
||||
}
|
||||
threadlist_removenode(tln);
|
||||
DEBUGASSERT(tl->tl_count > 0);
|
||||
tl->tl_count--;
|
||||
return tln->tln_self;
|
||||
}
|
||||
|
||||
void
|
||||
threadlist_insertafter(struct threadlist *tl,
|
||||
struct thread *onlist, struct thread *addee)
|
||||
{
|
||||
threadlist_insertafternode(&onlist->t_listnode, addee);
|
||||
tl->tl_count++;
|
||||
void threadlist_insertafter(struct threadlist *tl, struct thread *onlist,
|
||||
struct thread *addee) {
|
||||
threadlist_insertafternode(&onlist->t_listnode, addee);
|
||||
tl->tl_count++;
|
||||
}
|
||||
|
||||
void
|
||||
threadlist_insertbefore(struct threadlist *tl,
|
||||
struct thread *addee, struct thread *onlist)
|
||||
{
|
||||
threadlist_insertbeforenode(addee, &onlist->t_listnode);
|
||||
tl->tl_count++;
|
||||
void threadlist_insertbefore(struct threadlist *tl, struct thread *addee,
|
||||
struct thread *onlist) {
|
||||
threadlist_insertbeforenode(addee, &onlist->t_listnode);
|
||||
tl->tl_count++;
|
||||
}
|
||||
|
||||
void
|
||||
threadlist_remove(struct threadlist *tl, struct thread *t)
|
||||
{
|
||||
threadlist_removenode(&t->t_listnode);
|
||||
DEBUGASSERT(tl->tl_count > 0);
|
||||
tl->tl_count--;
|
||||
void threadlist_remove(struct threadlist *tl, struct thread *t) {
|
||||
threadlist_removenode(&t->t_listnode);
|
||||
DEBUGASSERT(tl->tl_count > 0);
|
||||
tl->tl_count--;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user