Remove SetNotAlive method from the thread class.

Also cleaning up methods with the same name in other classes that are derived from the above method.

R=perkj@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/41759004

Cr-Commit-Position: refs/heads/master@{#8242}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8242 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tommi@webrtc.org 2015-02-04 11:11:53 +00:00
parent c5f697135e
commit 875c97ed9d
37 changed files with 18 additions and 86 deletions

View File

@ -227,7 +227,6 @@ int32_t AudioRecordJni::Terminate() {
ThreadWrapper* tmpThread = _ptrThreadRec;
_ptrThreadRec = NULL;
_critSect.Leave();
tmpThread->SetNotAlive();
// Release again, we might have returned to waiting state
_timeEventRec.Set();
if (tmpThread->Stop())

View File

@ -221,7 +221,6 @@ int32_t AudioTrackJni::Terminate() {
ThreadWrapper* tmpThread = _ptrThreadPlay;
_ptrThreadPlay = NULL;
_critSect.Leave();
tmpThread->SetNotAlive();
_timeEventPlay.Set();
if (tmpThread->Stop())
{

View File

@ -218,8 +218,6 @@ int32_t AudioDeviceLinuxALSA::Terminate()
_ptrThreadRec = NULL;
_critSect.Leave();
tmpThread->SetNotAlive();
if (tmpThread->Stop())
{
delete tmpThread;
@ -240,8 +238,6 @@ int32_t AudioDeviceLinuxALSA::Terminate()
_ptrThreadPlay = NULL;
_critSect.Leave();
tmpThread->SetNotAlive();
if (tmpThread->Stop())
{
delete tmpThread;

View File

@ -280,7 +280,6 @@ int32_t AudioDeviceLinuxPulse::Terminate()
_ptrThreadRec = NULL;
UnLock();
tmpThread->SetNotAlive();
_timeEventRec.Set();
if (tmpThread->Stop())
{
@ -301,7 +300,6 @@ int32_t AudioDeviceLinuxPulse::Terminate()
_ptrThreadPlay = NULL;
_critSect.Leave();
tmpThread->SetNotAlive();
_timeEventPlay.Set();
if (tmpThread->Stop())
{

View File

@ -330,7 +330,6 @@ int32_t AudioDeviceWindowsWave::Terminate()
_ptrThread = NULL;
_critSect.Leave();
tmpThread->SetNotAlive();
_timeEvent.Set();
if (tmpThread->Stop())

View File

@ -918,7 +918,6 @@ MatlabEngine::~MatlabEngine()
if (_plotThread)
{
_plotThread->SetNotAlive();
_running = false;
_eventPtr->Set();

View File

@ -100,7 +100,6 @@ int32_t TestLoadGenerator::Stop ()
if (_genThread)
{
_genThread->SetNotAlive();
_running = false;
_eventPtr->Set();

View File

@ -199,7 +199,6 @@ int32_t TestSenderReceiver::Stop ()
if (_procThread)
{
_procThread->SetNotAlive();
_running = false;
_eventPtr->Set();

View File

@ -457,8 +457,6 @@ bool AviRecorder::StopThread()
if(_thread)
{
_thread->SetNotAlive();
ThreadWrapper* thread = _thread;
_thread = NULL;

View File

@ -65,8 +65,6 @@ int32_t ProcessThreadImpl::Stop()
_critSectModules->Enter();
if(_thread)
{
_thread->SetNotAlive();
ThreadWrapper* thread = _thread;
_thread = NULL;

View File

@ -47,17 +47,17 @@ VideoCaptureModule* VideoCaptureImpl::Create(const int32_t id,
}
VideoCaptureModuleV4L2::VideoCaptureModuleV4L2(const int32_t id)
: VideoCaptureImpl(id),
: VideoCaptureImpl(id),
_captureThread(NULL),
_captureCritSect(CriticalSectionWrapper::CreateCriticalSection()),
_deviceId(-1),
_deviceId(-1),
_deviceFd(-1),
_buffersAllocatedByDevice(-1),
_currentWidth(-1),
_currentWidth(-1),
_currentHeight(-1),
_currentFrameRate(-1),
_currentFrameRate(-1),
_captureStarted(false),
_captureVideoType(kVideoI420),
_captureVideoType(kVideoI420),
_pool(NULL)
{
}
@ -306,7 +306,6 @@ int32_t VideoCaptureModuleV4L2::StopCapture()
{
if (_captureThread) {
// Make sure the capture thread stop stop using the critsect.
_captureThread->SetNotAlive();
if (_captureThread->Stop()) {
delete _captureThread;
_captureThread = NULL;

View File

@ -178,7 +178,6 @@ int32_t VideoRenderAndroid::StopRender() {
_javaShutdownEvent.Wait(3000);
CriticalSectionScoped cs(&_critSect);
_javaRenderThread->SetNotAlive();
if (_javaRenderThread->Stop()) {
delete _javaRenderThread;
_javaRenderThread = NULL;

View File

@ -250,7 +250,6 @@ int32_t IncomingVideoStream::Stop() {
if (incoming_render_thread_) {
ThreadWrapper* thread = incoming_render_thread_;
incoming_render_thread_ = NULL;
thread->SetNotAlive();
#ifndef WIN32_
deliver_buffer_event_.StopTimer();
#endif

View File

@ -46,7 +46,6 @@ VideoRenderIosGles20::~VideoRenderIosGles20() {
screen_update_thread_ = NULL;
if (thread_wrapper) {
thread_wrapper->SetNotAlive();
screen_update_event_->Set();
screen_update_event_->StopTimer();

View File

@ -685,7 +685,6 @@ VideoRenderAGL::~VideoRenderAGL()
if (tmpPtr)
{
tmpPtr->SetNotAlive();
_screenUpdateEvent->Set();
_screenUpdateEvent->StopTimer();
@ -868,7 +867,6 @@ int VideoRenderAGL::StopThread()
if (tmpPtr)
{
tmpPtr->SetNotAlive();
_screenUpdateEvent->Set();
if (tmpPtr->Stop())
{

View File

@ -664,7 +664,6 @@ VideoRenderNSOpenGL::~VideoRenderNSOpenGL()
if (tmpPtr)
{
tmpPtr->SetNotAlive();
_screenUpdateEvent->Set();
_screenUpdateEvent->StopTimer();
@ -873,7 +872,6 @@ int VideoRenderNSOpenGL::StopThread()
if (tmpPtr)
{
tmpPtr->SetNotAlive();
_screenUpdateEvent->Set();
if (tmpPtr->Stop())
{

View File

@ -312,7 +312,6 @@ VideoRenderDirect3D9::~VideoRenderDirect3D9()
_screenUpdateThread = NULL;
if (tmpPtr)
{
tmpPtr->SetNotAlive();
_screenUpdateEvent->Set();
_screenUpdateEvent->StopTimer();
@ -515,7 +514,7 @@ int VideoRenderDirect3D9::InitDevice()
{ 1.0f, -1.0f, 0.0f, 0xffffffff, 1, 1 }, { 1.0f, 1.0f, 0.0f,
0xffffffff, 1, 0 } };
// Create the vertex buffer.
// Create the vertex buffer.
if (FAILED(_pd3dDevice->CreateVertexBuffer(sizeof(Vertices), 0,
D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &_pVB, NULL )))
@ -837,7 +836,7 @@ int32_t VideoRenderDirect3D9::DeleteChannel(const uint32_t streamId)
if (ddIt != _d3dChannels.end())
{
delete ddIt->second;
_d3dChannels.erase(ddIt);
_d3dChannels.erase(ddIt);
return 0;
}
return -1;
@ -853,7 +852,7 @@ VideoRenderCallback* VideoRenderDirect3D9::CreateChannel(const uint32_t channel,
CriticalSectionScoped cs(&_refD3DCritsect);
//FIXME this should be done in VideoAPIWindows? stop the frame deliver first
//remove the old channel
//remove the old channel
DeleteChannel(channel);
D3D9Channel* d3dChannel = new D3D9Channel(_pd3dDevice,
@ -890,9 +889,8 @@ int32_t VideoRenderDirect3D9::GetStreamSettings(const uint32_t channel,
"Direct3D render failed to find channel");
return -1;
}
// Only allow one stream per channel, demuxing is
// Only allow one stream per channel, demuxing is
return ddobj->GetStreamSettings(0, zOrder, left, top, right, bottom);
//return ddobj->GetStreamSettings(streamId, zOrder, left, top, right, bottom);
}
int VideoRenderDirect3D9::UpdateVerticeBuffer(LPDIRECT3DVERTEXBUFFER9 pVB,
@ -1092,7 +1090,7 @@ int32_t VideoRenderDirect3D9::SetBitmap(const void* bitMap,
int pitch = bmap.bmWidth * 4;
if (pbi.bmiHeader.biBitCount == 24)
{
{
ConvertRGB24ToARGB(srcPtr, dstPtr, bmap.bmWidth, bmap.bmHeight, 0);
}
else
@ -1168,7 +1166,7 @@ int32_t VideoRenderDirect3D9::ConfigureRenderer(const uint32_t channel,
"Direct3D render failed to find channel");
return -1;
}
// Only allow one stream per channel, demuxing is
// Only allow one stream per channel, demuxing is
ddobj->SetStreamSettings(0, zOrder, left, top, right, bottom);
return 0;

View File

@ -69,11 +69,6 @@ class ThreadWrapper {
// TODO(tommi): Move outside of the ThreadWrapper class to avoid confusion.
static uint32_t GetThreadId();
// Non blocking termination of the spawned thread. Note that it is not safe
// to delete this class until the spawned thread has been reclaimed.
// TODO(tommi): Remove this method.
virtual void SetNotAlive() = 0;
// Tries to spawns a thread and returns true if that was successful.
// Additionally, it tries to set thread priority according to the priority
// from when CreateThread was called. However, failure to set priority will

View File

@ -157,7 +157,6 @@ class CondVarTest : public ::testing::Test {
// Thus, we need to pin it down inside its Run function (between Grab
// and Pass).
ASSERT_TRUE(baton_.Pass(kShortWaitMs));
thread_->SetNotAlive();
ASSERT_TRUE(baton_.Grab(kShortWaitMs));
ASSERT_TRUE(thread_->Stop());
delete thread_;

View File

@ -129,7 +129,6 @@ TEST_F(CritSectTest, ThreadWakesTwice) NO_THREAD_SAFETY_ANALYSIS {
EXPECT_EQ(count_before, count.Count());
crit_sect->Leave();
thread->SetNotAlive(); // Tell thread to exit once run function finishes.
SwitchProcess();
EXPECT_TRUE(WaitForCount(count_before + 1, &count));
EXPECT_TRUE(thread->Stop());

View File

@ -444,7 +444,6 @@ void DataLogImpl::Process() {
void DataLogImpl::StopThread() {
if (file_writer_thread_ != NULL) {
file_writer_thread_->SetNotAlive();
flush_event_->Set();
// Call Stop() repeatedly, waiting for the Flush() call in Process() to
// finish.

View File

@ -266,9 +266,6 @@ bool EventPosix::Process() {
}
bool EventPosix::StopTimer() {
if (timer_thread_) {
timer_thread_->SetNotAlive();
}
if (timer_event_) {
timer_event_->Set();
}

View File

@ -118,10 +118,6 @@ bool ThreadPosix::Start(unsigned int& thread_id) {
return true;
}
void ThreadPosix::SetNotAlive() {
DCHECK(thread_checker_.CalledOnValidThread());
}
bool ThreadPosix::Stop() {
DCHECK(thread_checker_.CalledOnValidThread());
if (!thread_id_)

View File

@ -32,7 +32,6 @@ class ThreadPosix : public ThreadWrapper {
~ThreadPosix() override;
// From ThreadWrapper.
void SetNotAlive() override;
bool Start(unsigned int& id) override;
bool Stop() override;

View File

@ -89,10 +89,6 @@ bool ThreadWindows::Start(unsigned int& id) {
return true;
}
void ThreadWindows::SetNotAlive() {
DCHECK(main_thread_.CalledOnValidThread());
}
bool ThreadWindows::Stop() {
DCHECK(main_thread_.CalledOnValidThread());
if (thread_) {

View File

@ -27,7 +27,6 @@ class ThreadWindows : public ThreadWrapper {
bool Start(unsigned int& id) override;
bool Stop() override;
void SetNotAlive() override;
protected:
void Run();

View File

@ -103,7 +103,6 @@ bool TraceImpl::StopThread() {
// messages?
SleepMs(10);
thread_.SetNotAlive();
// Make sure the thread finishes as quickly as possible (instead of having
// to wait for the timeout).
event_.Set();

View File

@ -268,12 +268,6 @@ bool UdpSocket2ManagerWindows::StopWorkerThreads()
_managerNumber,
_numActiveSockets);
// Set worker threads to not alive so that they will stop calling
// UdpSocket2WorkerWindows::Run().
for (WorkerList::iterator iter = _workerThreadsList.begin();
iter != _workerThreadsList.end(); ++iter) {
(*iter)->SetNotAlive();
}
// Release all threads waiting for GetQueuedCompletionStatus(..).
if(_ioCompletionHandle)
{
@ -559,13 +553,6 @@ bool UdpSocket2WorkerWindows::Stop()
return _pThread->Stop();
}
void UdpSocket2WorkerWindows::SetNotAlive()
{
WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, -1,
"SetNotAlive UdpSocket2WorkerWindows");
_pThread->SetNotAlive();
}
int32_t UdpSocket2WorkerWindows::Init()
{
if(!_init)

View File

@ -100,7 +100,6 @@ public:
virtual bool Start();
virtual bool Stop();
virtual int32_t Init();
virtual void SetNotAlive();
protected:
static bool Run(ThreadObj obj);
bool Process();

View File

@ -102,8 +102,6 @@ int ViEAutoTestWindowManager::CreateWindows(AutoTestRect window1Size,
}
int ViEAutoTestWindowManager::TerminateWindows() {
_eventThread.SetNotAlive();
_terminate = true;
if (_eventThread.Stop()) {
_crit.Enter();

View File

@ -72,7 +72,6 @@ bool ViEToFileRenderer::PrepareForRendering(
void ViEToFileRenderer::StopRendering() {
assert(output_file_ != NULL);
if (thread_.get() != NULL) {
thread_->SetNotAlive();
// Signal that a frame is ready to be written to file.
frame_render_event_->Set();
// Call Stop() repeatedly, waiting for ProcessRenderQueue() to finish.

View File

@ -86,7 +86,6 @@ TbExternalTransport::TbExternalTransport(
TbExternalTransport::~TbExternalTransport()
{
_thread.SetNotAlive();
_event.Set();
if (_thread.Stop())
{

View File

@ -49,6 +49,7 @@ ViECapturer::ViECapturer(int capture_id,
"ViECaptureThread")),
capture_event_(*EventWrapper::Create()),
deliver_event_(*EventWrapper::Create()),
stop_(false),
effect_filter_(NULL),
image_proc_module_(NULL),
image_proc_module_ref_counter_(0),
@ -70,12 +71,8 @@ ViECapturer::~ViECapturer() {
module_process_thread_.DeRegisterModule(overuse_detector_.get());
// Stop the thread.
deliver_cs_->Enter();
capture_cs_->Enter();
capture_thread_.SetNotAlive();
stop_ = true;
capture_event_.Set();
capture_cs_->Leave();
deliver_cs_->Leave();
// Stop the camera input.
if (capture_module_) {
@ -454,6 +451,9 @@ bool ViECapturer::ViECaptureThreadFunction(void* obj) {
bool ViECapturer::ViECaptureProcess() {
int64_t capture_time = -1;
if (capture_event_.Wait(kThreadWaitTimeMs) == kEventSignaled) {
if (stop_)
return false;
overuse_detector_->FrameProcessingStarted();
int64_t encode_start_time = -1;
deliver_cs_->Enter();

View File

@ -168,6 +168,8 @@ class ViECapturer
EventWrapper& capture_event_;
EventWrapper& deliver_event_;
bool stop_;
scoped_ptr<I420VideoFrame> captured_frame_;
scoped_ptr<I420VideoFrame> deliver_frame_;

View File

@ -1703,7 +1703,6 @@ int32_t ViEChannel::StopDecodeThread() {
return 0;
}
decode_thread_->SetNotAlive();
if (decode_thread_->Stop()) {
delete decode_thread_;
} else {

View File

@ -185,7 +185,6 @@ ThreadTest::~ThreadTest()
{
if (_thread)
{
_thread->SetNotAlive();
if (_thread->Stop())
{
delete _thread;
@ -272,7 +271,6 @@ bool ThreadTest::Process()
"sending instance started from thread");
#endif
_thread->SetNotAlive();
_thread->Stop();
//res = veData1.jvm->DetachCurrentThread();

View File

@ -38,7 +38,6 @@ FakeExternalTransport::FakeExternalTransport(webrtc::VoENetwork* ptr)
FakeExternalTransport::~FakeExternalTransport() {
if (thread_) {
thread_->SetNotAlive();
event_->Set();
if (thread_->Stop()) {
delete thread_;