Removed unnecessary comments and lines.

Created eina_sched_{win32,posix}.c Now _eina_sched_prio_drop is in this file, not in eina_thread{win32,posix}.c
No more function about pthreads in eina_thread.c
Functions wrappers declared into eina_thread.h
Removed somes #ifdef linux
This commit is contained in:
carlos 2020-04-03 16:44:09 -03:00 committed by João Paulo Taylor Ienczak Zanette
parent 3bd220796f
commit b852570013
14 changed files with 389 additions and 287 deletions

View File

@ -129,7 +129,6 @@ _sysmon(void *data EINA_UNUSED, Eina_Thread thr EINA_UNUSED)
#ifndef _WIN32
pthread_getcpuclockid(thread, &cid);
#endif
//pthread_getcpuclockid(thread, &cid);
clock_gettime(cid, &t);
// calculate a long timestamp (64bits)
tim1 = (_eina_debug_thread_active[i].clok.tv_sec * 1000000000LL) +

View File

@ -16,9 +16,9 @@
* if not, see <http://www.gnu.org/licenses/>.
*/
# ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
# endif
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
@ -56,7 +56,6 @@ struct _Eina_Debug_Timer
static Eina_List *_timers = NULL;
static Eina_Bool _thread_runs = EINA_FALSE;
//static pthread_t _thread;
static Eina_Thread _thread;
static int pipeToThread[2];
@ -69,24 +68,24 @@ _timer_append(Eina_Debug_Timer *t)
unsigned int prev_time = 0;
char c = '\0';
EINA_LIST_FOREACH(_timers, itr, t2)
{
if (t2->timeout > t->timeout) goto end;
prev_time = t2->timeout;
}
{
if (t2->timeout > t->timeout) goto end;
prev_time = t2->timeout;
}
t2 = NULL;
end:
t->rel_time = t->timeout - prev_time;
if (!t2) _timers = eina_list_append(_timers, t);
else _timers = eina_list_prepend_relative(_timers, t, t2);
if (write(pipeToThread[1], &c, 1) != 1)
e_debug("EINA DEBUG ERROR: Can't wake up thread for debug timer");
e_debug("EINA DEBUG ERROR: Can't wake up thread for debug timer");
}
static void *
_monitor(void *_data EINA_UNUSED)
{
#ifdef HAVE_SYS_EPOLL_H
#define MAX_EVENTS 4
# define MAX_EVENTS 4
struct epoll_event event;
struct epoll_event events[MAX_EVENTS];
int epfd = epoll_create(MAX_EVENTS), ret;
@ -95,54 +94,53 @@ _monitor(void *_data EINA_UNUSED)
event.events = EPOLLIN;
ret = epoll_ctl(epfd, EPOLL_CTL_ADD, event.data.fd, &event);
if (ret) perror("epoll_ctl/add");
#ifdef EINA_HAVE_PTHREAD_SETNAME
# ifdef EINA_HAVE_PTHREAD_SETNAME
eina_thread_name_set(eina_thread_self(), "Edbg-tim");
# endif
eina_thread_name_set(eina_thread_self(), "Edbg-tim");
#endif
while (1)
{
int timeout = -1; //in milliseconds
#ifndef _WIN32
pthread_testcancel();
#endif
eina_spinlock_take(&_lock);
if (_timers)
{
Eina_Debug_Timer *t = eina_list_data_get(_timers);
timeout = t->timeout;
}
eina_spinlock_release(&_lock);
{
int timeout = -1; //in milliseconds
# ifndef _WIN32
pthread_testcancel();
# endif
eina_spinlock_take(&_lock);
if (_timers)
{
Eina_Debug_Timer *t = eina_list_data_get(_timers);
timeout = t->timeout;
}
eina_spinlock_release(&_lock);
ret = epoll_wait(epfd, events, MAX_EVENTS, timeout);
#ifndef _WIN32
pthread_testcancel();
#endif
ret = epoll_wait(epfd, events, MAX_EVENTS, timeout);
# ifndef _WIN32
pthread_testcancel();
# endif
/* Some timer has been add/removed or we need to exit */
if (ret)
{
char c;
if (read(pipeToThread[0], &c, 1) != 1) break;
}
else
{
Eina_List *itr, *itr2, *renew = NULL;
Eina_Debug_Timer *t;
eina_spinlock_take(&_lock);
EINA_LIST_FOREACH_SAFE(_timers, itr, itr2, t)
{
if (itr == _timers || t->rel_time == 0)
{
_timers = eina_list_remove(_timers, t);
if (t->cb(t->data)) renew = eina_list_append(renew, t);
else free(t);
}
}
EINA_LIST_FREE(renew, t) _timer_append(t);
eina_spinlock_release(&_lock);
}
}
/* Some timer has been add/removed or we need to exit */
if (ret)
{
char c;
if (read(pipeToThread[0], &c, 1) != 1) break;
}
else
{
Eina_List *itr, *itr2, *renew = NULL;
Eina_Debug_Timer *t;
eina_spinlock_take(&_lock);
EINA_LIST_FOREACH_SAFE(_timers, itr, itr2, t)
{
if (itr == _timers || t->rel_time == 0)
{
_timers = eina_list_remove(_timers, t);
if (t->cb(t->data)) renew = eina_list_append(renew, t);
else free(t);
}
}
EINA_LIST_FREE(renew, t) _timer_append(t);
eina_spinlock_release(&_lock);
}
}
#endif
_thread_runs = EINA_FALSE;
close(pipeToThread[0]);
@ -161,36 +159,36 @@ eina_debug_timer_add(unsigned int timeout_ms, Eina_Debug_Timer_Cb cb, void *data
eina_spinlock_take(&_lock);
_timer_append(t);
if (!_thread_runs)
{
{
#ifndef _WIN32
sigset_t oldset, newset;
sigset_t oldset, newset;
sigemptyset(&newset);
sigaddset(&newset, SIGPIPE);
sigaddset(&newset, SIGALRM);
sigaddset(&newset, SIGCHLD);
sigaddset(&newset, SIGUSR1);
sigaddset(&newset, SIGUSR2);
sigaddset(&newset, SIGHUP);
sigaddset(&newset, SIGQUIT);
sigaddset(&newset, SIGINT);
sigaddset(&newset, SIGTERM);
sigemptyset(&newset);
sigaddset(&newset, SIGPIPE);
sigaddset(&newset, SIGALRM);
sigaddset(&newset, SIGCHLD);
sigaddset(&newset, SIGUSR1);
sigaddset(&newset, SIGUSR2);
sigaddset(&newset, SIGHUP);
sigaddset(&newset, SIGQUIT);
sigaddset(&newset, SIGINT);
sigaddset(&newset, SIGTERM);
# ifdef SIGPWR
sigaddset(&newset, SIGPWR);
sigaddset(&newset, SIGPWR);
# endif
pthread_sigmask(SIG_BLOCK, &newset, &oldset);
pthread_sigmask(SIG_BLOCK, &newset, &oldset);
#endif
int err = pthread_create(&_thread, NULL, _monitor, NULL);
int err = pthread_create(&_thread, NULL, _monitor, NULL);
#ifndef _WIN32
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
#endif
if (err != 0)
{
e_debug("EINA DEBUG ERROR: Can't create debug timer thread!");
abort();
}
_thread_runs = EINA_TRUE;
}
if (err != 0)
{
e_debug("EINA DEBUG ERROR: Can't create debug timer thread!");
abort();
}
_thread_runs = EINA_TRUE;
}
eina_spinlock_release(&_lock);
return t;
}
@ -201,10 +199,10 @@ eina_debug_timer_del(Eina_Debug_Timer *t)
eina_spinlock_take(&_lock);
Eina_List *itr = eina_list_data_find_list(_timers, t);
if (itr)
{
_timers = eina_list_remove_list(_timers, itr);
free(t);
}
{
_timers = eina_list_remove_list(_timers, itr);
free(t);
}
eina_spinlock_release(&_lock);
}
@ -214,7 +212,7 @@ _eina_debug_timer_init(void)
eina_spinlock_new(&_lock);
#ifndef _WIN32
if (pipe(pipeToThread) == -1)
return EINA_FALSE;
return EINA_FALSE;
#endif
return EINA_TRUE;
}
@ -226,16 +224,14 @@ _eina_debug_timer_shutdown(void)
eina_spinlock_take(&_lock);
EINA_LIST_FREE(_timers, t)
free(t);
free(t);
close(pipeToThread[0]);
close(pipeToThread[1]);
if (_thread_runs)
eina_thread_cancel(_thread);
if (_thread_runs)
eina_thread_cancel(_thread);
_thread_runs = 0;
eina_spinlock_release(&_lock);
eina_spinlock_free(&_lock);
return EINA_TRUE;
}

