Ejemplo n.º 1
0
void *simplethread_threadproc(t_simplethread *x) 
{
	// loop until told to stop
	while (1) {

		// test if we're being asked to die, and if so return before we do the work
		if (x->x_systhread_cancel) 
			break;

		systhread_mutex_lock(x->x_mutex);	
		x->x_foo++;																// fiddle with shared data
		systhread_mutex_unlock(x->x_mutex);
		
		qelem_set(x->x_qelem);													// notify main thread using qelem mechanism
		
		
		systhread_sleep(x->x_sleeptime);						// sleep a bit
	}
	
	x->x_systhread_cancel = false;							// reset cancel flag for next time, in case
																				// the thread is created again
	
	systhread_exit(0);															// this can return a value to systhread_join();
	return NULL;
}
Ejemplo n.º 2
0
void *jit_freenect_capture_threadproc()//t_jit_freenect_grab *x) 
{
 
#ifdef NESADEBUG
#warning if crash remove=NULL
#endif
	freenect_context *context = NULL;
	
	postNesa("Threadproc called");//TODO:r
	
	if(!f_ctx){
		postNesa("f_ctx is null, calling init_Freenect");//TODO:r
		if (freenect_init(&context, NULL) < 0) {
			error("freenect_init() failed");
			goto out;
		}
		freenect_set_log_level(context, JIT_FREENECT_LOG_LEVEL);
		postNesa("freenect_init ok,id");//TODO: remove
	}
	
	f_ctx = context;
	
	struct timeval timeout;
	timeout.tv_sec = 60;
	timeout.tv_usec = 0;
	
	// loop until told to stop
	while (1) {
		
		//postNesaFlood("threadid=%i",x->id);
		// test if we're being asked to die, and if so return before we do the work
		if (x_systhread_cancel)
		{
			postNesa("stopping thread");
			break;
		}
		// this thread is used only to process freenect events
		// no need to lock the mutex
		//systhread_mutex_lock(x->x_mutex);	

		//if(f_ctx->first){
			//if(freenect_process_events(f_ctx) < 0){
		
		//if(freenect_active)
		//{
		if(f_ctx->first)
		if(freenect_process_events_timeout(f_ctx, &timeout)<0)
			{
				error("Could not process events.");
				//if (x->x_systhread_cancel) 
				break;
			}
		//}
		//else {
		//	postNesa("freenect_active=false\n");
		//}


		//}
		//else {
		//	post("not first");//TODO:remove
		//}
		//x->x_foo++;																// fiddle with shared data
		
		
		//systhread_mutex_unlock(x->x_mutex);
		
		//qelem_set(x->x_qelem);													// notify main thread using qelem mechanism
		
		//usleep(2500);
		//systhread_sleep(x->x_sleeptime);						// sleep a bit
	}

out:
	postNesa("Threadproc exits");//TODO:r
	
	
	//postNesa("Threadproc calls grab_close ,id=%i\n",x->id);//TODO:r
	// TODO: add notification through dupmoutlet
	//jit_freenect_grab_close(x, NULL, 0, NULL);
	
	freenect_shutdown(f_ctx);
	f_ctx = NULL;
	
	
	//x->x_systhread_cancel = false;							// reset cancel flag for next time, in case
	// the thread is created again
	
	systhread_exit(0);															// this can return a value to systhread_join();
	return NULL;
}