//------------------------------------------------------------------------------ // Function: ShbIpcReleaseBuffer // // Description: Releases a shared buffer // // Parameters: pShbInstance_p pointer to shared buffer instance // // Return: tShbError = error code //------------------------------------------------------------------------------ tShbError ShbIpcReleaseBuffer (tShbInstance pShbInstance_p) { tShbMemInst* pShbMemInst; tShbMemHeader* pShbMemHeader; tShbError ShbError; if (pShbInstance_p == NULL) { return (kShbInvalidArg); } pShbMemInst = ShbIpcGetShbMemInst(pShbInstance_p); pShbMemHeader = ShbIpcGetShbMemHeader(pShbInstance_p); EPL_DBGLVL_SHB_TRACE("%s() pShbInstance=%p pShbMemHeader=%p\n", __func__, (void *)pShbInstance_p, (void *)pShbMemHeader); // stop threads in any case, because they are bound to that specific instance ShbIpcStopSignalingNewData (pShbInstance_p); pShbMemHeader->m_ulRefCount--; if(pShbMemHeader->m_ulRefCount == 0) { EPL_DBGLVL_SHB_TRACE("%s() refCount = 0, destroy shared mem\n", __func__); //delete semaphores semDelete(pShbMemHeader->m_mutexBuffAccess); semDelete(pShbMemHeader->m_semNewData); semDelete(pShbMemHeader->m_semJobReady); semDelete(pShbMemHeader->m_semStopSignalingNewData); //destroy Buffer ShbIpcFree(pShbMemHeader->m_uiBufferKey); ShbError = kShbOk; } else { EPL_DBGLVL_SHB_TRACE("%s() refCount > 0, detach from shared mem\n", __func__); ShbError = kShbMemUsedByOtherProcs; } //delete privat mem ShbIpcReleasePrivateMem (pShbMemInst); return (ShbError); }
tShbError ShbIpcReleaseBuffer (tShbInstance pShbInstance_p) { tShbMemInst* pShbMemInst; tShbMemHeader* pShbMemHeader; tShbError ShbError; tShbError ShbError2; DEBUG_LVL_26_TRACE1("ShbIpcReleaseBuffer(%p)\n", pShbInstance_p); if (pShbInstance_p == NULL) { return (kShbOk); } pShbMemInst = ShbIpcGetShbMemInst (pShbInstance_p); pShbMemHeader = ShbIpcGetShbMemHeader (pShbMemInst); // stop threads in any case, because they are bound to that specific instance ShbError2 = ShbIpcStopSignalingNewData (pShbInstance_p); down(&pShbMemInst->m_SemaphoreStopThreadJobReady); if (pShbMemInst->m_tThreadJobReadyId != INVALID_ID) { kthread_stop(pShbMemInst->m_tThreadJobReadyId); } up(&pShbMemInst->m_SemaphoreStopThreadJobReady); if ( !--pShbMemHeader->m_ulRefCount ) { ShbError = kShbOk; // delete mem table element ShbIpcDeleteListElement(pShbMemHeader->m_iBufferId); // delete shared mem kfree(pShbMemInst->m_pShbMemHeader); } else { ShbError = kShbMemUsedByOtherProcs; } //delete privat mem kfree(pShbMemInst); return (ShbError); }
tShbError ShbIpcReleaseBuffer ( tShbInstance pShbInstance_p) { tShbMemInst* pShbMemInst; tShbMemHeader* pShbMemHeader; HANDLE hEventNewData; HANDLE hMutexBuffAccess; tShbError ShbError; tShbError ShbError2; if (pShbInstance_p == NULL) { return (kShbOk); } pShbMemInst = ShbIpcGetShbMemInst (pShbInstance_p); pShbMemHeader = ShbIpcGetShbMemHeader (pShbInstance_p); if ( !--pShbMemHeader->m_ulRefCount ) { ShbError = kShbOk; } else { ShbError = kShbMemUsedByOtherProcs; } ShbError2 = ShbIpcStopSignalingNewData (pShbInstance_p); hEventNewData = pShbMemInst->m_ahEventNewData[IDX_EVENT_NEW_DATA]; if (hEventNewData != INVALID_HANDLE_VALUE) { CloseHandle (hEventNewData); pShbMemInst->m_ahEventNewData[IDX_EVENT_NEW_DATA] = INVALID_HANDLE_VALUE; } hMutexBuffAccess = pShbMemInst->m_hMutexBuffAccess; if (hMutexBuffAccess != INVALID_HANDLE_VALUE) { CloseHandle (hMutexBuffAccess); pShbMemInst->m_hMutexBuffAccess = INVALID_HANDLE_VALUE; } UnmapViewOfFile (pShbMemHeader); if (pShbMemInst->m_hSharedMem != INVALID_HANDLE_VALUE) { CloseHandle (pShbMemInst->m_hSharedMem); pShbMemInst->m_hSharedMem = INVALID_HANDLE_VALUE; } ShbIpcReleasePrivateMem (pShbMemInst); if (ShbError == kShbOk) { ShbError = ShbError2; } return (ShbError); }
tShbError ShbIpcReleaseBuffer (tShbInstance pShbInstance_p) { tShbMemInst* pShbMemInst; tShbMemInst** ppShbMemInst; tShbMemHeader* pShbMemHeader; tShbError ShbError; DEBUG_LVL_26_TRACE("ShbIpcReleaseBuffer(%p)\n", pShbInstance_p); if (ShbTgtIsInterruptContext()) { return (kShbInterruptContextNotAllowed); } if (pShbInstance_p == NULL) { return (kShbOk); } pShbMemInst = ShbIpcGetShbMemInst (pShbInstance_p); pShbMemHeader = ShbIpcGetShbMemHeader (pShbMemInst); ShbIpcStopSignalingNewData (pShbInstance_p); // remove ShbMemInst from JobReady process list if signaling ppShbMemInst = &pShbIpcProcessListJobReadyFirst_g; while (*ppShbMemInst != NULL) { if (*ppShbMemInst == pShbMemInst) { if (pShbMemInst->m_pProcessListJobReadyNext == NULL) { ShbIpcEnterAtomicSection(NULL); *ppShbMemInst = pShbMemInst->m_pProcessListJobReadyNext; ShbIpcLeaveAtomicSection(NULL); } else { *ppShbMemInst = pShbMemInst->m_pProcessListJobReadyNext; } if (ppShbIpcProcessListJobReadyCurrent_g == &pShbMemInst->m_pProcessListJobReadyNext) { ppShbIpcProcessListJobReadyCurrent_g = ppShbMemInst; } break; } ppShbMemInst = &(*ppShbMemInst)->m_pProcessListJobReadyNext; } if ( !--pShbMemHeader->m_ulRefCount ) { ShbError = kShbOk; // delete mem table element ShbIpcDeleteListElement(pShbMemHeader->m_iBufferId); // delete shared mem free(pShbMemInst->m_pShbMemHeader); } else { ShbError = kShbMemUsedByOtherProcs; } //delete privat mem free(pShbMemInst); return (ShbError); }