View File

@ -176,7 +176,6 @@ eina_evlog(const char *event, void *obj, double srctime, const char *detail)
item = (Eina_Evlog_Item *)strings;
item->tim = SWAP_DBL(now);
item->srctim = SWAP_DBL(srctime);
//item->thread = SWAP_64((unsigned long long)(uintptr_t)pthread_self());
item->thread = SWAP_64((unsigned long long)(uintptr_t)eina_thread_self());
item->obj = SWAP_64((unsigned long long)(uintptr_t)obj);
item->event_offset = SWAP_16(sizeof(Eina_Evlog_Item));

View File

@ -297,7 +297,6 @@ eina_init(void)
#endif
#ifdef EFL_HAVE_THREADS
_eina_main_loop = eina_thread_self();
#endif
@ -389,11 +388,9 @@ eina_threads_init(void)
{
#ifdef EFL_HAVE_THREADS
int ret;
#ifdef EINA_HAVE_DEBUG_THREADS
# ifdef EINA_HAVE_DEBUG_THREADS
assert(eina_thread_equal(_eina_main_loop, eina_thread_self()));
#endif
# endif
++_eina_main_thread_count;
ret = _eina_main_thread_count;
@ -417,11 +414,10 @@ eina_threads_shutdown(void)
#ifdef EFL_HAVE_THREADS
int ret;
#ifdef EINA_HAVE_DEBUG_THREADS
# ifdef EINA_HAVE_DEBUG_THREADS
assert(eina_thread_equal(_eina_main_loop, eina_thread_self()));
assert(_eina_main_thread_count > 0);
#endif
# endif
ret = --_eina_main_thread_count;
if(_eina_main_thread_count > 0)
@ -443,11 +439,9 @@ eina_main_loop_is(void)
# ifdef __GNUC__
/* pthread_self() can't be optimized, it's a single asm "movl" */
if (__builtin_types_compatible_p(pthread_t, unsigned long int))
return (eina_thread_self() == _eina_main_loop);
else
# endif
if (eina_thread_equal(_eina_main_loop, eina_thread_self()))
return EINA_TRUE;
#endif
@ -458,12 +452,8 @@ eina_main_loop_is(void)
EAPI void
eina_main_loop_define(void)
{
#ifdef EFL_HAVE_THREADS
#ifdef EFL_HAVE_THREADS
_eina_main_loop = eina_thread_self();
#endif
}
/**
* @}
*/

View File

@ -21,13 +21,6 @@
#endif
#include "eina_thread.h"
#ifdef __linux__
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#endif
#include "eina_sched.h"
#include "eina_log.h"

View File

@ -30,7 +30,9 @@
#define EINA_SCHED_H_
#include "eina_types.h"
#include "eina_thread.h"
#define RTNICENESS 1
#define NICENESS 5
/**
* @brief Lowers the priority of the current thread.
@ -44,6 +46,7 @@
* only one that is implemented as of now. In this case, the nice level is
* incremented on this thread by @c NICENESS.
*/
inline void _eina_sched_prio_drop(void);
EAPI void eina_sched_prio_drop(void);
/**

View File

@ -0,0 +1,70 @@
/* EINA - EFL data type library
* Copyright (C) 2010 ProFUSION embedded systems
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library;
* if not, see <http://www.gnu.org/licenses/>.
*/
#include "eina_sched.h"
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>
#include <pthread.h>
inline void _eina_sched_prio_drop(void)
{
struct sched_param param;
int pol, ret;
Eina_Thread pthread_id;
pthread_id = eina_thread_self();
ret = pthread_getschedparam(pthread_id, &pol, &param);
if (ret)
{
EINA_LOG_ERR("Unable to query sched parameters");
return;
}
if (EINA_UNLIKELY(pol == SCHED_RR || pol == SCHED_FIFO))
{
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;
}
pthread_setschedparam(pthread_id, pol, &param);
}
else
{
int prio;
errno = 0;
prio = getpriority(PRIO_PROCESS, 0);
if (errno == 0)
{
prio += NICENESS;
if (prio > 19)
{
EINA_LOG_INFO("Max niceness reached; keeping max (19)");
prio = 19;
}
setpriority(PRIO_PROCESS, 0, prio);
}
}
}

