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

📄 boilerplate.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
字号:
#include <u.h>#include <libc.h>#include <thread.h>#include <fcall.h>#include "playlist.h"static Channel *reqs;Req*reqalloc(void){	Req *r;	if(reqs == nil)		reqs = chancreate(sizeof(Req*), 256);	if(r = nbrecvp(reqs))		return r;	r = malloc(sizeof(Req));	return r;}voidreqfree(Req *r){	if(!nbsendp(reqs, r))		free(r);}Wmsgwaitmsg(Worker *w, Channel *q){	Wmsg m;	sendp(q, w);	recv(w->eventc, &m);	return m;}intsendmsg(Channel *q, Wmsg *m){	Worker *w;	while(w = nbrecvp(q)){		/* Test for markerdom (see bcastmsg) */		if(w->eventc){			send(w->eventc, m);			return 1;		}		sendp(q, w);	/* put back */	}	return 0;}voidbcastmsg(Channel *q, Wmsg *m){	Worker *w, marker;	void *a;	a = m->arg;	/*	 * Use a marker to mark the end of the queue.	 * This prevents workers from getting the	 * broadcast and putting themselves back on the	 * queue before the broadcast has finished	 */	marker.eventc = nil;	/* Only markers have eventc == nil */	sendp(q, &marker);	while((w = recvp(q)) != &marker){		if(w->eventc == nil){			/* somebody else's marker, put it back */			sendp(q, w);		}else{			if(a) m->arg = strdup(a);			send(w->eventc, m);		}	}	free(a);	m->arg = nil;}voidreadbuf(Req *r, void *s, long n){	r->ofcall.count = r->ifcall.count;	if(r->ifcall.offset >= n){		r->ofcall.count = 0;		return;	}	if(r->ifcall.offset+r->ofcall.count > n)		r->ofcall.count = n - r->ifcall.offset;	memmove(r->ofcall.data, (char*)s+r->ifcall.offset, r->ofcall.count);}voidreadstr(Req *r, char *s){	readbuf(r, s, strlen(s));}

⌨️ 快捷键说明

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