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


#include "memory.h" 
#include"../include/os.h" 
 
#define SEMAPHORE_LOCK 
 
#ifndef SEMAPHORE_LOCK 
static int lock_flag=1; 
#endif 
 
void unlock_memory_body(int memory_body_id) 
{ 
 
#ifndef SEMAPHORE_LOCK 
	lock_flag=1; 
#else 
	struct thread_environment r; 
	union system_call_parameter *par; 
	struct capability c; 
	__asm__("cli\n\t"); 
	par=get_kernel_parameter(); 
	COPY_CAPABILITY((par->capability.capability_1),c); 
	COPY_CAPABILITY((os->system_capability), 
		(par->capability.capability_1)); 
	r.system_call=4; 
	r.system_call_arg1=os->system_file[ 
		memory_body->my_memory_body].semaphore_id; 
	r.system_call_arg2=1; 
	r.system_call_arg3=0; 
	call_kernel(&r); 
	COPY_CAPABILITY(c,(par->capability.capability_1)); 
#endif 
	return ; 
} 
 
void lock_memory_body(int memory_body_id) 
{ 
	struct thread_environment r; 
#ifndef SEMAPHORE_LOCK 
	for(;;){ 
		if(lock_flag!=0){ 
			lock_flag=0; 
			return; 
		} 
		r.ax=(-1); 
		call_kernel(&r); 
	} 
#else 
	union system_call_parameter *par; 
	struct capability c; 
 
	par=get_kernel_parameter(); 
	COPY_CAPABILITY((par->capability.capability_2),c); 
	r.system_call=4; 
	r.system_call_arg1=0; 
	r.system_call_arg3=os->system_file[ 
		memory_body->my_memory_body].semaphore_id; 
	r.system_call_arg4=TRUE; 
	r.system_call_arg5=FALSE; 
	COPY_CAPABILITY((os->system_capability), 
		(par->capability.capability_2)); 
	call_kernel(&r); 
	COPY_CAPABILITY(c,(par->capability.capability_2)); 
	__asm__("sti\n\t"); 
#endif 
	return; 
} 
 
void memory_v_operation(int processor,int semaphore) 
{ 
	struct thread_environment r; 
	union system_call_parameter *par; 
	struct capability c; 
	if((processor<0)||(semaphore<0)) 
		return; 
	par=get_kernel_parameter(); 
	COPY_CAPABILITY((par->capability.capability_1),c); 
	COPY_CAPABILITY((os->system_capability), 
		(par->capability.capability_1)); 
	r.system_call=4; 
	r.system_call_arg1=semaphore; 
	r.system_call_arg2=-1; 
	r.system_call_arg3=0; 
	call_kernel(&r); 
	COPY_CAPABILITY(c,(par->capability.capability_1)); 
	return; 
} 
 
void memory_wait(int sleep_semaphore, 
	int next_processor,int next_semaphore) 
{ 
	struct thread_environment r; 
	union system_call_parameter *par; 
	struct capability c1,c2; 
 
	par=get_kernel_parameter(); 
 
	COPY_CAPABILITY((par->capability.capability_1),c1); 
	COPY_CAPABILITY((par->capability.capability_2),c2); 
 
	COPY_CAPABILITY((os->system_capability), 
		(par->capability.capability_1)); 
	COPY_CAPABILITY((os->system_capability), 
		(par->capability.capability_2)); 
 
	r.system_call=4; 
#ifndef SEMAPHORE_LOCK 
	r.system_call_arg1=0; 
	unlock_memory_body(memory_body->my_memory_body); 
#else 
	r.system_call_arg1=os->system_file[ 
		memory_body->my_memory_body].semaphore_id; 
#endif 
	r.system_call_arg2=1; 
	r.system_call_arg3=sleep_semaphore; 
	r.system_call_arg4=TRUE; 
	r.system_call_arg5=FALSE; 
	call_kernel(&r); 
 
	COPY_CAPABILITY((os->system_capability), 
		(par->capability.capability_1)); 
	COPY_CAPABILITY((os->system_capability), 
		(par->capability.capability_2)); 
 
	r.system_call=4; 
	if((next_processor<0)||(next_semaphore<0)) 
		r.system_call_arg1=0; 
	else 
		r.system_call_arg1=next_semaphore; 
	r.system_call_arg2=-1; 
 
#ifndef SEMAPHORE_LOCK 
	r.system_call_arg3=0; 
	lock_memory_body(memory_body->my_memory_body); 
	if(r.system_call_arg1!=0) 
		call_kernel(&r); 
#else 
	r.system_call_arg3=os->system_file[ 
		memory_body->my_memory_body].semaphore_id; 
	r.system_call_arg4=TRUE; 
	r.system_call_arg5=FALSE; 
	call_kernel(&r); 
#endif 
	COPY_CAPABILITY(c1,(par->capability.capability_1)); 
	COPY_CAPABILITY(c2,(par->capability.capability_2)); 
	return; 
 
}