View File

@ -0,0 +1,64 @@
/* EINA - EFL data type library
* Copyright (C) 2020 Carlos Signor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library;
* if not, see <http://www.gnu.org/licenses/>.
*/
#include "eina_sched.h"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
inline void _eina_sched_prio_drop(void)
{
Eina_Thread pthread_id;
int sched_priority;
pthread_id = eina_thread_self();
sched_priority = GetThreadPriority((HANDLE)pthread_id);
if (EINA_UNLIKELY(sched_priority == THREAD_PRIORITY_TIME_CRITICAL))
{
sched_priority -= RTNICENESS;
/* We don't change the policy */
if (sched_priority < 1)
{
EINA_LOG_INFO("RT prio < 1, setting to 1 instead");
sched_priority = 1;
}
if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
{
EINA_LOG_ERR("Unable to query sched parameters");
}
}
else
{
sched_priority += NICENESS;
/* We don't change the policy */
if (sched_priority > THREAD_PRIORITY_TIME_CRITICAL)
{
EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)");
sched_priority = THREAD_PRIORITY_TIME_CRITICAL;
}
if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
{
EINA_LOG_ERR("Unable to query sched parameters");
}
}
}

View File

@ -23,7 +23,7 @@
#include <stdlib.h>
#include "eina_config.h"
#include "eina_lock.h" /* it will include pthread.h with proper flags */
#include "eina_lock.h"
#include "eina_thread.h"
#include "eina_sched.h"
#include "eina_cpu.h"
@ -40,13 +40,10 @@
# include <string.h>
#if defined(EINA_HAVE_PTHREAD_AFFINITY) || defined(EINA_HAVE_PTHREAD_SETNAME)
#ifndef __linux__
#include <pthread_np.h>
#define cpu_set_t cpuset_t
#endif
# define cpu_set_t cpuset_t
#endif
static void *_eina_internal_call(void *context);
EAPI Eina_Thread
eina_thread_self(void)
@ -59,7 +56,32 @@ eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
{
return !!_eina_thread_equal(t1, t2);
}
static void *_eina_internal_call(void *context)
{
Eina_Thread_Call *c = context;
void *r;
Eina_Thread self;
// Default this thread to not cancellable as per Eina documentation
eina_thread_cancellable_set(EINA_FALSE, NULL);
EINA_THREAD_CLEANUP_PUSH(free, c);
if (c->prio == EINA_THREAD_BACKGROUND || c->prio == EINA_THREAD_IDLE)
eina_sched_prio_drop();
self = eina_thread_self();
_eina_debug_thread_add(&self);
EINA_THREAD_CLEANUP_PUSH(_eina_debug_thread_del, &self);
r = c->func((void*) c->data, eina_thread_self());
EINA_THREAD_CLEANUP_POP(EINA_TRUE);
EINA_THREAD_CLEANUP_POP(EINA_TRUE);
return r;
}
EAPI Eina_Bool
eina_thread_create(Eina_Thread *t,
Eina_Thread_Priority prio, int affinity,
@ -104,7 +126,7 @@ eina_thread_name_set(Eina_Thread t, const char *name)
buf[15] = 0;
}
else buf[0] = 0;
if (_eina_thread_set_name(t, buf) == 0) return EINA_TRUE;
if (_eina_thread_name_set(t, buf) == 0) return EINA_TRUE;
#else
(void)t;
(void)name;
@ -122,36 +144,13 @@ eina_thread_cancel(Eina_Thread t)
EAPI Eina_Bool
eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable)
{
int state = cancellable ? EINA_THREAD_CANCEL_ENABLE : EINA_THREAD_CANCEL_DISABLE;
int old = 0;
int r;
#ifndef _WIN32
/* enforce deferred in case users changed to asynchronous themselves */
pthread_setcanceltype(EINA_THREAD_CANCEL_DEFERRED, &old);
r = pthread_setcancelstate(state, &old);
if (was_cancellable && r == 0)
*was_cancellable = (old == EINA_THREAD_CANCEL_ENABLE);
return r == 0;
#else
if(!state){
*was_cancellable = EINA_TRUE;
return EINA_FALSE;
}else{
*was_cancellable = EINA_TRUE;
return EINA_TRUE;
}
#endif
return _eina_thread_cancellable_set(cancellable,was_cancellable);
}
EAPI void
eina_thread_cancel_checkpoint(void)
{
#ifndef _WIN32
pthread_testcancel();
#endif
_eina_thread_cancel_checkpoint();
}
EAPI void *
@ -182,29 +181,3 @@ eina_thread_shutdown(void)
return EINA_TRUE;
}
static void *_eina_internal_call(void *context)
{
Eina_Thread_Call *c = context;
void *r;
Eina_Thread self;
// Default this thread to not cancellable as per Eina documentation
eina_thread_cancellable_set(EINA_FALSE, NULL);
EINA_THREAD_CLEANUP_PUSH(free, c);
if (c->prio == EINA_THREAD_BACKGROUND || c->prio == EINA_THREAD_IDLE)
eina_sched_prio_drop();
self = eina_thread_self();
_eina_debug_thread_add(&self);
EINA_THREAD_CLEANUP_PUSH(_eina_debug_thread_del, &self);
r = c->func((void*) c->data, eina_thread_self());
EINA_THREAD_CLEANUP_POP(EINA_TRUE);
EINA_THREAD_CLEANUP_POP(EINA_TRUE);
return r;
}

