示例#1
0
	void ThreadPool::Start(uint16 WorkerThreads)
	{
		if(IsStarted)
		{
			printf(TM_TEXT"ERROR - ThreadPool is already started!\n");
			return;
		}

		if(WorkerThreads)
		{
			for (uint16 i = 0; i < WorkerThreads; ++i)
			{
				if(TaskLine->GetSize() == 0)
				{
					if(!MakeThread(new Thread(this)))
					{
						printf(TM_TEXT"ERROR - creating suspended thread!\n");
					}
				}
				else
				{
					if(!MakeThread(new Thread(this, TaskLine->PopFront())))
					{
						printf(TM_TEXT"ERROR - creating thread with target!\n");
					}
				}
			}
		}
		else
		{
			printf(TM_TEXT"ERROR - Cannot start 0 threads!?\n");
		}

		IsStarted = true;
	}
示例#2
0
	void ThreadPool::Start()
	{
		if(IsStarted)
		{
			printf(TM_TEXT"ERROR - ThreadPool is already started!\n");
			return;
		}

		for(uint16 i = 0; i < DEFAULT_THREADS; ++i)
		{
			if(TaskLine->GetSize() == 0)
			{
				if(!MakeThread(new Thread(this)))
				{
					printf(TM_TEXT"ERROR - Creating suspended thread!\n");
				}
			}
			else
			{
				if(!MakeThread(new Thread(this, TaskLine->PopFront())))
				{
					printf(TM_TEXT"ERROR - creating thread with target!\n");
				}
			}
		}

		IsStarted = true;
	}
