forked from enlightenment/efl
eina_sched.c win32 implementation
This commit is contained in:
parent
cb61d63cb8
commit
d51f5295e5
|
@ -19,8 +19,8 @@
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include "eina_thread.h"
|
||||||
#include <pthread.h>
|
//#include <pthread.h>
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
# include <sched.h>
|
# include <sched.h>
|
||||||
# include <sys/time.h>
|
# include <sys/time.h>
|
||||||
|
@ -31,17 +31,18 @@
|
||||||
#include "eina_sched.h"
|
#include "eina_sched.h"
|
||||||
#include "eina_log.h"
|
#include "eina_log.h"
|
||||||
|
|
||||||
#define RTNICENESS 1s
|
#define RTNICENESS 1
|
||||||
#define NICENESS 5
|
#define NICENESS 5
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
EAPI void
|
EAPI void
|
||||||
eina_sched_prio_drop(void)
|
eina_sched_prio_drop(void)
|
||||||
{
|
{
|
||||||
struct sched_param param;
|
struct sched_param param;
|
||||||
int pol, ret;
|
int pol, ret;
|
||||||
pthread_t pthread_id;
|
Eina_Thread pthread_id;
|
||||||
|
|
||||||
pthread_id = pthread_self();
|
pthread_id = eina_thread_self(); //pthread_id = pthread_self();
|
||||||
ret = pthread_getschedparam(pthread_id, &pol, ¶m);
|
ret = pthread_getschedparam(pthread_id, &pol, ¶m);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
|
@ -82,3 +83,48 @@ eina_sched_prio_drop(void)
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
EAPI void
|
||||||
|
eina_sched_prio_drop(void)
|
||||||
|
{
|
||||||
|
Eina_Thread pthread_id;
|
||||||
|
struct sched_param param;
|
||||||
|
|
||||||
|
pthread_id = eina_thread_self(); //pthread_id = pthread_self();
|
||||||
|
|
||||||
|
param.sched_priority = GetThreadPriority((HANDLE)pthread_id);
|
||||||
|
|
||||||
|
if(EINA_UNLIKELY(param.sched_priority == THREAD_PRIORITY_TIME_CRITICAL))
|
||||||
|
{
|
||||||
|
param.sched_priority -= RTNICENESS;
|
||||||
|
|
||||||
|
/* We don't change the policy */
|
||||||
|
if (param.sched_priority < 1)
|
||||||
|
{
|
||||||
|
EINA_LOG_INFO("RT prio < 1, setting to 1 instead");
|
||||||
|
param.sched_priority = 1;
|
||||||
|
}
|
||||||
|
if(!SetThreadPriority((HANDLE)pthread_id, param.sched_priority))
|
||||||
|
{
|
||||||
|
EINA_LOG_ERR("Unable to query sched parameters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
param.sched_priority += NICENESS;
|
||||||
|
|
||||||
|
/* We don't change the policy */
|
||||||
|
if (param.sched_priority > THREAD_PRIORITY_TIME_CRITICAL)
|
||||||
|
{
|
||||||
|
EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)");
|
||||||
|
param.sched_priority = THREAD_PRIORITY_TIME_CRITICAL;
|
||||||
|
}
|
||||||
|
if(!SetThreadPriority((HANDLE)pthread_id, param.sched_priority))
|
||||||
|
{
|
||||||
|
EINA_LOG_ERR("Unable to query sched parameters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -48,7 +48,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static inline void *
|
inline void *
|
||||||
_eina_thread_join(Eina_Thread t)
|
_eina_thread_join(Eina_Thread t)
|
||||||
{
|
{
|
||||||
void *ret = NULL;
|
void *ret = NULL;
|
||||||
|
@ -58,7 +58,7 @@ _eina_thread_join(Eina_Thread t)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Eina_Bool
|
inline Eina_Bool
|
||||||
_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data)
|
_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -107,13 +107,13 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Eina_Bool
|
inline Eina_Bool
|
||||||
_eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
|
_eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
|
||||||
{
|
{
|
||||||
return pthread_equal((pthread_t)t1, (pthread_t)t2);
|
return pthread_equal((pthread_t)t1, (pthread_t)t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Eina_Thread
|
inline Eina_Thread
|
||||||
_eina_thread_self(void)
|
_eina_thread_self(void)
|
||||||
{
|
{
|
||||||
return (Eina_Thread)pthread_self();
|
return (Eina_Thread)pthread_self();
|
||||||
|
@ -122,7 +122,7 @@ _eina_thread_self(void)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static void *
|
void *
|
||||||
_eina_internal_call(void *context)
|
_eina_internal_call(void *context)
|
||||||
{
|
{
|
||||||
Eina_Thread_Call *c = context;
|
Eina_Thread_Call *c = context;
|
||||||
|
|
|
@ -66,8 +66,8 @@ inline void *
|
||||||
_eina_thread_join(Eina_Thread t)
|
_eina_thread_join(Eina_Thread t)
|
||||||
{
|
{
|
||||||
//void *ret = NULL;
|
//void *ret = NULL;
|
||||||
int timeout_millis = 10000;
|
//int timeout_millis = 10000;
|
||||||
int ret = WaitForSingleObject(t,timeout_millis);//int ret = pthread_join((pthread_t)t, &ret);
|
int ret = (int)WaitForSingleObject(t,INFINITE);//int ret = pthread_join((pthread_t)t, &ret);
|
||||||
|
|
||||||
if (ret != 0) return ret;//if (ret == 0) return ret;
|
if (ret != 0) return ret;//if (ret == 0) return ret;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in New Issue