View File

@ -336,10 +336,8 @@ typedef void *(*Eina_Thread_Cancellable_Run_Cb)(void *data);
*
* @since 1.19
*/
EAPI void *eina_thread_cancellable_run(Eina_Thread_Cancellable_Run_Cb cb, Eina_Free_Cb cleanup_cb, void *data);
typedef struct _Eina_Thread_Call Eina_Thread_Call;
struct _Eina_Thread_Call
{
@ -350,11 +348,23 @@ struct _Eina_Thread_Call
int affinity;
};
/*
* These defines are used by eina_sched to drop the thread priority
* Those are the functions definitions of wrappers that will implements the functions
* above with win32 and posix api
*/
#define RTNICENESS 1
#define NICENESS 5
inline Eina_Thread _eina_thread_self(void);
inline Eina_Bool _eina_thread_equal(Eina_Thread t1, Eina_Thread t2);
inline Eina_Bool _eina_thread_create(Eina_Thread *t,
int affinity,
void *(*func)(void *data),
void *data);
inline void *_eina_thread_join(Eina_Thread t);
Eina_Bool _eina_thread_name_set(Eina_Thread thread, char *buf);
Eina_Bool _eina_thread_cancel(Eina_Thread thread);
void _eina_thread_setcanceltype(int type, int *oldtype);
void _eina_thread_cancel_checkpoint();
EAPI Eina_Bool _eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable);
int _eina_thread_setcancelstate(int type, int *oldtype);
void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t);
#ifdef _WIN32
# define EINA_THREAD_CANCEL_ENABLE 0
@ -370,12 +380,6 @@ struct _Eina_Thread_Call
# define EINA_THREAD_CANCELED PTHREAD_CANCELED
#endif
/**
* @}
*/
/**
* @}
*/

