⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlock.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
字号:
#include "u.h"#include "lib.h"#include "dat.h"#include "fns.h"static voidqueue(Proc **first, Proc **last){	Proc *t;	t = *last;	if(t == 0)		*first = up;	else		t->qnext = up;	*last = up;	up->qnext = 0;}static Proc*dequeue(Proc **first, Proc **last){	Proc *t;	t = *first;	if(t == 0)		return 0;	*first = t->qnext;	if(*first == 0)		*last = 0;	return t;}voidqlock(QLock *q){	lock(&q->lk);	if(q->hold == 0) {		q->hold = up;		unlock(&q->lk);		return;	}	/*	 * Can't assert this because of RWLock	assert(q->hold != up);	 */			queue((Proc**)&q->first, (Proc**)&q->last);	unlock(&q->lk);	procsleep();}intcanqlock(QLock *q){	lock(&q->lk);	if(q->hold == 0) {		q->hold = up;		unlock(&q->lk);		return 1;	}	unlock(&q->lk);	return 0;}voidqunlock(QLock *q){	Proc *p;	lock(&q->lk);	/* 	 * Can't assert this because of RWlock	assert(q->hold == CT);	 */	p = dequeue((Proc**)&q->first, (Proc**)&q->last);	if(p) {		q->hold = p;		unlock(&q->lk);		procwakeup(p);	} else {		q->hold = 0;		unlock(&q->lk);	}}intholdqlock(QLock *q){	return q->hold == up;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -