static int Set(systimer* p, int No, const void* Data, int Size) { int Result = ERR_INVALID_PARAM; switch (No) { case TIMER_TIME: assert(Size == sizeof(tick_t)); LockEnter(p->Section); p->TickStart = *(tick_t*)Data; p->TimeRef = GetTimeTick(); LockLeave(p->Section); Result = ERR_NONE; break; case TIMER_SPEED: assert(Size == sizeof(fraction)); if (!EqFrac(&p->Speed, (const fraction*)Data)) { LockEnter(p->Section); if (p->Play) { int t = GetTimeTick(); p->TickStart += Scale(t-p->TimeRef,p->SpeedTime.Num,p->SpeedTime.Den); p->TimeRef = t; } p->Speed = *(fraction*)Data; p->SpeedTime = p->Speed; p->SpeedTime.Num *= TICKSPERSEC; p->SpeedTime.Den *= GetTimeFreq(); LockLeave(p->Section); } Result = ERR_NONE; break; case TIMER_PLAY: assert(Size == sizeof(bool_t)); if (p->Play != *(bool_t*)Data) { int t; LockEnter(p->Section); t = GetTimeTick(); p->Play = *(bool_t*)Data; if (!p->Play) // save time p->TickStart += Scale(t-p->TimeRef,p->SpeedTime.Num,p->SpeedTime.Den); p->TimeRef = t; LockLeave(p->Section); } Result = ERR_NONE; break; } return Result; }
static NOINLINE int FindModule(context* p,const tchar_t* Path,int Id) { // important to find from the begining for Palm OS // so the exising plugins are found first int No,Count; int Result = -1; LockEnter(p->NodeLock); Count = ARRAYCOUNT(p->NodeModule,nodemodule); if (!Path) Path = T(""); for (No=0;No<Count;++No) { bool_t SameId = ARRAYBEGIN(p->NodeModule,nodemodule)[No].Id == Id; bool_t SameName = TcsICmp(Path,StringDef(MODULE_PATH,No))==0; if (SameId && Id!=0) // same Id means same module SameName = 1; if (SameName && !Id) SameId = 1; if (SameId && SameName) { Result = No; break; } } LockLeave(p->NodeLock); return Result; }
void NodeAddModule(const tchar_t* Path,int Id,int64_t Date,bool_t Load,bool_t Tmp) { context* p = Context(); LockEnter(p->NodeLock); if (ArrayAppend(&p->NodeModule,NULL,sizeof(nodemodule),256)) { int No = ARRAYCOUNT(p->NodeModule,nodemodule)-1; nodemodule* Module = ARRAYBEGIN(p->NodeModule,nodemodule)+No; memset(Module,0,sizeof(nodemodule)); Module->Id = Id; Module->Date = Date; Module->Tmp = Tmp; StringAdd(1,MODULE_PATH,No,Path); if (Load) { p->LoadModuleNo = No; Module->Module = NodeLoadModule(Path,&Module->Id,&Module->Func,&Module->Db); p->LoadModuleNo = 0; #ifdef PLUGINCLEANUP FreeModule(Module); #endif } } LockLeave(p->NodeLock); }
void NodeTree_MoveBefore(void* p, void* Before) { if (p != Before) { nodetree* Parent; LockEnter(Node_Context(p)->NodeLock); Parent = NodeTree_Parent(p); RemoveChild(Parent,p); AddChild(Parent,p,Before); LockLeave(Node_Context(p)->NodeLock); } }
bool_t ConditionWait(void* Handle, int Tick, void *Lock) { condition_t *cond = (condition_t *)Handle; bool_t ret; InterlockedIncrement(&cond->waiters); LockLeave(Lock); ret = SemaphoreWait(cond->semaphore, Tick); if (!ret) InterlockedDecrement(&cond->waiters); LockEnter(Lock); return ret; }
static err_t AddChild(nodetree* p,nodetree* Child, nodetree* Before) { nodetree** i; LockEnter(Node_Context(p)->NodeLock); for (i=&p->Children;*i;i=&(*i)->Next) if (*i == Before) break; Child->Parent = p; Child->Next = Before; *i = Child; LockLeave(Node_Context(p)->NodeLock); return ERR_NONE; }
static void RemoveChild(nodetree* p,nodetree* Child) { nodetree** i; LockEnter(Node_Context(p)->NodeLock); for (i=&p->Children;*i;i=&(*i)->Next) if (*i==Child) { *i=Child->Next; break; } Child->Next = NULL; Child->Parent = NULL; LockLeave(Node_Context(p)->NodeLock); }
static int Get(systimer* p, int No, void* Data, int Size) { int Result = ERR_INVALID_PARAM; switch (No) { case TIMER_PLAY: GETVALUE(p->Play,bool_t); break; case TIMER_SPEED: GETVALUE(p->Speed,fraction); break; case TIMER_TIME: assert(Size == sizeof(tick_t)); LockEnter(p->Section); if (p->Speed.Num==0) // benchmark mode *(tick_t*)Data = TIME_BENCH; else if (p->Play) *(tick_t*)Data = p->TickStart + Scale(GetTimeTick()-p->TimeRef,p->SpeedTime.Num,p->SpeedTime.Den); else *(tick_t*)Data = p->TickStart; LockLeave(p->Section); Result = ERR_NONE; break; } return Result; }