View File

@ -1,5 +1,5 @@
/* EINA - EFL data type library
* Copyright (C) 2012 Cedric Bail
* Copyright (C) 2020 Carlos Signor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -23,7 +23,7 @@
#include <stdlib.h>
#include "eina_config.h"
#include "eina_lock.h" /* it will include pthread.h with proper flags */
#include "eina_lock.h"
#include "eina_thread.h"
#include "eina_sched.h"
#include "eina_cpu.h"
@ -55,14 +55,14 @@ _eina_thread_join(Eina_Thread t)
return NULL;
}
Eina_Bool _eina_thread_set_name(Eina_Thread thread, char *buf)
Eina_Bool _eina_thread_name_set(Eina_Thread thread, char *buf)
{
#ifndef __linux__
pthread_set_name_np((pthread_t)t, buf)
return EINA_TRUE;
#else
return pthread_setname_np((pthread_t)thread, buf);
#endif
#ifndef __linux__
pthread_set_name_np((pthread_t)t, buf);
return EINA_TRUE;
#else
return pthread_setname_np((pthread_t)thread, buf);
#endif
}
inline Eina_Bool
@ -75,7 +75,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
pthread_attr_init(&attr);
if (affinity >= 0)
{
{
#ifdef EINA_HAVE_PTHREAD_AFFINITY
cpu_set_t cpu;
@ -83,7 +83,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
CPU_SET(affinity, &cpu);
pthread_attr_setaffinity_np(&attr, sizeof(cpu), &cpu);
#endif
}
}
/* setup initial locks */
@ -129,48 +129,31 @@ _eina_thread_self(void)
{
return (Eina_Thread)pthread_self();
}
inline void _eina_sched_prio_drop(void)
void _eina_thread_setcanceltype(int type, int *oldtype)
{
struct sched_param param;
int pol, ret;
Eina_Thread pthread_id;
pthread_setcanceltype(EINA_THREAD_CANCEL_DEFERRED, &oldtype);
}
int _eina_thread_setcancelstate(int type, int *oldtype)
{
return pthread_setcancelstate(type, &oldtype);
}
EAPI Eina_Bool
_eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable)
{
int state = cancellable ? EINA_THREAD_CANCEL_ENABLE : EINA_THREAD_CANCEL_DISABLE;
int old = 0;
int r;
pthread_id = eina_thread_self();
ret = pthread_getschedparam(pthread_id, &pol, &param);
if (ret)
{
EINA_LOG_ERR("Unable to query sched parameters");
return;
}
/* enforce deferred in case users changed to asynchronous themselves */
if (EINA_UNLIKELY(pol == SCHED_RR || pol == SCHED_FIFO))
{
param.sched_priority -= RTNICENESS;
_eina_thread_setcanceltype(EINA_THREAD_CANCEL_DEFERRED, &old);
/* 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;
}
pthread_setschedparam(pthread_id, pol, &param);
}
else
{
int prio;
errno = 0;
prio = getpriority(PRIO_PROCESS, 0);
if (errno == 0)
{
prio += NICENESS;
if (prio > 19)
{
EINA_LOG_INFO("Max niceness reached; keeping max (19)");
prio = 19;
}
setpriority(PRIO_PROCESS, 0, prio);
}
}
r = _eina_thread_setcancelstate(state, &old);
if (was_cancellable && r == 0)
*was_cancellable = (old == EINA_THREAD_CANCEL_ENABLE);
return r == 0;
}
void _eina_thread_cancel_checkpoint(){
pthread_testcancel();
}

View File

@ -21,10 +21,8 @@
#endif
#include <stdlib.h>
#include "eina_config.h"
#include "eina_lock.h" /* it will include pthread.h with proper flags */
#include "eina_lock.h"
#include "eina_sched.h"
#include "eina_cpu.h"
#include "eina_thread.h"
@ -37,16 +35,9 @@
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#include <errno.h>
#include <string.h>
#if defined(EINA_HAVE_PTHREAD_AFFINITY) || defined(EINA_HAVE_PTHREAD_SETNAME)
#ifndef __linux__
#define cpu_set_t cpuset_t
#endif
#endif
typedef struct _Eina_win32_thread_func
{
void *data;
@ -86,12 +77,16 @@ void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t)
{
case EINA_THREAD_URGENT:
nPriority = THREAD_PRIORITY_HIGHEST;
break;
case EINA_THREAD_NORMAL:
nPriority = THREAD_PRIORITY_NORMAL;
break;
case EINA_THREAD_BACKGROUND:
nPriority = THREAD_PRIORITY_BELOW_NORMAL;
break;
case EINA_THREAD_IDLE:
nPriority = THREAD_PRIORITY_IDLE;
break;
}
SetThreadPriority((HANDLE)*t, nPriority);
@ -130,14 +125,7 @@ _eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), voi
if (affinity >= 0 && ret)
{
#ifdef EINA_HAVE_PTHREAD_AFFINITY
cpu_set_t cpu;
CPU_ZERO(&cpu);
CPU_SET(affinity, &cpu);
SetThreadAffinityMask(*t, (DWORD_PTR *)&cpu);
#else
SetThreadAffinityMask(*t, (DWORD_PTR *)&affinity);
#endif
}
return ret;
@ -158,7 +146,7 @@ _eina_thread_self(void)
return (Eina_Thread)GetCurrentThread();
}
Eina_Bool _eina_thread_set_name(Eina_Thread thread, char *buf)
Eina_Bool _eina_thread_name_set(Eina_Thread thread, char *buf)
{
HRESULT res = SetThreadDescription((HANDLE)thread, (PCWSTR)buf);
return HRESULT_CODE(res);
@ -171,44 +159,30 @@ Eina_Bool _eina_thread_cancel(Eina_Thread thread)
ExitThread(*lpExitCode);
return !success;
}
inline void _eina_sched_prio_drop(void)
void _eina_thread_setcanceltype(int type, int *oldtype)
{
Eina_Thread pthread_id;
int sched_priority;
pthread_id = eina_thread_self();
sched_priority = GetThreadPriority((HANDLE)pthread_id);
if (EINA_UNLIKELY(sched_priority == THREAD_PRIORITY_TIME_CRITICAL))
pthread_setcanceltype(EINA_THREAD_CANCEL_DEFERRED, &oldtype);
}
int _eina_thread_setcancelstate(int type, int *oldtype)
{
return pthread_setcancelstate(type, &oldtype);
}
EAPI Eina_Bool
_eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable)
{
int state = cancellable ? EINA_THREAD_CANCEL_ENABLE : EINA_THREAD_CANCEL_DISABLE;
if (!state)
{
sched_priority -= RTNICENESS;
/* We don't change the policy */
if (sched_priority < 1)
{
EINA_LOG_INFO("RT prio < 1, setting to 1 instead");
sched_priority = 1;
}
if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
{
EINA_LOG_ERR("Unable to query sched parameters");
}
*was_cancellable = EINA_TRUE;
return EINA_FALSE;
}
else
{
sched_priority += NICENESS;
/* We don't change the policy */
if (sched_priority > THREAD_PRIORITY_TIME_CRITICAL)
{
EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)");
sched_priority = THREAD_PRIORITY_TIME_CRITICAL;
}
if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
{
EINA_LOG_ERR("Unable to query sched parameters");
}
*was_cancellable = EINA_TRUE;
return EINA_TRUE;
}
}
void _eina_thread_cancel_checkpoint(void)
{
pthread_testcancel();
}

