コード例 #1
0
ファイル: Win32Thread.cpp プロジェクト: marekolsak/fastgrid
		//-------------------------------------------------------------------------
		// Win32Threads standard start routine.
		//
		static unsigned long __stdcall StartThread(void *data) {

			Thread *thread = static_cast<Thread *>(data);
			Win32ThreadPrivateData *pd =
				static_cast<Win32ThreadPrivateData *>(thread->_prvData);

			TlsSetValue(Win32ThreadPrivateData::TLS.ID ,data);
			//---------------------------------------------------------------------
			// Set the proper scheduling priorities
			//
			SetThreadSchedulingParams(thread);

			pd->isRunning = true;
			pd->isCanceled = false;

			try{
				thread->run();
			}
			catch(...)
			{
				// abnormal termination but must be caught in win32 anyway
			}

			pd->isRunning = false;
			return 0;
		};
コード例 #2
0
			//-------------------------------------------------------------------------
			// Win32Threads standard start routine.
			//
			static unsigned int __stdcall StartThread(void *data) {

				Thread *thread = static_cast<Thread *>(data);

				Win32ThreadPrivateData *pd =
					static_cast<Win32ThreadPrivateData *>(thread->m_prvData);

				if (thread->m_prvData == 0) return 0;

				TlsSetValue(Win32ThreadPrivateData::TLS.getId(), data);
				//---------------------------------------------------------------------
				// Set the proper scheduling priorities
				//
				SetThreadSchedulingParams(thread);

				pd->isRunning = true;

				// release the thread that created this thread.
				pd->threadStartedBlock.release();

				if (0 <= pd->cpunum)
					thread->setProcessorAffinity(pd->cpunum);

				try{
					thread->run();
				}
				catch (Win32ThreadCanceled&)
				{
					// thread is canceled do cleanup
					try {
						thread->cancelCleanup();
					}
					catch (...) {}
				}
				catch (...)
				{
					// abnormal termination but must be caught in win32 anyway
				}

				TlsSetValue(Win32ThreadPrivateData::TLS.getId(), 0);
				pd->isRunning = false;

				return 0;
			};
コード例 #3
0
ファイル: PThread.cpp プロジェクト: aoighost/osg
    //-------------------------------------------------------------------------
    // pthreads standard start routine.
    //
    static void *StartThread(void *data)
    {

        Thread *thread = static_cast<Thread *>(data);

        PThreadPrivateData *pd =
        static_cast<PThreadPrivateData *>(thread->_prvData);


        if (pd->cpunum>=0)
        {
#if defined(__sgi)
            pthread_setrunon_np( pd->cpunum );
#elif defined(HAVE_PTHREAD_SETAFFINITY_NP) || defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY) || defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
            cpu_set_t cpumask;
            CPU_ZERO( &cpumask );
            CPU_SET( pd->cpunum, &cpumask );

#if defined(HAVE_PTHREAD_SETAFFINITY_NP)
            pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);
#elif defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
            sched_setaffinity( 0, sizeof(cpumask), &cpumask );
#elif defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
            sched_setaffinity( 0, &cpumask );
#endif
#endif
        }
#if defined(HAVE_PTHREAD_SETAFFINITY_NP) || defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY) || defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
        else
        {
            // BUG-fix for linux:
            // Each thread inherits the processor affinity mask from its parent thread.
            // We need to explicitly set it to all CPUs, if no affinity was specified.

            cpu_set_t cpumask;
            CPU_ZERO( &cpumask );

            for (int i = 0; i < OpenThreads::GetNumberOfProcessors(); ++i)
            {
                CPU_SET( i, &cpumask );
            }

#if defined(HAVE_PTHREAD_SETAFFINITY_NP)
            pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);
#elif defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
            sched_setaffinity( 0, sizeof(cpumask), &cpumask );
#elif defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
            sched_setaffinity( 0, &cpumask );
#endif
        }
#endif

        ThreadCleanupStruct tcs;
        tcs.thread = thread;
        tcs.runflag = &pd->_isRunning;

        // Set local storage so that Thread::CurrentThread() can return the right thing
        int status = pthread_setspecific(PThreadPrivateData::s_tls_key, thread);
        if (status)
        {
            printf("Error: pthread_setspecific(,) returned error status, status = %d\n",status);
        }

        pthread_cleanup_push(thread_cleanup_handler, &tcs);

#ifdef ALLOW_PRIORITY_SCHEDULING

        //---------------------------------------------------------------------
        // Set the proper scheduling priorities
        //
        SetThreadSchedulingParams(thread);

#endif // ] ALLOW_PRIORITY_SCHEDULING

        pd->setRunning(true);

        // release the thread that created this thread.
        pd->threadStartedBlock.release();

        thread->run();

        pd->setRunning(false);

        pthread_cleanup_pop(0);

        return 0;

    };
コード例 #4
0
ファイル: PThread.cpp プロジェクト: BlitzMaxModules/osg.mod
    //-------------------------------------------------------------------------
    // pthreads standard start routine.
    //
    static void *StartThread(void *data) {

	Thread *thread = static_cast<Thread *>(data);

	PThreadPrivateData *pd =
	    static_cast<PThreadPrivateData *>(thread->_prvData);
            

        if (pd->cpunum>=0)
        {
#if defined(__sgi)
            pthread_setrunon_np( pd->cpunum );
#elif defined(HAVE_PTHREAD_SETAFFINITY_NP) || defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY) || defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
            cpu_set_t cpumask;
            CPU_ZERO( &cpumask );
            CPU_SET( pd->cpunum, &cpumask );

#if defined(HAVE_PTHREAD_SETAFFINITY_NP)
            pthread_setaffinity_np( pthread_self(), sizeof(cpumask), &cpumask);
#elif defined(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
            sched_setaffinity( 0, sizeof(cpumask), &cpumask );
#elif defined(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
            sched_setaffinity( 0, &cpumask );
#endif
#endif
        }
        

	ThreadCleanupStruct tcs;
	tcs.thread = thread;
	tcs.runflag = &pd->isRunning;

	// Set local storage so that Thread::CurrentThread() can return the right thing
	int status = pthread_setspecific(PThreadPrivateData::s_tls_key, thread);
	if (status)
        {
            printf("Error: pthread_setspecific(,) returned error status, status = %d\n",status);
        }

	pthread_cleanup_push(thread_cleanup_handler, &tcs);

#ifdef ALLOW_PRIORITY_SCHEDULING

	//---------------------------------------------------------------------
	// Set the proper scheduling priorities
	//
	SetThreadSchedulingParams(thread);

#endif // ] ALLOW_PRIORITY_SCHEDULING

        pd->isRunning = true;

        // release the thread that created this thread.
        pd->threadStartedBlock.release();

        thread->run();

        pd->isRunning = false;

	pthread_cleanup_pop(0);

        return 0;

    };