/********************************************************************* * * GUI_TIMER_Delete */ void GUI_TIMER_Delete(GUI_TIMER_HANDLE hObj) { /* Unlink Timer */ GUI_LOCK(); _Unlink(hObj); GUI_ALLOC_Free(hObj); GUI_UNLOCK(); }
// Alloc -- Allocate Memory ----------------------------------------CHeapBlock- // // Locate acceptable free block in free pool. Split block if larger than // required and link second half of block on free list. // // NOTE: Must be re-entrant // void *CHeapBlock::Alloc(U32 &nBytes, U32 raAlloc) { if (nBytes < sUnit_) nBytes = sUnit_; nBytes = (nBytes + (ALIGNSIZE-1)) & ~ALIGNMASK; Critical section; for (BLKHEAD *pBlk = _LockFirst(); pBlk != NULL; pBlk = _LockNext(pBlk)) { if (nBytes <= pBlk->sThis) { // Found 1st fit _Unlink(pBlk); pBlk->tThis = TYPEALLOC; if (nBytes + sSplit_ <= pBlk->sThis) // Split free block _SplitBlk(pBlk,nBytes); #ifdef _HEAPCHECK pBlk->raAlloc = raAlloc; #endif return pBlk+1; // return &<data> } } Tracef("CHeapBlock::Alloc(%u) returning NULL!\n", nBytes); return NULL; }
/********************************************************************* * * GUI_TIMER_SetDelay */ void GUI_TIMER_SetDelay(GUI_TIMER_HANDLE hObj, GUI_TIMER_TIME Delay) { GUI_LOCK(); { GUI_TIMER_Obj* pObj = GUI_TIMER_H2P(hObj); pObj->t0 = Delay; _Unlink(hObj); _Link(hObj); } GUI_UNLOCK(); }
/********************************************************************* * * GUI_TIMER_Restart */ void GUI_TIMER_Restart(GUI_TIMER_HANDLE hObj) { GUI_TIMER_Obj* pObj; GUI_LOCK(); { if (hObj == 0) { hObj = _hActiveTimer; } pObj = GUI_TIMER_H2P(hObj); pObj->t0 = GUI_GetTime() +pObj->Period; _Unlink(hObj); _Link(hObj); } GUI_UNLOCK(); }
// Free -- Free Memory ---------------------------------------------CHeapBlock- // // When a block is freed it is merged with previous and next block // if they are free. If merged with next block then next block is // removed from list. If not merged with either block then this // block is added to free list. // // NULL pointers and invalid block pointers are ignored. // // NOTE: Must be re-entrant // U32 CHeapBlock::Free(void *pData) { BLKHEAD *pBlk,*pPrevBlk,*pNextBlk; U32 cbRet=0; if (pData != NULL) { pBlk = GetBlk(pData); // Check if allocated block if (pBlk->tThis == TYPEALLOC) { Critical section; cbRet=pBlk->sThis; FREE(cbRet, pBlk->raAlloc); // Merge with next block if it is free pNextBlk = GetNext(pBlk); if (pNextBlk->tThis == TYPEFREE) { _Unlink(pNextBlk); pBlk->sThis += pNextBlk->sThis + sizeof(BLKHEAD); GetNext(pBlk)->sPrev = pBlk->sThis; } // Merge with previous block if it is free pPrevBlk = GetPrev(pBlk); if (pPrevBlk->tThis != TYPEFREE) { pBlk->tThis = TYPEFREE; _Link(pBlk); } else { pPrevBlk->sThis += pBlk->sThis + sizeof(BLKHEAD); GetNext(pPrevBlk)->sPrev = pPrevBlk->sThis; } } } return cbRet; }