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; 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); }