View File

@ -200,11 +200,11 @@ sources = [
if sys_windows == true
sources += 'eina_file_win32.c'
sources += 'eina_thread_win32.c'
sources += 'eina_lock_win32.c'
sources += 'eina_sched_win32.c'
else
sources += 'eina_file.c'
sources += 'eina_thread_posix.c'
sources += 'eina_lock_posix.c'
sources += 'eina_sched_posix.c'
endif
eina_config = configuration_data()

View File

@ -89,6 +89,60 @@ UNIMPLEMENTED inline int pthread_cond_signal(void* c)
return 0;
}
UNIMPLEMENTED inline int pthread_rwlock_init(void* a, ...)
{
#warning pthread_rwlock_init is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_mutexattr_settype(void* a, ...)
{
#warning pthread_mutexattr_settype is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_mutex_init(void* a, ...)
{
#warning pthread_mutex_init is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_mutex_destroy(void* a, ...)
{
#warning pthread_mutex_destroy is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_condattr_init(void* a, ...)
{
#warning pthread_condattr_init is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_cond_init(void* a, ...)
{
#warning pthread_cond_init is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_condattr_destroy(void* a, ...)
{
#warning pthread_condattr_destroy is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_cond_destroy(void* a, ...)
{
#warning pthread_cond_destroy is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_rwlock_destroy(void* a, ...)
{
#warning pthread_rwlock_destroy is not implemented.
return 0;
}
UNIMPLEMENTED inline int pthread_rwlock_rdlock(void* c)
{
#warning pthread_rwlock_rdlock is not implemented.