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


#include"kernel.h" 
 
#define WRONG_SEMAPHORE_ID	-1 
#define WRONG_CAPABILITY	-2 
#define TOO_SMALL_STEP		-3 
#define TOO_SMALL_FIRST_TIME	-4 
 
void kernel_semaphore_time_deal() 
{ 
	int semaphore_id,v_value; 
	struct kernel_time my_time; 
	struct semaphore *s; 
 
	TIME_INC(TIME_INCREASE_STEP,(os->current_time)); 
	for(;;){ 
		semaphore_id=os->semaphore_heap[0].semaphore_id; 
		s=&(os->semaphore[semaphore_id]); 
		if(TIME_GREAT_AND_EQUAL((s->first),(os->current_time))) 
			break; 
		COPY_TIME((s->step),my_time); 
		TIME_ADD((s->first),my_time); 
		if(TIME_LESS_AND_EQUAL(my_time,(os->current_time))){ 
			s->v_value=(-1);SET_MOST_TIME(my_time); 
		} 
		set_semaphore_time(semaphore_id,&my_time); 
		v_value=s->v_value; 
		system_call_v(semaphore_id,&v_value,&(s->capability)); 
	} 
	return; 
} 
 
int set_semaphore_time_system_call(int semaphore_id,int v_value, 
	struct kernel_time *first_time,struct kernel_time *step_time, 
	struct capability *sem_capability) 
{ 
	struct semaphore *s; 
	struct kernel_time my_time; 
 
	if((semaphore_id<0)||(semaphore_id>=SEMAPHORE_NUMBER)) 
		return WRONG_SEMAPHORE_ID; 
	s=&(os->semaphore[semaphore_id]); 
	if(!KERNEL_COMPARE_CAPABILITY(s->capability,(*sem_capability))) 
		return WRONG_CAPABILITY; 
	SET_MINIMAL_STEP(my_time); 
	if(TIME_LESS_AND_EQUAL((*first_time),(os->current_time))){  
		COPY_TIME((os->current_time),(*first_time)); 
		TIME_ADD(my_time,(*first_time)); 
	} 
	if(TIME_LESS_AND_EQUAL((*step_time),my_time)) 
		COPY_TIME(my_time,(*step_time)); 
	COPY_TIME((*step_time),(s->step)); 
	s->v_value=v_value; 
 	set_semaphore_time(semaphore_id,first_time); 
	return 0; 
} 
 
int set_semaphore_time_and_p_operation(int thread_id, 
	int semaphore_id,int sleep_flag,int v_flag,int v_value, 
	struct kernel_time *first_time,struct kernel_time *step_time, 
	struct capability *semaphore_capability) 
{ 
	int return_value; 
	return_value=set_semaphore_time_system_call( 
		((semaphore_id>=0)?semaphore_id:(0-semaphore_id)), 
		v_value,first_time,step_time,semaphore_capability); 
	if((semaphore_id<0)&&(return_value>=0)) 
		return_value=system_call_p(thread_id,(0-semaphore_id), 
			sleep_flag,v_flag,semaphore_capability); 
	return return_value; 
}