CFSThread::CFSThread() { m_pData=0; m_hThread=0; #if defined (MAC) MPCreateQueue(&m_WaitQueue); #endif }
cFUThread::cFUThread(THREAD_ROUTINE_POINTER startAddress, void* parameter, bool suspended, const char* szName) : isSuspended(suspended) , isSuspendedCS() , semaphore() , threadStartedSemaphore() , terminate(false) , exitCode(0) #ifdef FP_APPLE , queue(cFUThread_INVALID) #endif , name() , thread(cFUThread_INVALID) { if (szName != nullptr) { name = szName; } //Create the structure from the function parameters. cFUThreadInternalParam* params = new cFUThreadInternalParam; params->object = this; params->parameter = parameter; params->func = startAddress; #if defined(WIN32) unsigned int ThreadId; thread = (HANDLE)_beginthreadex(nullptr, 0, InternalFunc, params, 0, &ThreadId); threadStartedSemaphore.Down(); #elif defined (FP_APPLE) if (MPLibraryIsLoaded()) { OSStatus status = MPCreateQueue(&queue); if (status == noErr) status = MPCreateTask(&InternalFunc, params, 0, queue, &exitCode, nullptr, 0, &thread); } #elif defined(LINUX) || defined(IOS) || defined(ANDROID) int status = pthread_create(&thread, nullptr, InternalFunc, params); if (status == 0) // Success threadStartedSemaphore.Down(); #endif }
bool wxThreadInternal::Create( wxThread *thread, unsigned int stackSize ) { wxASSERT_MSG( m_state == STATE_NEW && !m_tid, wxT("Create()ing thread twice?") ); if ( thread->IsDetached() ) Detach(); OSStatus err = noErr; m_thread = thread; if ( m_notifyQueueId == kInvalidID ) { OSStatus err = MPCreateQueue( &m_notifyQueueId ); if (err != noErr) { wxLogSysError( wxT("Can't create the thread event queue") ); return false; } } m_state = STATE_NEW; err = MPCreateTask( MacThreadStart, (void*)m_thread, stackSize, m_notifyQueueId, &m_exitcode, 0, 0, &m_tid ); if (err != noErr) { wxLogSysError( wxT("Can't create thread") ); return false; } if ( m_prio != wxPRIORITY_DEFAULT ) SetPriority( m_prio ); return true; }
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, ¶m, 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, ¶m); 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, ¶m, 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(); }
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); } }