コード例 #1
0
ファイル: base_thread.cpp プロジェクト: iamyuiwong/thread
void * BaseThread::entryPoint(void * self)
{
	BaseThread * th = reinterpret_cast<BaseThread *>(self);
	if (NULL == self) {
		return (void *)-1;
	} else {
#		if defined(WIN32)
		th->id = thread::CurrentThreadId();
#		endif /* defined(WIN32) */
		th->_exitCode = th->run(th->arg());
		th->setRunning(false);
		return th->_exitCode;
	}
}
コード例 #2
0
bool BaseThread::shutdownAndWait() {
	bool ret = true;
	BaseThread *pThread = this;
	string uniqueID = (pThread != NULL ? pThread->getUniqueID() : "?");
	if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());

	if(pThread != NULL) {
		if(pThread->getRunningStatus() == true) {
			if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());

			pThread->signalQuit();
			sleep(0);
			ret = false;

			int maxWaitSeconds = 5;
			if(pThread->canShutdown() == false) {
				maxWaitSeconds = 2;
			}

			for( time_t elapsed = time(NULL); difftime(time(NULL),elapsed) <= maxWaitSeconds; ) {
				if(pThread->getRunningStatus() == false) {
					ret = true;
					break;
				}

				sleep(0);
			}
			if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str());
			sleep(0);
		}
	}
	if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] uniqueID [%s] ret [%d] END\n",__FILE__,__FUNCTION__,__LINE__,uniqueID.c_str(),ret);
	return ret;
}
コード例 #3
0
ファイル: testTh.cpp プロジェクト: twManu/libmanu
int main(int argc, char *argv[])
{
	FileStream *streamV, *streamA;
	RateCtrl *rcVideo, *rcAudio;
	rtpStreamTask *rtpTaskV, *rtpTaskA;
	BaseThread *baseTask;
	int ret = -1;
	//video
	streamV = new FileStream("../3gpp/stream2.dump", FileStream::BM_RDONLY);
	if( !streamV ) {
		ERROR("Fail to create stream\n");
		goto err;
	}
	if( !streamV->open() ) {
		ERROR("fail to open stream\n");
		goto delVStream;
	}
	rcVideo = new RateCtrl();
	if( !rcVideo ) {
		ERROR("Fail to create rateCtrl\n");
		goto delVStream;
	}
	rtpTaskV = new rtpStreamTask(streamV, rcVideo, 15*1000); //15ms sleep
	if( !rtpTaskV ) {
		ERROR("Fail to create task\n");
		goto delVrc;
	}
	if( !rtpTaskV->Init("127.0.0.1", 5568, "video", 90000) ) {
		ERROR("Fail to create task\n");
		goto delVTask;
	}
	//audio
	streamA = new FileStream("../3gpp/stream1.dump", FileStream::BM_RDONLY);
	if( !streamA ) {
		ERROR("Fail to create streamA\n");
		goto delVTask;
	}
	if( !streamA->open() ) {
		ERROR("fail to open streamA\n");
		goto delAStream;
	}
	rcAudio = new RateCtrl();
	if( !rcAudio ) {
		ERROR("Fail to create rateCtrl\n");
		goto delAStream;
	}
	rtpTaskA = new rtpStreamTask(streamA, rcAudio, 15*1000); //15ms sleep
	if( !rtpTaskA ) {
		ERROR("Fail to create taskA\n");
		goto delArc;
	}
	if( !rtpTaskA->Init("127.0.0.1", 5566, "audio", 44100) ) {
		ERROR("Fail to create task\n");
		goto delATask;
	}	
	rcVideo->timeReset();
	*rcAudio = *rcVideo;
	baseTask = rtpTaskV;
	//if( !rtpTaskA->Start() ) goto delVTask;
	baseTask=rtpTaskA;
	if( baseTask->Start() ) {
		while( baseTask->isRunning() ) sleep(5);	//till terminate
		ret = 0;
	}


delATask:
	delete rtpTaskA;
delArc:
	delete rcAudio;
delAStream:
	delete streamA;
delVTask:
	delete rtpTaskV;
delVrc:
	delete rcVideo;
delVStream:
	delete streamV;
err:
	return ret;
}
コード例 #4
0
void* thread_start_callback(void* _t_ptr)
{
	BaseThread* t = (BaseThread*)_t_ptr;
	return t->run();

}