void TThread::Cancel() { TLock Lck(CriticalSection); if (!IsAlive()) { return; } Status = STATUS_CANCELLED; int code = pthread_cancel(ThreadHandle); EAssertR(code == 0, "Failed to cancel thread!"); }
bool BufferManager::PutIn(PACKET& packet) { std::unique_lock<std::mutex> Lck(m_localbufferMutex); if (GetRemainBufferInSecond() <= 0) { m_localbufferCV.wait(Lck); } m_localbuffer->push_back(packet); return true; }
HRESULT CAMRSplitter::RemoveOutputPins() { CAutoLock Lck(&lock_filter); if (m_State != State_Stopped) { return VFW_E_NOT_STOPPED; } // we retire all current output pins for (int i=0; i<output.GetCount(); i++) { CAMROutputPin *pin = output[i]; if (pin->IsConnected()) { pin->GetConnected()->Disconnect(); pin->Disconnect(); } retired.Add(pin); } output.RemoveAll(); return NOERROR; }
bool BufferManager::PullOut(PACKET& packet) { std::unique_lock<std::mutex> Lck(m_localbufferMutex); if (!m_localbuffer->empty()) { packet = m_localbuffer->front(); m_localbuffer->pop_front(); if (GetRemainBufferInSecond() <= MAX_BUFFER_SIZE_IN_SECONDS / 2) { m_localbufferCV.notify_one(); } } else { //std::cout << "buffer is empty" << std::endl; return false; } return true; }
GRect &GWindow::GetPos() { static GRect r; r = Pos; GLocker Lck(Wnd, _FL); if (Lck.Lock()) { BRect frame = Wnd->Frame(); r.x1 = frame.left; r.y1 = frame.top; r.x2 = frame.right; r.y2 = frame.bottom; Pos = frame; Lck.Unlock(); } return r; }
void TThread::Start() { TLock Lck(CriticalSection); if (IsAlive()) { printf("Tried to start a thread that is already alive! Ignoring ...\n"); return; } if (IsCancelled()) { return; } Status = STATUS_STARTED; // create new thread int code = pthread_create( &ThreadHandle, // Handle NULL, // Attributes EntryPoint, // Thread func this // Arg ); EAssert(code == 0); }
bool TThread::IsFinished() { TLock Lck(CriticalSection); return Status == STATUS_FINISHED; }
bool TThread::IsCancelled() { TLock Lck(CriticalSection); return Status == STATUS_CANCELLED; }
bool TThread::IsAlive() { TLock Lck(CriticalSection); return Status == STATUS_STARTED || IsCancelled(); }
TThread::~TThread() { TLock Lck(CriticalSection); if (IsAlive() && !IsCancelled()) { Cancel(); } }
void TThread::SetFinished(void *pArg) { TThread *pThis = (TThread *) pArg; TLock Lck(pThis->CriticalSection); pThis->Status = STATUS_FINISHED; }
void BufferManager::SubDurationRemain(double duration) { std::unique_lock<std::mutex> Lck(m_localbufferMutex); m_buffer_in_duration_remain -= duration; }