示例#3
0
void RageThread::Create( int (*fn)(void *), void *data )
{
	/* Don't create a thread that's already running: */
	ASSERT( m_pSlot == NULL );

	InitThreads();

	/* Lock unused slots, so nothing else uses our slot before we mark it used. */
	LockMut(g_ThreadSlotsLock);

	int slotno = FindEmptyThreadSlot();
	m_pSlot = &g_ThreadSlots[slotno];
	
	if( name == "" )
	{
		if( LOG )
			LOG->Warn("Created a thread without naming it first.");

		/* If you don't name it, I will: */
		strcpy( m_pSlot->name, "Joe" );
	} else {
		strcpy( m_pSlot->name, name.c_str() );
	}

	if( LOG )
		LOG->Trace( "Starting thread: %s", name.c_str() );
	sprintf( m_pSlot->ThreadFormattedOutput, "Thread: %s", name.c_str() );

	/* Start a thread using our own startup function.  We pass the id to fill in,
	 * to make sure it's set before the thread actually starts.  (Otherwise, early
	 * checkpoints might not have a completely set-up thread slot.) */
	m_pSlot->pImpl = MakeThread( fn, data, &m_pSlot->id );
}
示例#4
0
void TaskQueue::TaskThreadPool::AddQueueTask(TaskQueue *queue, Task &&task) {
	QMutexLocker lock(&queues_mutex_);

	queue->tasks_.push_back(new Task(std_::move(task)));
	auto list_was_empty = queue_list_.Empty(kAllQueuesList);
	auto threads_count = threads_.size();
	auto all_threads_processing = (threads_count == tasks_in_process_);
	auto some_threads_are_vacant = !all_threads_processing && list_was_empty;
	auto will_create_thread = !some_threads_are_vacant && (threads_count < MaxThreadsCount);

	if (!queue->SerialTaskInProcess()) {
		if (!queue_list_.IsInList(queue)) {
			queue_list_.Register(queue);
		}
	}
	if (will_create_thread) {
		threads_.push_back(MakeThread([this]() {
			ThreadFunction();
		}));
		threads_.back()->start();
	} else if (some_threads_are_vacant) {
		t_assert(threads_count > tasks_in_process_);
		thread_condition_.wakeOne();
	}
}
示例#5
0
IThreadHandle *PosixThreader::MakeThread(IThread *pThread, ThreadFlags flags)
{
	ThreadParams defparams;

	defparams.flags = flags;
	defparams.prio = ThreadPrio_Normal;

	return MakeThread(pThread, &defparams);
}
示例#6
0
void PosixThreader::MakeThread(IThread *pThread)
{
	ThreadParams defparams;

	defparams.flags = Thread_AutoRelease;
	defparams.prio = ThreadPrio_Normal;

	MakeThread(pThread, &defparams);
}
示例#7
0
IThreadHandle *BaseWorker::MakeThread(IThread *pThread, ThreadFlags flags)
{
	ThreadParams pt;

	pt.flags = flags;
	pt.prio = ThreadPrio_Normal;

	return MakeThread(pThread, &pt);
}
示例#8
0
void BaseWorker::MakeThread(IThread *pThread)
{
	ThreadParams pt;

	pt.flags = Thread_AutoRelease;
	pt.prio = ThreadPrio_Normal;

	MakeThread(pThread, &pt);
}
示例#9
0
static void CPROC OkayChoiceClicked( uintptr_t psv, PCONTROL pc )
{
	PBANNER banner = (PBANNER)psv;
#ifdef DEBUG_BANNER_DRAW_UPDATE
	lprintf( WIDE( "OKAY!" ) );
#endif
	banner->flags |= (BANNER_CLOSED|BANNER_OKAY);
	{
		PTHREAD thread = (banner)->pWaitThread;
		if( thread && ( thread != MakeThread() ) )
		{
			WakeThread( thread );
		}
	}
}
示例#10
0
int GetCh( void )
{
	int ch;
	//if( g.pCurrentPlayer && g.pCurrentPlayer->flags.bRemote )
	//   return 0;
	if( !pThreadInput )
		pThreadInput = MakeThread();
	if( !inputpipe )
	{
		inputpipe = open( WIDE("stockmarket.pipe"), O_RDWR|O_CREAT|O_TRUNC, 0600 );
		ThreadTo( InputThread, 0 );
	}
	if( !save )
		save = sack_fopen( 0, WIDE("stockmarket.save"), WIDE("wt") );
	if( script )
	{
		ch = fgetc( script );
		if( ch == -1 )
		{
			fclose( script );
			script = NULL;
		}
	}
	if( !script )
	{
		ch = 0; // clear upper bits.
		lprintf( WIDE("will read 1 TEXTCHAR") );
		while( bEnque || ( read( inputpipe, &ch, 1 ) < 1 ) )
		{
			lprintf( WIDE("Waiting for input event.") );
			WakeableSleep( SLEEP_FOREVER );
			lprintf( WIDE("Input event received.") );
		}
		lprintf( WIDE("Read input.") );
	}
	if( ch == '\r' )
		fputc( '\n', save );
	else
		fputc( ch, save );
	fflush( save );
	return ch;
}
  KinectInterfacePrimesense::KinectInterfacePrimesense(const char* device_uri) {
    device_initialized_ = false;
    device_ = NULL;
    pts_world_ = NULL;
    pts_uvd_ = NULL;
    labels_ = NULL;
    depth_1mm_ = NULL;
    registered_rgb_ = NULL;
    openni_funcs_ = NULL;
    depth_dim_.zeros();
    rgb_dim_.zeros();
    ir_dim_.zeros();
    for (uint32_t i = 0; i < NUM_STREAMS; i++) {
      streams_[i] = NULL;
      frames_[i] = NULL;
    }

    depth_frame_number_ = 0;
    rgb_frame_number_ = 0;
    ir_frame_number_ = 0;
    tp_ = NULL;

    init(device_uri);

    //  Now spawn the Kinect Update Thread
    kinect_running_ = true;
    Callback<void>* threadBody = MakeCallableOnce(
      &KinectInterfacePrimesense::kinectUpdateThread, this);
    kinect_thread_ = MakeThread(threadBody);

    device_initialized_ = true;
    // Increment the devices counter
    openni_static_lock_.lock();
    openni_devices_open_++;
    open_kinects_.pushBack(this);
    openni_static_lock_.unlock();
  }
