www.pudn.com > LFYOS.zip > reset_sem.c


#include"kernel.h" 
#define WRONG_SEMAPHORE_ID 	(-1) 
#define WRONG_CAPABILITY	(-2) 
int reset_semaphore_value(int sem_id,struct capability *cap) 
{ 
	struct semaphore *s; 
	struct kernel_time new_time,new_step; 
 
	if((sem_id<=0)||(sem_id>=SEMAPHORE_NUMBER)) 
		return WRONG_SEMAPHORE_ID; 
	s=&(os->semaphore[sem_id]); 
	if(!KERNEL_COMPARE_CAPABILITY(s->capability,(*cap))) 
		return WRONG_CAPABILITY; 
	if(s->value<0){ 
		int value=(-1); 
		system_call_v(sem_id,&value,&(os->system_capability)); 
	} 
	if(s->value>0) 
		s->value=0; 
	SET_MOST_TIME(new_time); 
	SET_MINIMAL_STEP(new_step); 
	set_semaphore_time_system_call(sem_id,0, 
		&new_time,&new_step,&(s->capability)); 
	return sem_id; 
}