www.pudn.com > LFYOS.zip > sem_re.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; 
}