eina_sched.c win32 implementation

This commit is contained in:
caiosignor 2020-03-16 15:12:00 -03:00 committed by João Paulo Taylor Ienczak Zanette
parent cb61d63cb8
commit d51f5295e5
3 changed files with 58 additions and 12 deletions

View File

@ -19,8 +19,8 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <pthread.h>
#include "eina_thread.h"
//#include <pthread.h>
#ifdef __linux__
# include <sched.h>
# include <sys/time.h>
@ -31,17 +31,18 @@
#include "eina_sched.h"
#include "eina_log.h"
#define RTNICENESS 1s
#define RTNICENESS 1
#define NICENESS 5
#ifndef _WIN32
EAPI void
eina_sched_prio_drop(void)
{
struct sched_param param;
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, &param);
if (ret)
{
@ -82,3 +83,48 @@ eina_sched_prio_drop(void)
}
# 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

View File

@ -48,7 +48,7 @@
#endif
static inline void *
inline void *
_eina_thread_join(Eina_Thread t)
{
void *ret = NULL;
@ -58,7 +58,7 @@ _eina_thread_join(Eina_Thread t)
return NULL;
}
static inline Eina_Bool
inline Eina_Bool
_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data)
{
int err;
@ -107,13 +107,13 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
return EINA_FALSE;
}
static inline Eina_Bool
inline Eina_Bool
_eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
{
return pthread_equal((pthread_t)t1, (pthread_t)t2);
}
static inline Eina_Thread
inline Eina_Thread
_eina_thread_self(void)
{
return (Eina_Thread)pthread_self();
@ -122,7 +122,7 @@ _eina_thread_self(void)
/*
static void *
void *
_eina_internal_call(void *context)
{
Eina_Thread_Call *c = context;

View File

@ -66,8 +66,8 @@ inline void *
_eina_thread_join(Eina_Thread t)
{
//void *ret = NULL;
int timeout_millis = 10000;
int ret = WaitForSingleObject(t,timeout_millis);//int ret = pthread_join((pthread_t)t, &ret);
//int timeout_millis = 10000;
int ret = (int)WaitForSingleObject(t,INFINITE);//int ret = pthread_join((pthread_t)t, &ret);
if (ret != 0) return ret;//if (ret == 0) return ret;
return NULL;