예제 #1
0
s32 LWP_CreateThread(lwp_t *thethread,void* (*entry)(void *),void *arg,void *stackbase,u32 stack_size,u8 prio)
{
	u32 status;
	lwp_cntrl *lwp_thread;
	
	if(!thethread || !entry) return -1;

	lwp_thread = __lwp_cntrl_allocate();
	if(!lwp_thread) return -1;

	status = __lwp_thread_init(lwp_thread,stackbase,stack_size,__lwp_priotocore(prio),0,TRUE);
	if(!status) {
		__lwp_cntrl_free(lwp_thread);
		__lwp_thread_dispatchenable();
		return -1;
	}
	
	status = __lwp_thread_start(lwp_thread,entry,arg);
	if(!status) {
		__lwp_cntrl_free(lwp_thread);
		__lwp_thread_dispatchenable();
		return -1;
	}

	*thethread = (lwp_t)(LWP_OBJMASKTYPE(LWP_OBJTYPE_THREAD)|LWP_OBJMASKID(lwp_thread->object.id));
	__lwp_thread_dispatchenable();

	return 0;
}
예제 #2
0
s32 LWP_JoinThread(lwp_t thethread,void **value_ptr)
{
	u32 level;
	void *return_ptr;
	lwp_cntrl *exec,*lwp_thread;
	
	lwp_thread = __lwp_cntrl_open(thethread);
	if(!lwp_thread) return 0;

	if(__lwp_thread_isexec(lwp_thread)) {
		__lwp_thread_dispatchenable();
		return EDEADLK;			//EDEADLK
	}

	exec = _thr_executing;
	_CPU_ISR_Disable(level);
	__lwp_threadqueue_csenter(&lwp_thread->join_list);
	exec->wait.ret_code = 0;
	exec->wait.ret_arg_1 = NULL;
	exec->wait.ret_arg = (void*)&return_ptr;
	exec->wait.queue = &lwp_thread->join_list;
	exec->wait.id = thethread;
	_CPU_ISR_Restore(level);
	__lwp_threadqueue_enqueue(&lwp_thread->join_list,LWP_WD_NOTIMEOUT);
	__lwp_thread_dispatchenable();

	if(value_ptr) *value_ptr = return_ptr;
	return 0;
}
예제 #3
0
s32 LWP_CondDestroy(cond_t cond)
{
	cond_st *ptr = __lwp_cond_open(cond);
	if(!ptr) return -1;

	if(__lwp_threadqueue_first(&ptr->wait_queue)) {
		__lwp_thread_dispatchenable();
		return EBUSY;
	}
	__lwp_thread_dispatchenable();

	__lwp_cond_free(ptr);
	return 0;
}
예제 #4
0
s32 LWP_ResumeThread(lwp_t thethread)
{
	lwp_cntrl *lwp_thread;

	lwp_thread = __lwp_cntrl_open(thethread);
	if(!lwp_thread) return -1;

	if(__lwp_statesuspended(lwp_thread->cur_state)) {
		__lwp_thread_resume(lwp_thread,TRUE);
		__lwp_thread_dispatchenable();
		return LWP_SUCCESSFUL;
	}
	__lwp_thread_dispatchenable();
	return LWP_NOT_SUSPENDED;
}
예제 #5
0
s32 LWP_SuspendThread(lwp_t thethread)
{
	lwp_cntrl *lwp_thread;

	lwp_thread = __lwp_cntrl_open(thethread);
	if(!lwp_thread) return -1;

	if(!__lwp_statesuspended(lwp_thread->cur_state)) {
		__lwp_thread_suspend(lwp_thread);
		__lwp_thread_dispatchenable();
		return LWP_SUCCESSFUL;
	}
	__lwp_thread_dispatchenable();
	return LWP_ALREADY_SUSPENDED;
}
예제 #6
0
void DEBUG_Init(s32 device_type,s32 channel_port)
{
    u32 level;
    struct uip_ip_addr localip,netmask,gateway;

    UIP_LOG("DEBUG_Init()\n");

    __lwp_thread_dispatchdisable();

    bp_init();

    if(device_type==GDBSTUB_DEVICE_USB) {
        current_device = usb_init(channel_port);
    } else {
        localip.addr = uip_ipaddr((const u8_t*)tcp_localip);
        netmask.addr = uip_ipaddr((const u8_t*)tcp_netmask);
        gateway.addr = uip_ipaddr((const u8_t*)tcp_gateway);

        current_device = tcpip_init(&localip,&netmask,&gateway,(u16)channel_port);
    }

    if(current_device!=NULL) {
        _CPU_ISR_Disable(level);
        __exception_sethandler(EX_DSI,dbg_exceptionhandler);
        __exception_sethandler(EX_PRG,dbg_exceptionhandler);
        __exception_sethandler(EX_TRACE,dbg_exceptionhandler);
        __exception_sethandler(EX_IABR,dbg_exceptionhandler);
        _CPU_ISR_Restore(level);

        dbg_initialized = 1;

    }
    __lwp_thread_dispatchenable();
}
예제 #7
0
void LWP_ThreadSignal(lwpq_t thequeue)
{
	tqueue_st *tq;

	tq = __lwp_tqueue_open(thequeue);
	if(!tq) return;

	__lwp_threadqueue_dequeue(&tq->tqueue);
	__lwp_thread_dispatchenable();
}
예제 #8
0
파일: message.c 프로젝트: Alcaro/RetroArch
void MQ_Close(mqbox_t mqbox)
{
	mqbox_st *mbox;

	mbox = __lwp_mqbox_open(mqbox);
	if(!mbox) return;

	__lwpmq_close(&mbox->mqueue,0);
	__lwp_thread_dispatchenable();

	__lwp_mqbox_free(mbox);
}
예제 #9
0
파일: message.c 프로젝트: Alcaro/RetroArch
s32 MQ_Init(mqbox_t *mqbox,u32 count)
{
	mq_attr attr;
	mqbox_st *ret = NULL;

	if(!mqbox) return -1;

	ret = __lwp_mqbox_allocate();
	if(!ret) return MQ_ERROR_TOOMANY;

	attr.mode = LWP_MQ_FIFO;
	if(!__lwpmq_initialize(&ret->mqueue,&attr,count,sizeof(mqmsg_t))) {
		__lwp_mqbox_free(ret);
		__lwp_thread_dispatchenable();
		return MQ_ERROR_TOOMANY;
	}

	*mqbox = (mqbox_t)(LWP_OBJMASKTYPE(LWP_OBJTYPE_MBOX)|LWP_OBJMASKID(ret->object.id));
	__lwp_thread_dispatchenable();
	return MQ_ERROR_SUCCESSFUL;
}
예제 #10
0
void LWP_SetThreadPriority(lwp_t thethread,u32 prio)
{
	lwp_cntrl *lwp_thread;

	if(thethread==LWP_THREAD_NULL) thethread = LWP_GetSelf();

	lwp_thread = __lwp_cntrl_open(thethread);
	if(!lwp_thread) return;

	__lwp_thread_changepriority(lwp_thread,__lwp_priotocore(prio),TRUE);
	__lwp_thread_dispatchenable();
}
예제 #11
0
파일: message.c 프로젝트: Alcaro/RetroArch
static mqbox_st* __lwp_mqbox_allocate()
{
	mqbox_st *mqbox;

	__lwp_thread_dispatchdisable();
	mqbox = (mqbox_st*)__lwp_objmgr_allocate(&_lwp_mqbox_objects);
	if(mqbox) {
		__lwp_objmgr_open(&_lwp_mqbox_objects,&mqbox->object);
		return mqbox;
	}
	__lwp_thread_dispatchenable();
	return NULL;
}
예제 #12
0
static s32 __lwp_cond_waitsupp(cond_t cond,mutex_t mutex,u64 timeout,u8 timedout)
{
	u32 status,mstatus,level;
	cond_st *thecond = __lwp_cond_open(cond);

	if(!thecond) return -1;

	if(thecond->lock!=LWP_MUTEX_NULL && thecond->lock!=mutex) {
		__lwp_thread_dispatchenable();
		return EINVAL;
	}


	LWP_MutexUnlock(mutex);
	if(!timedout) {
		thecond->lock = mutex;
		_CPU_ISR_Disable(level);
		__lwp_threadqueue_csenter(&thecond->wait_queue);
		_thr_executing->wait.ret_code = 0;
		_thr_executing->wait.queue = &thecond->wait_queue;
		_thr_executing->wait.id = cond;
		_CPU_ISR_Restore(level);
		__lwp_threadqueue_enqueue(&thecond->wait_queue,timeout);
		__lwp_thread_dispatchenable();

		status = _thr_executing->wait.ret_code;
		if(status && status!=ETIMEDOUT)
			return status;
	} else {
		__lwp_thread_dispatchenable();
		status = ETIMEDOUT;
	}

	mstatus = LWP_MutexLock(mutex);
	if(mstatus)
		return EINVAL;

	return status;
}
예제 #13
0
static cond_st* __lwp_cond_allocate()
{
	cond_st *cond;

	__lwp_thread_dispatchdisable();
	cond = (cond_st*)__lwp_objmgr_allocate(&_lwp_cond_objects);
	if(cond) {
		__lwp_objmgr_open(&_lwp_cond_objects,&cond->object);
		return cond;
	}
	__lwp_thread_dispatchenable();
	return NULL;
}
예제 #14
0
static tqueue_st* __lwp_tqueue_allocate()
{
	tqueue_st *tqueue;

	__lwp_thread_dispatchdisable();
	tqueue = (tqueue_st*)__lwp_objmgr_allocate(&_lwp_tqueue_objects);
	if(tqueue) {
		__lwp_objmgr_open(&_lwp_tqueue_objects,&tqueue->object);
		return tqueue;
	}
	__lwp_thread_dispatchenable();
	return NULL;
}
예제 #15
0
static s32 __lwp_cond_signalsupp(cond_t cond,u8 isbroadcast)
{
	lwp_cntrl *thethread;
	cond_st *thecond = __lwp_cond_open(cond);
	if(!thecond) return -1;

	do {
		thethread = __lwp_threadqueue_dequeue(&thecond->wait_queue);
		if(!thethread) thecond->lock = LWP_MUTEX_NULL;
	} while(isbroadcast && thethread);
	__lwp_thread_dispatchenable();
	return 0;
}
예제 #16
0
static lwp_cntrl* __lwp_cntrl_allocate()
{
	lwp_cntrl *thethread;
	
	__lwp_thread_dispatchdisable();
	thethread = (lwp_cntrl*)__lwp_objmgr_allocate(&_lwp_thr_objects);
	if(thethread) {
		__lwp_objmgr_open(&_lwp_thr_objects,&thethread->object);
		return thethread;
	}
	__lwp_thread_dispatchenable();
	return NULL;
}
예제 #17
0
BOOL LWP_ThreadIsSuspended(lwp_t thethread)
{
	BOOL state;
	lwp_cntrl *lwp_thread;

	lwp_thread = __lwp_cntrl_open(thethread);
  	if(!lwp_thread) return FALSE;
	
	state = (__lwp_statesuspended(lwp_thread->cur_state) ? TRUE : FALSE);

	__lwp_thread_dispatchenable();
	return state;
}
예제 #18
0
void LWP_ThreadBroadcast(lwpq_t thequeue)
{
	tqueue_st *tq;
	lwp_cntrl *thethread;

	tq = __lwp_tqueue_open(thequeue);
	if(!tq) return;
	
	do {
		thethread = __lwp_threadqueue_dequeue(&tq->tqueue);
	} while(thethread);
	__lwp_thread_dispatchenable();
}
예제 #19
0
파일: message.c 프로젝트: Alcaro/RetroArch
BOOL MQ_Receive(mqbox_t mqbox,mqmsg_t *msg,u32 flags)
{
	BOOL ret;
	mqbox_st *mbox;
	u32 tmp,wait = (flags==MQ_MSG_BLOCK)?TRUE:FALSE;

	mbox = __lwp_mqbox_open(mqbox);
	if(!mbox) return FALSE;

	ret = FALSE;
	if(__lwpmq_seize(&mbox->mqueue,mbox->object.id,(void*)msg,&tmp,wait,LWP_THREADQ_NOTIMEOUT)==LWP_MQ_STATUS_SUCCESSFUL) ret = TRUE;
	__lwp_thread_dispatchenable();

	return ret;
}
예제 #20
0
파일: message.c 프로젝트: Alcaro/RetroArch
BOOL MQ_Jam(mqbox_t mqbox,mqmsg_t msg,u32 flags)
{
	BOOL ret;
	mqbox_st *mbox;
	u32 wait = (flags==MQ_MSG_BLOCK)?TRUE:FALSE;

	mbox = __lwp_mqbox_open(mqbox);
	if(!mbox) return FALSE;

	ret = FALSE;
	if(__lwpmq_submit(&mbox->mqueue,mbox->object.id,(void*)&msg,sizeof(mqmsg_t),LWP_MQ_SEND_URGENT,wait,LWP_THREADQ_NOTIMEOUT)==LWP_MQ_STATUS_SUCCESSFUL) ret = TRUE;
	__lwp_thread_dispatchenable();

	return ret;
}
예제 #21
0
void LWP_CloseQueue(lwpq_t thequeue)
{
	lwp_cntrl *thethread;
	tqueue_st *tq = (tqueue_st*)thequeue;

	tq = __lwp_tqueue_open(thequeue);
	if(!tq) return;
	
	do {
		thethread = __lwp_threadqueue_dequeue(&tq->tqueue);
	} while(thethread);
	__lwp_thread_dispatchenable();

	__lwp_tqueue_free(tq);
	return;
}
예제 #22
0
s32 LWP_InitQueue(lwpq_t *thequeue)
{
	tqueue_st *tq;

	if(!thequeue) return -1;

	tq = __lwp_tqueue_allocate();
	if(!tq) return -1;

	__lwp_threadqueue_init(&tq->tqueue,LWP_THREADQ_MODEFIFO,LWP_STATES_WAITING_ON_THREADQ,0);

	*thequeue = (lwpq_t)(LWP_OBJMASKTYPE(LWP_OBJTYPE_TQUEUE)|LWP_OBJMASKID(tq->object.id));
	__lwp_thread_dispatchenable();

	return 0;
}
예제 #23
0
s32 LWP_CondInit(cond_t *cond)
{
	cond_st *ret;

	if(!cond) return -1;

	ret = __lwp_cond_allocate();
	if(!ret) return ENOMEM;

	ret->lock = LWP_MUTEX_NULL;
	__lwp_threadqueue_init(&ret->wait_queue,LWP_THREADQ_MODEFIFO,LWP_STATES_WAITING_FOR_CONDVAR,ETIMEDOUT);

	*cond = (cond_t)(LWP_OBJMASKTYPE(LWP_OBJTYPE_COND)|LWP_OBJMASKID(ret->object.id));
	__lwp_thread_dispatchenable();

	return 0;
}
예제 #24
0
s32 LWP_ThreadSleep(lwpq_t thequeue)
{
	u32 level;
	tqueue_st *tq;
	lwp_cntrl *exec = NULL;

	tq = __lwp_tqueue_open(thequeue);
	if(!tq) return -1;

	exec = _thr_executing;
	_CPU_ISR_Disable(level);
	__lwp_threadqueue_csenter(&tq->tqueue);
	exec->wait.ret_code = 0;
	exec->wait.ret_arg = NULL;
	exec->wait.ret_arg_1 = NULL;
	exec->wait.queue = &tq->tqueue;
	exec->wait.id = thequeue;
	_CPU_ISR_Restore(level);
	__lwp_threadqueue_enqueue(&tq->tqueue,LWP_THREADQ_NOTIMEOUT);
	__lwp_thread_dispatchenable();
	return 0;
}
예제 #25
0
void LWP_YieldThread()
{
	__lwp_thread_dispatchdisable();
	__lwp_thread_yield();
	__lwp_thread_dispatchenable();
}
예제 #26
0
void LWP_Reschedule(u32 prio)
{
	__lwp_thread_dispatchdisable();
	__lwp_rotate_readyqueue(prio);
	__lwp_thread_dispatchenable();
}