コード例 #1
0
ファイル: ofThread.cpp プロジェクト: CaterTsai/openFrameworks
//-------------------------------------------------
void ofThread::run(){
#ifdef TARGET_ANDROID
	JNIEnv * env;
	jint attachResult = ofGetJavaVMPtr()->AttachCurrentThread(&env,NULL);
	if(attachResult!=0){
		ofLogWarning() << "couldn't attach new thread to java vm";
	}
#endif
	// user function
    // should loop endlessly.
	try{
		threadedFunction();
	}catch(const Poco::Exception& exc){
		ofLogFatalError("ofThreadErrorLogger::exception") << exc.displayText();
	}catch(const std::exception& exc){
		ofLogFatalError("ofThreadErrorLogger::exception") << exc.what();
	}catch(...){
		ofLogFatalError("ofThreadErrorLogger::exception") << "Unknown exception.";
	}

    _threadRunning = false;

#if !defined(TARGET_WIN32)
	// FIXME: this won't be needed once we update POCO https://github.com/pocoproject/poco/issues/79
	if(!threadBeingWaitedFor){ //if threadedFunction() ended and the thread is not being waited for, detach it before exiting.
		pthread_detach(pthread_self());
	}
#endif
#ifdef TARGET_ANDROID
	attachResult = ofGetJavaVMPtr()->DetachCurrentThread();
#endif
}
コード例 #2
0
ファイル: ofThread.cpp プロジェクト: 4ker/openFrameworks
//-------------------------------------------------
void ofThread::run(){
#ifdef TARGET_ANDROID
	JNIEnv * env;
	jint attachResult = ofGetJavaVMPtr()->AttachCurrentThread(&env,nullptr);
	if(attachResult!=0){
		ofLogWarning() << "couldn't attach new thread to java vm";
	}
#endif

	// user function
    // should loop endlessly.
	try{
		threadedFunction();
	}catch(const std::exception& exc){
		ofLogFatalError("ofThreadErrorLogger::exception") << exc.what();
	}catch(...){
		ofLogFatalError("ofThreadErrorLogger::exception") << "Unknown exception.";
	}
	thread.detach();
#ifdef TARGET_ANDROID
	attachResult = ofGetJavaVMPtr()->DetachCurrentThread();
#endif

    std::unique_lock<std::mutex> lck(mutex);
	threadRunning = false;
	threadDone = true;
    condition.notify_all();
}
コード例 #3
0
//---------------------------------------------------------------
bool CloudsRGBDVideoPlayer::setup(string videoPath, string calibrationXMLPath, string subtitlesPath, float offsetTime,float clipVolume){

	cout << "*** SETTING UP CLIP " << calibrationXMLPath << endl;
    if (!ofFile::doesFileExist(videoPath)){
    	ofLogError("CloudsRGBDVideoPlayer::setup") << "Movie path " << videoPath << " failed to load";
        return false;
    }

	if(!ofFile::doesFileExist(calibrationXMLPath)){
    	ofLogError("CloudsRGBDVideoPlayer::setup") << "XML path " << calibrationXMLPath << " failed to load";
		return false;
	}

	cout << "*** SETTING UP CLIP FILES ARE PRESENT " << endl;

    if(!bEventRegistered){
		ofAddListener(ofEvents().update, this, &CloudsRGBDVideoPlayer::update);
		bEventRegistered = true;
	}
    
    nextVideoPath = videoPath;
    nextCalibrationXML = calibrationXMLPath;
    nextSubtitlesPath = subtitlesPath;
    nextOffsetTime = offsetTime;
    nextClipVolume = clipVolume;

	clipPrerolled = true;

#ifdef TARGET_WIN32
    nextPlayer->setUseTexture(false);
	bLoadResult = false;

	cout << "*** SETTING UP CLIP STARTING THREAD" << endl;
    startThread(true);

    return true;
#else
    // No need to use a thread, just call this function directly.
    threadedFunction();

    return bLoadResult;
#endif
}
コード例 #4
0
//-------------------------------------------------
void ofThread::run() {
#ifdef TARGET_ANDROID
    JNIEnv * env;
    jint attachResult = ofGetJavaVMPtr()->AttachCurrentThread(&env,NULL);
    if(attachResult!=0) {
        ofLogWarning() << "couldn't attach new thread to java vm";
    }
#endif
    // user function
    // should loop endlessly.
    threadedFunction();

    _threadRunning = false;

#if !defined(TARGET_WIN32) && !defined(TARGET_ANDROID)
    // FIXME: this won't be needed once we update POCO https://github.com/pocoproject/poco/issues/79
    if(!threadBeingWaitedFor) { //if threadedFunction() ended and the thread is not being waited for, detach it before exiting.
        pthread_detach(pthread_self());
    }
#endif
#ifdef TARGET_ANDROID
    attachResult = ofGetJavaVMPtr()->DetachCurrentThread();
#endif
}