示例#12
0
DWORD CClient::StartClient()
{
    DWORD dwRet;
    DWORD dwCount = 0;

    while (1)
    {
        dwRet = ConnectServer();
        if (dwRet != E_RET_SUCCESS) {
            WriteLog(E_LOG_LEVEL_ERROR, "Fail to connect to Server");
        }

        dwRet = MakeThread();
        if (dwRet != E_RET_SUCCESS) {
            WriteLog(E_LOG_LEVEL_ERROR, "Fail to make thread");
        }

        WaitForMultipleObjects(MAX_THREAD, m_hArray, TRUE, INFINITE);

        /*
        	normally, code have to be not executed
        	if it was done, first or second thread is exited
        */
        g_bThreadExit = FALSE;

        /*
        	Wait for 1 second to exit all thread ordinarily
        */
        ::Sleep(1000);
        int i;
        for (i = 0; i < MAX_THREAD; i++)
            m_hArray[i] = NULL;

        g_bThreadExit = TRUE;
    }
}
示例#13
0
SaneWinMain( argc, argv )
{
   int nowait = 0;
	int task_monitor = 0;
	int noinput = 0;
	if( argc < 2 )
	{
#ifdef WIN32
		const TEXTCHAR * const args[] ={ WIDE("cmd.exe"), NULL };
#else
		const TEXTCHAR * const args[] ={ WIDE("/bin/sh"), NULL };
#endif

		if( !( task = LaunchPeerProgram( args[0], NULL, args, output, ended, 0 ) ) )
         done = 1;
	}
	else
	{
      int delay = 0;
		int offset = 1;
		while( argv[offset] && argv[offset][0] == '-' )
		{
			if( StrCaseCmp( argv[offset]+1, WIDE("nowait") ) == 0 )
            nowait = 1;
			if( StrCaseCmp( argv[offset]+1, WIDE("taskmon") ) == 0 )
            task_monitor = 1;
			if( StrCaseCmp( argv[offset]+1, WIDE("noin") ) == 0 )
            noinput = 1;
			if( StrCaseCmp( argv[offset]+1, WIDE("local") ) == 0 )
			{
            SetCurrentPath( OSALOT_GetEnvironmentVariable( WIDE("MY_LOAD_PATH") ) );
			}
			if( StrCaseCmp( argv[offset]+1, WIDE("delay") ) == 0 )
			{
				delay = atoi( argv[offset+1] );
            offset++; // used an extra parameter
			}
			offset++;
		}
		if( delay )
			WakeableSleep( delay );
		if( offset < argc )
		{
			if( !( task = LaunchPeerProgram( argv[offset], NULL, argv + offset, noinput?NULL:output, ended, 0 ) ) )
				done = 1;
		}
		else
		{
#ifdef WIN32
			const TEXTCHAR * const args[] ={ WIDE("cmd.exe"), NULL };
#else
			const TEXTCHAR * const args[] ={ WIDE("/bin/sh"), NULL };
#endif
			if( !( task = LaunchPeerProgram( args[0], NULL, args, noinput?NULL:output, ended, 0 ) ) )
				done = 1;
		}
	}
	main_thread = MakeThread();
	while( !done )
	{
		TEXTCHAR buf[256];
		if( nowait )
			WakeableSleep( 1000 );
		else
		{
			if( !noinput )
			{
				if( fgets( buf, 256, stdin ) )
				{
					pprintf( task, WIDE("%s"), buf );
				}
			}
			else
            nowait = 1;
		}
	}
   if( task_monitor )
		SendMessage( FindWindow( WIDE("TaskMonClass"), WIDE("Task Completion Monitor") ), WM_USER+500, 0, 0 );
   fprintf( stdout, WIDE("Shell Completed.") );
   return 0;
}