Esempio n. 1
0
void
ArbitMgr::threadMain()
{
    ArbitSignal aSignal;
    aSignal = theInputBuffer;
    threadStart(aSignal);
    bool stop = false;
    while (! stop) {
        NdbMutex_Lock(theInputMutex);
        while (! theInputFull) {
            NdbCondition_WaitTimeout(theInputCond, theInputMutex, theInputTimeout);
            threadTimeout();
        }
        aSignal = theInputBuffer;
        theInputFull = false;
        NdbCondition_Signal(theInputCond);
        NdbMutex_Unlock(theInputMutex);
        switch (aSignal.gsn) {
        case GSN_ARBIT_CHOOSEREQ:
            threadChoose(aSignal);
            break;
        case GSN_ARBIT_STOPORD:
            stop = true;
            break;
        }
    }
    threadStop(aSignal);
}
Esempio n. 2
0
void KNMusicStandardBackend::previewStop()
{
    //Stop the smart volume.
    smartVolumeOff();
    //Stop the preview thread.
    threadStop(m_preview);
}
Esempio n. 3
0
t_ilm_bool SystemdHealthMonitor::stop()
{
    LOG_INFO("SystemdHealthMonitor", "stopping");
    t_ilm_bool result = ILM_TRUE;
    if (watchdogEnabled())
    {
        result = threadStop();
    }
    return result;
}
Esempio n. 4
0
	void threadStart(T t) {
		if (!prepareEvent) prepareEvent = createEvent();
		if (!stopEvent)    stopEvent    = createEvent(true);

		threadStop(threadTimeout);
		::ResetEvent(stopEvent);

		ThreadStartParam param = { this, prepareEvent, stopEvent, t };
		threadHandle = (HANDLE)_beginthreadex(NULL, 0, &threadFunc, &param, 0, NULL);
		if (threadHandle) {
			HANDLE handles[] = { prepareEvent, threadHandle };
			::WaitForMultipleObjects(2, handles, FALSE, INFINITE);
			if (::WaitForSingleObject(threadHandle, 0) == WAIT_OBJECT_0) {
				::CloseHandle(threadHandle);
				threadHandle = 0;
			}
		}
	}
Esempio n. 5
0
void Thread::stop(bool force)
{
	// Changed by Tim. p3.3.17

	if (thread == 0)
		return;
	//if (force && thread > 0) {
	if (force)
	{
		pthread_cancel(thread);
		threadStop();
	}
	_running = false;
	if (thread)
	{
		if (pthread_join(thread, 0))
		{
			// perror("Failed to join sequencer thread");
		}
	}
}
Esempio n. 6
0
void KNMusicStandardBackend::stop()
{
    threadStop(m_main);
}
Esempio n. 7
0
	virtual ~SimpleThreadBase() {
		threadStop(threadTimeout);
		closeAllEvent();
	}
Esempio n. 8
0
void Thread::loop()
{
	// Changed by Tim. p3.3.17

	if (!debugMode)
	{
		if (mlockall(MCL_CURRENT | MCL_FUTURE))
			perror("WARNING: Cannot lock memory:");
	}

	/*
		  pthread_attr_t* attributes = 0;
		  attributes = (pthread_attr_t*) malloc(sizeof(pthread_attr_t));
		  pthread_attr_init(attributes);

		  if (realTimeScheduling && realTimePriority > 0) {

				doSetuid();
	//             if (pthread_attr_setschedpolicy(attributes, SCHED_FIFO)) {
	//                   printf("cannot set FIFO scheduling class for RT thread\n");
	//                   }
	//             if (pthread_attr_setscope (attributes, PTHREAD_SCOPE_SYSTEM)) {
	//                   printf("Cannot set scheduling scope for RT thread\n");
	//                   }
	//             struct sched_param rt_param;
	//             memset(&rt_param, 0, sizeof(rt_param));
	//             rt_param.sched_priority = realTimePriority;
	//             if (pthread_attr_setschedparam (attributes, &rt_param)) {
	//                   printf("Cannot set scheduling priority %d for RT thread (%s)\n",
	//                      realTimePriority, strerror(errno));
	//                   }

			   // do the SCHED_FIFO stuff _after_ thread creation:
			   struct sched_param *param = new struct sched_param;
			   param->sched_priority = realTimePriority;
			   int error = pthread_setschedparam(pthread_self(), SCHED_FIFO, param);
				if (error != 0)
				  perror( "error set_schedparam 2:");

	//          if (!debugMode) {
	//                if (mlockall(MCL_CURRENT|MCL_FUTURE))
	//                      perror("WARNING: Cannot lock memory:");
	//                }

				undoSetuid();
				}

	 */


	/*
	#define BIG_ENOUGH_STACK (1024*1024*1)
		  char buf[BIG_ENOUGH_STACK];
		  for (int i = 0; i < BIG_ENOUGH_STACK; i++)
				buf[i] = i;
	#undef BIG_ENOUGH_STACK
	 */

#ifdef __APPLE__
#define BIG_ENOUGH_STACK (1024*256*1)
#else
#define BIG_ENOUGH_STACK (1024*1024*1)
#endif
	char buf[BIG_ENOUGH_STACK];
	for (int i = 0; i < BIG_ENOUGH_STACK; i++)
		buf[i] = i;
#undef BIG_ENOUGH_STACK

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);

	int policy = 0;
	if ((policy = sched_getscheduler(0)) < 0)
	{
		printf("Thread: Cannot get current client scheduler: %s\n", strerror(errno));
	}

	/*
	if (debugMsg)
		  printf("Thread <%s> set to %s priority %d\n",
			 _name, policy == SCHED_FIFO ? "SCHED_FIFO" : "SCHED_OTHER",
			  realTimePriority);
	 */
	if (debugMsg)
		printf("Thread <%s, id %p> has %s priority %d\n",
			_name, (void *) pthread_self(), policy == SCHED_FIFO ? "SCHED_FIFO" : "SCHED_OTHER",
			_realTimePriority);


	//      pthread_mutex_lock(&lock);
	_running = true;
	//      pthread_cond_signal(&ready);
	//      pthread_mutex_unlock(&lock);

	threadStart(userPtr);

	while (_running)
	{
		if (debugMode) // DEBUG
			_pollWait = 10; // ms
		else
			_pollWait = -1;

		int n = poll(pfd, npfd, _pollWait);
		if (n < 0)
		{
			if (errno == EINTR)
				continue;
			fprintf(stderr, "poll failed: %s\n", strerror(errno));
			exit(-1);
		}
		if (n == 0)
		{ // timeout
			defaultTick();
			continue;
		}

		struct pollfd* p = &pfd[0];
		int i = 0;
		for (iPoll ip = plist.begin(); ip != plist.end(); ++ip, ++p, ++i)
		{
			if (ip->action & p->revents)
			{
				(ip->handler)(ip->param1, ip->param2);
				break;
			}
		}
	}
	threadStop();
}