/********************************************************* Signal to waiting threads bus reset completion */ HRESULT briSignalOnResetPreCompletion (void) { HRESULT hResult = NO_ERROR; uint32 waitingTasks = 0; if (!briInitialized) { hResult = E_BRI_NOT_INITIALIZED_FATAL; sysLogError(hResult, __LINE__, moduleName); return hResult; } // Exclusive exclusive access for briPreCompletionWaitingTasks (mutex) hResult = TCMutexLock(briPreCompletionMutexSemID); if (hResult != NO_ERROR) return hResult; waitingTasks = briPreCompletionWaitingTasks; briPreCompletionWaitingTasks = 0; // Release exclusive access for briPreCompletionWaitingTasks (mutex) TCMutexUnlock(briPreCompletionMutexSemID); if (waitingTasks > 0) { while (waitingTasks--) { TCSemaphoreSignal(briPreCompletionSemID); } } return hResult; }
HRESULT crRemoveCallback(CALLBACK_DESCRIPTOR* callback) { HRESULT hResult = NO_ERROR; CALLBACK_DESCRIPTOR* prev = NULL; CALLBACK_DESCRIPTOR* next = NULL; if (crFindCallback(CR_FIND_CALLBACK_PREV, 0, 0, callback, &prev) == FALSE) { hResult = E_AVC_CR_CALLBACK_NOT_FOUND; sysLogError(hResult, __LINE__, moduleName); return hResult; } // exclusive access for the cr list (mutex) hResult = TCMutexLock(crListMutexSemID); if (hResult != NO_ERROR) return hResult; kvGetValue(callback, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next); kvSetValue(callback, CALLBACK_DESCRIPTOR_NEXT, 0); kvSetValue(prev, CALLBACK_DESCRIPTOR_NEXT, (uint32) next); if (crDescHead == callback) { crDescHead = next; } // exclusive access for the cr list (mutex) TCMutexUnlock(crListMutexSemID); return hResult; }
/********************************************************* Wait for a bus reset pre completion */ HRESULT briWaitOnResetPreCompletion (BOOL *bResetDetected) { HRESULT hResult = NO_ERROR; *bResetDetected = FALSE; if (!briInitialized) { hResult = E_BRI_NOT_INITIALIZED_FATAL; sysLogError(hResult, __LINE__, moduleName); return hResult; } // exclusive access for briPreCompletionWaitingTasks (mutex) hResult = TCMutexLock(briPreCompletionMutexSemID); if (hResult != NO_ERROR) return hResult; if (briInBusResetProgress == TRUE && briPreCompletionDone == FALSE) { *bResetDetected = TRUE; briPreCompletionWaitingTasks++; } // Release exclusive access for briPreCompletionWaitingTasks (mutex) TCMutexUnlock(briPreCompletionMutexSemID); if (*bResetDetected == TRUE) { hResult = TCSemaphoreWait(briPreCompletionSemID); if (hResult != NO_ERROR) return hResult; } return hResult; }
HRESULT crAddCallback(CALLBACK_DESCRIPTOR* callback) { HRESULT hResult = NO_ERROR; // First check for required key types, these are described in the cr.h hResult = kvIsKey(callback, CALLBACK_DESCRIPTOR_TYPE); if (hResult != NO_ERROR) return hResult; hResult = kvIsKey(callback, CALLBACK_DESCRIPTOR_NEXT); if (hResult != NO_ERROR) return hResult; #ifdef _SYSDEBUG // check in debug mode never to allow adding of the same element twice if (crFindCallback(CR_FIND_CALLBACK_THIS, 0, 0, callback, &callback) == TRUE) { char* name = NULL; kvGetValue(callback, CALLBACK_DESCRIPTOR_NAME, (uint32*) &name); sysDebugPrintf("cr error: can't add callback '%s'(0x%08X) twice\n\r", (name) ? name : "un-named", callback); } #endif //_SYSDEBUG // exclusive access for the cr list (mutex) hResult = TCMutexLock(crListMutexSemID); if (hResult != NO_ERROR) return hResult; // need to link this descriptor into the list, by making the crDescHead the next element, and making this the crDescHead kvSetValue(callback, CALLBACK_DESCRIPTOR_NEXT, (uint32) crDescHead); crDescHead = callback; // exclusive access for the cr list (mutex) TCMutexUnlock(crListMutexSemID); return hResult; }
HRESULT lhlStatusQueueCreate(STATUS_INFO **statusInfo) { HRESULT hResult = NO_ERROR; uint32 index; uint32 ptr; BOOL bFound = FALSE; // exclusive access for the statusInfoQueue (mutex) hResult = TCMutexLock(lhlStatusQueueMutexSemID); if (hResult != NO_ERROR) return hResult; *statusInfo = NULL; // find a free statusInfo from the pool ptr = statusInfoQueue.ptr; for (index = 0; index < STATUS_INFO_ITEMS; index++) { if (statusInfoQueue.allocated[ptr] == FALSE) { *statusInfo = &statusInfoQueue.statusInfo[ptr]; lhlStatusQueueResetInfo(*statusInfo); statusInfoQueue.allocated[ptr] = TRUE; bFound = TRUE; #ifdef _STATISTICS lhlStatistics.statusInfoInuse++; if (lhlStatistics.statusInfoInuseMax < lhlStatistics.statusInfoInuse) { lhlStatistics.statusInfoInuseMax = lhlStatistics.statusInfoInuse; } #endif //_STATISTICS } ptr = (ptr + 1) % STATUS_INFO_ITEMS; if (bFound == TRUE) { statusInfoQueue.ptr = ptr; break; } } if (bFound == FALSE) { SYS_DEBUG(SYSDEBUG_TRACE_WARNINGS, "lhlStatusQueue: No more free status info items\n\r"); hResult = E_NULL_PTR; sysLogError(hResult, __LINE__, moduleName); } // exclusive access for the statusInfoQueue (mutex) TCMutexUnlock(lhlStatusQueueMutexSemID); return hResult; }
HRESULT lmHandleListElement(LM_CONTEXT* list, BOOL bIndexed, uint32 index, LM_HANDLE_INDEX_ELEMENT_CB callback, void **data, uint32 *arg1, uint32 *arg2) { HRESULT hResult = NO_ERROR; LM_ELEMENT* elem = 0; if (list == NULL) { hResult = E_NULL_PTR; sysLogError(hResult, __LINE__, moduleName); return hResult; } // Exclusive access for accessing list (mutex) hResult = TCMutexLock(list->lmMutexSemID); if (hResult != NO_ERROR) return hResult; elem = (LM_ELEMENT*) &(list->elements); if (bIndexed) { // call indexed elem if (index < list->elemcount) { lmMoveAheadElementSizeItems(list->elemsize, &elem, index); hResult = (callback) (list, index, elem, data, arg1, arg2); } else { hResult = E_LM_ELEMENT_UNAVAILABLE; } } else { // walk through the list elements and call for each elem uint32 count = 0; for (count = 0; count < list->elemcount; count++) { hResult = (callback) (list, count, elem, data, arg1, arg2); if (hResult != E_LM_ELEMENT_NOT_FOUND) break; lmMoveAheadElementSize(list->elemsize, &elem); } if (count == list->elemcount) { hResult = E_LM_ELEMENT_UNAVAILABLE; } } // Release exclusive for accessing list (mutex) TCMutexUnlock(list->lmMutexSemID); return hResult; }
static HRESULT lhlStatusQueueDisplay(void) { HRESULT hResult = NO_ERROR; // exclusive access for the pending transactions table (mutex) hResult = TCMutexLock(lhlStatusQueueMutexSemID); if (hResult != NO_ERROR) return hResult; hResult = __lhlStatusQueueDisplay(); // exclusive access for the pending transactions table (mutex) TCMutexUnlock(lhlStatusQueueMutexSemID); return hResult; }
HRESULT lmDisposeList(LM_CONTEXT* list) { HRESULT hResult = NO_ERROR; if (list == NULL) { hResult = E_NULL_PTR; sysLogError(hResult, __LINE__, moduleName); return hResult; } // Exclusive access for accessing list (mutex) hResult = TCMutexLock(list->lmMutexSemID); if (hResult != NO_ERROR) return hResult; memset(list, 0, list->listsize); // Release exclusive for accessing list (mutex) TCMutexUnlock(list->lmMutexSemID); return hResult; }
HRESULT lhlStatusQueueMatch(uint32 nodeAddr, uint32 tLabel, uint32 genType, PB_PACKETTYPE packetType, STATUS_INFO **statusInfo, BOOL bRemoveEntry) { HRESULT hResult = NO_ERROR; uint32 index; STATUS_INFO *si = NULL; BOOL bFound = FALSE; // exclusive access for the statusInfoQueue (mutex) hResult = TCMutexLock(lhlStatusQueueMutexSemID); if (hResult != NO_ERROR) return hResult; if (statusInfo) { *statusInfo = NULL; } // find a matching statusInfo from the pool for (index = 0; index < STATUS_INFO_ITEMS; index++) { si = &statusInfoQueue.statusInfo[index]; if (statusInfoQueue.allocated[index] == TRUE) { if (si->nodeAddr == nodeAddr && si->tLabel == tLabel && si->packetType == packetType && si->genType == genType) { bFound = TRUE; if (statusInfo) { *statusInfo = si; } if (bRemoveEntry) { hResult = si->hResultFinal; lhlStatusQueueResetInfo(si); statusInfoQueue.allocated[index] = FALSE; statusInfoQueue.ptr = index; #ifdef _STATISTICS lhlStatistics.statusInfoInuse--; #endif //_STATISTICS } break; } } } if (bFound == FALSE || (statusInfo && *statusInfo == NULL)) { SYS_DEBUG(SYSDEBUG_TRACE_WARNINGS, "lhlStatusQueue: No match nodeAddr 0x%04x, tLabel 0x%04x, pckType:0x%04x, genType:0x%04x\n\r", nodeAddr, tLabel, packetType, genType); #ifdef _SYSDEBUGERROR if (sysDebugIsEnabled(SYSDEBUG_TRACE_ERRORS)) { sysDebugPrintf("lhlStatusQueueMatch\n\r"); __lhlStatusQueueDisplay(); } #endif //_SYSDEBUGERROR hResult = E_NULL_PTR; sysLogError(hResult, __LINE__, moduleName); } // exclusive access for the statusInfoQueue (mutex) TCMutexUnlock(lhlStatusQueueMutexSemID); return hResult; }
BOOL crFindCallback(uint32 mode, uint32 type, uint32 index, CALLBACK_DESCRIPTOR* findcallback, CALLBACK_DESCRIPTOR** callback) { HRESULT hResult = NO_ERROR; CALLBACK_DESCRIPTOR* current = crDescHead; CALLBACK_DESCRIPTOR* next = NULL; uint32 counter = 0; uint32 foundtype = 0; BOOL bFound = FALSE; // exclusive access for the cr list (mutex) hResult = TCMutexLock(crListMutexSemID); if (hResult != NO_ERROR) return FALSE; while (current) { switch (mode) { case CR_FIND_CALLBACK_TYPE: kvGetValue(current, CALLBACK_DESCRIPTOR_TYPE, &foundtype); if (foundtype == type) { bFound = (counter == index); counter++; } break; case CR_FIND_CALLBACK_FIRST: bFound = TRUE; break; case CR_FIND_CALLBACK_THIS: bFound = (current == findcallback); break; case CR_FIND_CALLBACK_PREV: kvGetValue(current, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next); if (!next) break; bFound = (next == findcallback); break; case CR_FIND_CALLBACK_NEXT: kvGetValue(findcallback, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next); current = next; if (!current) continue; bFound = TRUE; break; } if (bFound == TRUE) { *callback = current; break; } kvGetValue(current, CALLBACK_DESCRIPTOR_NEXT, (uint32 *) &next); if (!next) break; current = next; } // exclusive access for the cr list (mutex) TCMutexUnlock(crListMutexSemID); return bFound; }