1 /*********************************************************************************
3 * --------------------------------------------------------------------------------
5 * This file is part of MiMic
6 * Copyright (C)2011 Ryo Iizuka
8 * MiMic is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * For further information please contact.
23 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
25 *********************************************************************************/
26 #include "../NyLPC_cThread.h"
28 #if NyLPC_ARCH==NyLPC_ARCH_MBEDRTOS
32 static osPriority prio_table[]={
33 osPriorityNormal,osPriorityHigh};
37 static void proc(void const *argument)
39 NyLPC_TcThread_t* t=(NyLPC_TcThread_t*)argument;
42 Thread::wait(30);// danger wait!
43 }while(NyLPC_TUInt32_isBitOn(t->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED));
45 NyLPC_TUInt32_setBit(t->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED);
50 void NyLPC_cThread_initialize(NyLPC_TcThread_t* i_inst,NyLPC_TInt32 i_stack,NyLPC_TInt32 i_prio)
52 NyLPC_TUInt32_setBit(i_inst->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED);
53 i_inst->_thread=new Thread(proc,i_inst,prio_table[i_prio],i_stack);
55 void NyLPC_cThread_finalize(NyLPC_TcThread_t* i_inst)
57 NyLPC_cThread_join(i_inst);
58 delete (Thread*)(i_inst->_thread);
62 void NyLPC_cThread_start(NyLPC_TcThread_t* i_inst,NyLPC_TcThread_ThreadFunc i_func,void* i_param)
64 NyLPC_ArgAssert(i_inst!=NULL);
65 NyLPC_ArgAssert(i_func!=NULL);
71 void NyLPC_cThread_join(NyLPC_TcThread_t* i_inst)
73 NyLPC_TUInt32_setBit(i_inst->_sbit,NyLPC_TcThread_BIT_IS_JOIN_REQ);
74 while(!NyLPC_TUInt32_isBitOn(i_inst->_sbit,NyLPC_TcThread_BIT_IS_TERMINATED))
80 void NyLPC_cThread_sleep(NyLPC_TUInt32 i_time_in_msec)
83 Thread::wait(i_time_in_msec);
85 void NyLPC_cThread_yield(void)