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

📄 sem_re.c

📁 国内一位牛人自己开发的操作系统
💻 C
字号:
#include"kernel.h"

#define WRONG_SEMAPHORE 	-1
#define WRONG_PROCESS_NUMBER 	-2
#define WRONG_PROCESS_STATE 	-3
#define WRONG_CAPABILITY 	-4
#define IS_THREAD_SEMAPHORE	-5

int release_semaphore(int release_flag,int semaphore_id,
	struct capability *semaphore_capability)
{
	struct semaphore *s;
	struct kernel_time my_time;

	if((semaphore_id<=0)||(semaphore_id>=SEMAPHORE_NUMBER))
		return WRONG_SEMAPHORE;
	s=(&(os->semaphore[semaphore_id]));
	if((s->process<=0)||(s->process>=PROCESS_NUMBER))
		return WRONG_PROCESS_NUMBER;
	if(!KERNEL_COMPARE_CAPABILITY(
			(os->process[s->process].capability),
			(*semaphore_capability)))
		return WRONG_CAPABILITY;
	if(s->thread_id>=0){
		if(release_flag)
			return IS_THREAD_SEMAPHORE;
		os->thread[s->thread_id].semaphore=(-1);
		s->thread_id=(-1);
	}
	for(;;){
		if(s->thread_ring<0)
			break;
		v_thread(s->thread_ring);
	}
	move_semaphore(semaphore_id,0);

	SET_MOST_TIME(my_time);
	SET_MINIMAL_STEP(s->step);
	s->v_value=0;
	set_semaphore_time(semaphore_id,&my_time);
	return 0;
}

⌨️ 快捷键说明

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