Ejemplo n.º 1
0
Archivo: Os.c Proyecto: broonie/ohNet
DWORD threadEntrypoint(LPVOID aArg)
{
    ThreadData* data = (ThreadData*)aArg;
    int priority = THREAD_PRIORITY_NORMAL;
    static const int kHostPriorities[] = { THREAD_PRIORITY_IDLE
                                          ,THREAD_PRIORITY_LOWEST
                                          ,THREAD_PRIORITY_BELOW_NORMAL
                                          ,THREAD_PRIORITY_NORMAL
                                          ,THREAD_PRIORITY_ABOVE_NORMAL
                                          ,THREAD_PRIORITY_HIGHEST
                                          ,THREAD_PRIORITY_TIME_CRITICAL };
    static const int kNumHostPriorities = sizeof(kHostPriorities) / sizeof(kHostPriorities[0]);
    int step = (kPriorityMax - kPriorityMin) / kNumHostPriorities;
    int i;

    assert(data != NULL);

    for (i=kNumHostPriorities-1; i>=0; i--) {
        if (kPriorityMin + (i*step) < data->iPriority) {
            priority = kHostPriorities[i];
            break;
        }
    }
    if (!SetThreadPriority(data->iThread, priority)) {
        //fprintf(stderr, "SetPriority failed (err=%d)\n", GetLastError());
        //fflush(stderr);
    }

    (void)TlsSetValue(data->iCtx->iTlsIndex, data->iArg);
    data->iEntryPoint(data->iArg);

    return 0;
}
Ejemplo n.º 2
0
static void* threadEntrypoint(void* aArg)
{
#ifndef __ANDROID__
    int oldState;
    int status;
#endif
    ThreadData* data = (ThreadData*)aArg;
    assert(data != NULL);

#if defined(ATTEMPT_THREAD_PRIORITIES)
    {
        TInt platMin = sched_get_priority_min(kThreadSchedPolicy);
        TInt platMax = sched_get_priority_max(kThreadSchedPolicy);
        // convert the UPnP library's 50 - 150 priority range into
        // an equivalent posix priority
        // ...calculate priority as percentage of library range
        int32_t percent = (((int32_t )data->iPriority - 50) * 100) / (150 - 50);
        // ...calculate native priority as 'percent' through the dest range
        int32_t priority = platMin + ((percent * (platMax - platMin))/100);
        sched_param param;
        param.sched_priority = priority;
        int status = pthread_setschedparam(data->iThread, kThreadSchedPolicy, &param);
        assert(status == 0);
    }
#elif defined(ATTEMPT_THREAD_NICENESS) // ATTEMPT_THREAD_PRIORITIES
    {
        static const int kMinimumNice = 5; // set MIN
        // Map all prios > 105 -> nice 0 (default), anything else to MIN
        //int nice_value = (data->iPriority > 105 ? 0 : kMinimumNice);
        // Map prio=[50,150]-> nice=[MIN,0]
        int nice_value = -1 * (((((int) data->iPriority-50) * kMinimumNice) / (150-50)) - kMinimumNice);
        if ( nice_value < 0 )
            nice_value = 0;
        //printf("Thread of priority %d asking for niceness %d (current niceness is %d)\n", data->iPriority, nice_value, getpriority(PRIO_PROCESS, 0));
        int result = setpriority(PRIO_PROCESS, 0, nice_value);
        //if ( result == -1 )
        //    perror("Warning: Could not renice this thread");
    }
#endif

    // Disable cancellation - we're in a C++ environment, and
    // don't want to rely on pthreads to mess things up for us.
#ifndef __ANDROID__
    status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
    assert(status == 0);
#endif

    //tlsThreadArg = data->iArg;
    pthread_setspecific(data->iCtx->iThreadArgKey, data->iArg);
    data->iEntryPoint(data->iArg);

    return NULL;
}
Ejemplo n.º 3
0
Archivo: Os.c Proyecto: astaykov/ohNet
static void* threadEntrypoint(void* aArg)
{
#ifndef __ANDROID__
    int oldState;
    int status;
#endif
    ThreadData* data = (ThreadData*)aArg;
    assert(data != NULL);

#ifdef ATTEMPT_THREAD_PRIORITIES
    {
        TInt platMin = sched_get_priority_min(kThreadSchedPolicy);
        TInt platMax = sched_get_priority_max(kThreadSchedPolicy);
        // convert the UPnP library's 50 - 150 priority range into
        // an equivalent posix priority
        // ...calculate priority as percentage of library range
        int32_t percent = (((int32_t )data->iPriority - 50) * 100) / (150 - 50);
        // ...calculate native priority as 'percent' through the dest range
        int32_t priority = platMin + ((percent * (platMax - platMin))/100);
        sched_param param;
        param.sched_priority = priority;
        int status = pthread_setschedparam(data->iThread, kThreadSchedPolicy, &param);
        assert(status == 0);
    }
#endif // ATTEMPT_THREAD_PRIORITIES

    // Disable cancellation - we're in a C++ environment, and
    // don't want to rely on pthreads to mess things up for us.
#ifndef __ANDROID__
    status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
    assert(status == 0);
#endif

    //tlsThreadArg = data->iArg;
    pthread_setspecific(gThreadArgKey, data->iArg);
    data->iEntryPoint(data->iArg);

    return NULL;
}