Example #1
0
 virtual ~wxThreadInternal()
 {
     if ( m_notifyQueueId)
     {
         MPDeleteQueue( m_notifyQueueId );
         m_notifyQueueId = kInvalidID ;
     }
 }
Example #2
0
thread::~thread()
{
    if (m_joinable)
    {
#if defined(BOOST_HAS_WINTHREADS)
        int res = 0;
        res = CloseHandle(reinterpret_cast<HANDLE>(m_thread));
        assert(res);
#elif defined(BOOST_HAS_PTHREADS)
        pthread_detach(m_thread);
#elif defined(BOOST_HAS_MPTASKS)
        assert(m_pJoinQueueID != kInvalidID);
        OSStatus lStatus = MPDeleteQueue(m_pJoinQueueID);
        assert(lStatus == noErr);
#endif
    }
}
Example #3
0
void cFUThread::StopThread()
{
	assert(thread != cFUThread_INVALID);
	isSuspendedCS.Enter();
	terminate = true;
	bool _isSuspended = isSuspended;
	isSuspendedCS.Leave();
	if (_isSuspended)
		StartThread(); //The real function will not start because terminate = true;
#if defined(WIN32)
	WaitForSingleObject(thread, INFINITE);
	CloseHandle(thread); // delete the thread once it's finished
#elif defined (FP_APPLE)
	OSStatus status;
	//MPTerminateTask(thread, status);
	status = MPWaitOnQueue(queue, nullptr, nullptr, nullptr, kDurationForever);
	status = MPDeleteQueue(queue);
#elif defined(LINUX) || defined(IOS)|| defined(ANDROID)
	pthread_join(thread, nullptr);
#endif
	thread = cFUThread_INVALID;
}
Example #4
0
thread::thread(const function0<void>& threadfunc)
    : m_joinable(true)
{
    thread_param param(threadfunc);
#if defined(BOOST_HAS_WINTHREADS)
    m_thread = reinterpret_cast<void*>(_beginthreadex(0, 0, &thread_proxy,
                                           &param, 0, &m_id));
    if (!m_thread)
        throw thread_resource_error();
#elif defined(BOOST_HAS_PTHREADS)
    int res = 0;
    res = pthread_create(&m_thread, 0, &thread_proxy, &param);
    if (res != 0)
        throw thread_resource_error();
#elif defined(BOOST_HAS_MPTASKS)
    threads::mac::detail::thread_init();
    threads::mac::detail::create_singletons();
    OSStatus lStatus = noErr;

    m_pJoinQueueID = kInvalidID;
    m_pTaskID = kInvalidID;

    lStatus = MPCreateQueue(&m_pJoinQueueID);
    if (lStatus != noErr) throw thread_resource_error();

    lStatus = MPCreateTask(&thread_proxy, &param, 0UL, m_pJoinQueueID, NULL,
        NULL, 0UL, &m_pTaskID);
    if (lStatus != noErr)
    {
        lStatus = MPDeleteQueue(m_pJoinQueueID);
        assert(lStatus == noErr);
        throw thread_resource_error();
    }
#endif
    param.wait();
}
Example #5
0
static void SendFlowControlTest(void)
{
	OSStatus  err;
	OSStatus  junk;
	MPQueueID deathQueue;
	MPTaskID  rcvTask;
	MPTaskID  sndTask;

	gRcvStarted = false;
	gLookerEP = NULL;
	gQuitLooker = false;
	
	deathQueue = kInvalidID;
	err = MPCreateQueue(&deathQueue);
	if (err == noErr) {
		err = MPCreateTask(SFCRcv, NULL, 65536, deathQueue, (void *) 1, (void *) 666, kNilOptions, &rcvTask);
	}
	if (err == noErr) {
		MPLogPrintf("Waiting for receiver to start.\n");
		while ( ! gRcvStarted ) {
			printf(".");
			fflush(stdout);
		}
		MPLogPrintf("\n");
	}
	if (err == noErr) {
		err = MPCreateTask(SFCSnd, NULL, 65536, deathQueue, (void *) 2, (void *) 666, kNilOptions, &sndTask);
	}
	if (err == noErr) {
		err = MPCreateTask(SFCLooker, NULL, 65536, deathQueue, (void *) 3, (void *) 666, kNilOptions, &rcvTask);
	}
	if (err == noErr) {
		UInt32 terminatedTaskCount;
		UInt32 taskNumber;
		OSStatus taskStatus;
		UInt32 lastPrinted;
		
		lastPrinted = 0;
		terminatedTaskCount = 0;
		do {
			err = MPWaitOnQueue(deathQueue, (void **) &taskNumber, NULL, (void **) &taskStatus, kDurationImmediate);
			if (err == noErr) {
				MPLogPrintf("Task number %ld completed with status %ld.\n", taskNumber, taskStatus);
				terminatedTaskCount += 1;
			} else if (err == kMPTimeoutErr) {
				#if !TARGET_API_MAC_CARBON
					SystemTask();
				#endif
				if (TickCount() > (lastPrinted + 60)) {
					printf(".");
					fflush(stdout);
					lastPrinted = TickCount();
				}
				err = noErr;
			}
		} while ( (err == noErr) && (terminatedTaskCount < 3) );
	}
	
	// Clean up.
	
	if (deathQueue != kInvalidID) {
		junk = MPDeleteQueue(deathQueue);
		assert(junk == noErr);
	}

	printf("gLookCounter = %ld\n", gLookCounter);
	gLookCounter = 0;
	
	if (err == noErr) {
		printf("Success!\n");
	} else {
		printf("Failed with error %ld.\n", err);
	}
}
Example #6
0
CFSThread::~CFSThread()
{
#if defined (MAC)
	MPDeleteQueue(m_WaitQueue);
#endif
}