int paHandleManager :: allocate(int nh) { if (m_nMaxHandles != 0) return -1; //error already allocated. m_nMaxHandles = nh; m_nActiveHandles = 0; m_handle = (int*)paMalloc( nh * sizeof(int)); m_handle2index = (int*)paMalloc( nh * sizeof(int)); //error test for memory allocation failure. paAssert(m_handle != 0); paAssert(m_handle2index != 0); // Assign unique numeric handles for each index. // park free handles with '-1' int i; for(i=0; i<nh; i++) { m_handle[i] = i; m_handle2index[i] = -1; } return 0; }
int paImpact :: deleteImpact(paImpact* i) { paLOCKCHECK paAssert(i && "Impact not valid."); // if (i==0) return -1; paAssert(i->m_poolHandle != -1 && "Impact not in use."); // if (i->m_poolHandle == -1) return -1; //error - contact not being used. i->terminate(); paImpact::pool.deleteActiveObject(i->m_poolHandle); i->m_poolHandle = -1; return 0; }
PHYA_API void paLock() { if (!paScene::audioThreadIsOn) return; paAssert(("Already locked.", paScene::isLocked == false)); // Happens if you call paLock twice in same thread. paEnterCriticalSection(&_critSec); paScene::isLocked = true; }
PHYA_API void paUnlock() { if (!paScene::audioThreadIsOn) return; paAssert(("Not locked.", paScene::isLocked == true)); paLeaveCriticalSection(&_critSec); paScene::isLocked = false; }
// static int paContact :: deleteContact(paContact* c) { // paLOCKCHECK // Can't use flag checking inside audio thread. paAssert(c && "Contact not valid."); // if (c==0) return -1; paAssert(c->m_poolHandle != -1 && "Contact not in use."); // if (c->m_poolHandle == -1) return -1; //error - contact not being used. c->terminate(); pool.deleteActiveObject(c->m_poolHandle); //gpc--; //printf("%d\n",gpc); c->m_poolHandle = -1; return 0; }
paThreadHandle paStartThread(unsigned (_stdcall *func)(void*)) { DWORD dwThreadID; HANDLE h; // HANDLE hprocess; BOOL result; // DWORD err; // hprocess = GetCurrentProcess(); // err = GetLastError(); // result = SetPriorityClass(hprocess, HIGH_PRIORITY_CLASS); // err = GetLastError(); // err = GetLastError(); h = (HANDLE)_beginthreadex(NULL, 0, func, NULL, 0, (unsigned*)&dwThreadID); paAssert(h != 0); // err = GetLastError(); // THREAD_PRIORITY_TIME_CRITICAL THREAD_PRIORITY_ABOVE_NORMAL result = SetThreadPriority(h, THREAD_PRIORITY_NORMAL); paAssert(result != 0); return h; }
int paHandleManager :: deleteHandle(int deletedHandle) { int deletedHandleIndex = m_handle2index[deletedHandle]; paAssert(deletedHandleIndex != -1); if (deletedHandleIndex == -1) return -1; //error -handle was free already. m_nActiveHandles--; int lastHandleIndex = m_nActiveHandles; // Biggest index of the active handles. int lastHandle = m_handle[lastHandleIndex]; // Mark deleted handle as free - used to check that a handle is active before deleting. m_handle2index[deletedHandle] = -1; if (m_nActiveHandles == 0 || lastHandle == deletedHandle) return 0; // No moving required. // When ennumerating the handle list with getNextHandle, we may want to delete // the last handle read. The following line ensures that the rest of the list // can be ennumerated without a glitch, by back tracking to the slot where the // 'lastHandle' has moved to. if (deletedHandleIndex == m_handleCounter -1) m_handleCounter--; //error - should check that we havn't attempted to delete a handle previously // ennumerated while handles remain in the ennumeration. // Move the deleted handle to the new first free handle index. m_handle[m_nActiveHandles] = deletedHandle; // Move the displaced 'lastHandle' to where the deleted handle was. m_handle[deletedHandleIndex] = lastHandle; m_handle2index[lastHandle] = deletedHandleIndex; return 0; }