merged from devs/coquinho/lock

This commit is contained in:
caiosignor 2020-03-13 12:57:56 -03:00 committed by João Paulo Taylor Ienczak Zanette
parent 425a9a5fbd
commit f9b57e5569
11 changed files with 103 additions and 96 deletions

View File

@ -556,14 +556,17 @@ _monitor(void *_data)
// set a name for this thread for system debugging // set a name for this thread for system debugging
#ifdef EINA_HAVE_PTHREAD_SETNAME #ifdef EINA_HAVE_PTHREAD_SETNAME
/*
# ifndef __linux__ # ifndef __linux__
pthread_set_name_np pthread_set_name_np
# else # else
pthread_setname_np pthread_setname_np
# endif # endif
(pthread_self(), "Edbg-mon"); (pthread_self(), "Edbg-mon");
#endif
*/
#endif
eina_thread_name_set(eina_thread_self(), "Edbg-mon");
// sit forever processing commands or timeouts in the debug monitor // sit forever processing commands or timeouts in the debug monitor
// thread - this is separate to the rest of the app so it shouldn't // thread - this is separate to the rest of the app so it shouldn't
// impact the application specifically // impact the application specifically
@ -704,14 +707,16 @@ eina_debug_session_data_get(Eina_Debug_Session *session)
Eina_Bool Eina_Bool
eina_debug_init(void) eina_debug_init(void)
{ {
pthread_t self;
Eina_Thread self;//pthread_t self;
eina_threads_init(); eina_threads_init();
// For Windows support GetModuleFileName can be used // For Windows support GetModuleFileName can be used
// set up thread things // set up thread things
eina_spinlock_new(&_eina_debug_lock); eina_spinlock_new(&_eina_debug_lock);
eina_spinlock_new(&_eina_debug_thread_lock); eina_spinlock_new(&_eina_debug_thread_lock);
self = pthread_self();
self = eina_thread_self(); //self = pthread_self();
_eina_debug_thread_mainloop_set(&self); _eina_debug_thread_mainloop_set(&self);
_eina_debug_thread_add(&self); _eina_debug_thread_add(&self);
_eina_debug_cpu_init(); _eina_debug_cpu_init();
@ -735,7 +740,7 @@ Eina_Bool
eina_debug_shutdown(void) eina_debug_shutdown(void)
{ {
Eina_Debug_Session *session; Eina_Debug_Session *session;
pthread_t self = pthread_self(); Eina_Thread self = eina_thread_self(); //pthread_t self = pthread_self();
EINA_LIST_FREE(sessions, session) EINA_LIST_FREE(sessions, session)
eina_debug_session_terminate(session); eina_debug_session_terminate(session);

View File

@ -197,7 +197,9 @@ _signal_handler(int sig EINA_UNUSED,
siginfo_t *si EINA_UNUSED, void *foo EINA_UNUSED) siginfo_t *si EINA_UNUSED, void *foo EINA_UNUSED)
{ {
int i, slot = 0; int i, slot = 0;
pthread_t self = pthread_self();
//pthread_t self = pthread_self();
Eina_Thread self = eina_thread_self();
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_SCHED_GETCPU) && defined(__clockid_t_defined) #if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_SCHED_GETCPU) && defined(__clockid_t_defined)
clockid_t cid; clockid_t cid;
#endif #endif
@ -235,7 +237,9 @@ found:
_bt_cpu[slot] = sched_getcpu(); _bt_cpu[slot] = sched_getcpu();
# ifdef HAVE_PTHREAD_GETCPUCLOCKID # ifdef HAVE_PTHREAD_GETCPUCLOCKID
/* Try pthread_getcpuclockid() first */ /* Try pthread_getcpuclockid() first */
pthread_getcpuclockid(self, &cid); #ifndef _WIN32
pthread_getcpuclockid(self, &cid);
#endif
# elif defined(_POSIX_THREAD_CPUTIME) # elif defined(_POSIX_THREAD_CPUTIME)
/* Fallback to POSIX clock id. */ /* Fallback to POSIX clock id. */
cid = CLOCK_THREAD_CPUTIME_ID; cid = CLOCK_THREAD_CPUTIME_ID;
@ -292,7 +296,7 @@ _signal_shutdown(void)
} }
static void static void
_collect_bt(pthread_t pth) _collect_bt(Eina_Thread pth)// _collect_bt(pthread_t pth)
{ {
// this async signals the thread to switch to the deebug signal handler // this async signals the thread to switch to the deebug signal handler
// and collect a backtrace and other info from inside the thread // and collect a backtrace and other info from inside the thread

View File

@ -80,7 +80,10 @@ _sysmon(void *data EINA_UNUSED, Eina_Thread thr EINA_UNUSED)
for (i = 0; i < _eina_debug_thread_active_num; i++) for (i = 0; i < _eina_debug_thread_active_num; i++)
{ {
// get the correct clock id to use for the target thread // get the correct clock id to use for the target thread
pthread_getcpuclockid #ifndef _WIN32
pthread_getcpuclockid(self, &cid);
#endif
// pthread_getcpuclockid
(_eina_debug_thread_active[i].thread, &cid); (_eina_debug_thread_active[i].thread, &cid);
// get the clock cpu time accumulation for that threas // get the clock cpu time accumulation for that threas
clock_gettime(cid, &t); clock_gettime(cid, &t);
@ -126,7 +129,10 @@ _sysmon(void *data EINA_UNUSED, Eina_Thread thr EINA_UNUSED)
{ {
Eina_Thread thread = _eina_debug_thread_active[i].thread; Eina_Thread thread = _eina_debug_thread_active[i].thread;
// get the clock for the thread and its cpu time usage // get the clock for the thread and its cpu time usage
pthread_getcpuclockid(thread, &cid); #ifndef _WIN32
pthread_getcpuclockid(thread, &cid);
#endif
//pthread_getcpuclockid(thread, &cid);
clock_gettime(cid, &t); clock_gettime(cid, &t);
// calculate a long timestamp (64bits) // calculate a long timestamp (64bits)
tim1 = (_eina_debug_thread_active[i].clok.tv_sec * 1000000000LL) + tim1 = (_eina_debug_thread_active[i].clok.tv_sec * 1000000000LL) +

View File

@ -56,7 +56,8 @@ struct _Eina_Debug_Timer
static Eina_List *_timers = NULL; static Eina_List *_timers = NULL;
static Eina_Bool _thread_runs = EINA_FALSE; static Eina_Bool _thread_runs = EINA_FALSE;
static pthread_t _thread; //static pthread_t _thread;
static Eina_Thread _thread;
static int pipeToThread[2]; static int pipeToThread[2];
@ -95,17 +96,22 @@ _monitor(void *_data EINA_UNUSED)
ret = epoll_ctl(epfd, EPOLL_CTL_ADD, event.data.fd, &event); ret = epoll_ctl(epfd, EPOLL_CTL_ADD, event.data.fd, &event);
if (ret) perror("epoll_ctl/add"); if (ret) perror("epoll_ctl/add");
#ifdef EINA_HAVE_PTHREAD_SETNAME #ifdef EINA_HAVE_PTHREAD_SETNAME
/*
# ifndef __linux__ # ifndef __linux__
pthread_set_name_np pthread_set_name_np
# else # else
pthread_setname_np pthread_setname_np
# endif # endif
(pthread_self(), "Edbg-tim"); (pthread_self(), "Edbg-tim");
*/
#endif #endif
eina_thread_name_set(eina_thread_self(), "Edbg-tim");
while (1) while (1)
{ {
int timeout = -1; //in milliseconds int timeout = -1; //in milliseconds
pthread_testcancel(); #ifndef _WIN32
pthread_testcancel();
#endif
eina_spinlock_take(&_lock); eina_spinlock_take(&_lock);
if (_timers) if (_timers)
{ {
@ -115,7 +121,9 @@ _monitor(void *_data EINA_UNUSED)
eina_spinlock_release(&_lock); eina_spinlock_release(&_lock);
ret = epoll_wait(epfd, events, MAX_EVENTS, timeout); ret = epoll_wait(epfd, events, MAX_EVENTS, timeout);
pthread_testcancel(); #ifndef _WIN32
pthread_testcancel();
#endif
/* Some timer has been add/removed or we need to exit */ /* Some timer has been add/removed or we need to exit */
if (ret) if (ret)
@ -228,7 +236,8 @@ _eina_debug_timer_shutdown(void)
close(pipeToThread[0]); close(pipeToThread[0]);
close(pipeToThread[1]); close(pipeToThread[1]);
if (_thread_runs) if (_thread_runs)
pthread_cancel(_thread); eina_thread_cancel(_thread);//pthread_cancel(_thread);
_thread_runs = 0; _thread_runs = 0;
eina_spinlock_release(&_lock); eina_spinlock_release(&_lock);
eina_spinlock_free(&_lock); eina_spinlock_free(&_lock);

View File

@ -176,7 +176,8 @@ eina_evlog(const char *event, void *obj, double srctime, const char *detail)
item = (Eina_Evlog_Item *)strings; item = (Eina_Evlog_Item *)strings;
item->tim = SWAP_DBL(now); item->tim = SWAP_DBL(now);
item->srctim = SWAP_DBL(srctime); 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)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->obj = SWAP_64((unsigned long long)(uintptr_t)obj);
item->event_offset = SWAP_16(sizeof(Eina_Evlog_Item)); item->event_offset = SWAP_16(sizeof(Eina_Evlog_Item));
item->detail_offset = SWAP_16(detail_offset); item->detail_offset = SWAP_16(detail_offset);

View File

@ -65,6 +65,7 @@
#include "eina_freeq.h" #include "eina_freeq.h"
#include "eina_slstr.h" #include "eina_slstr.h"
#include "eina_vpath.h" #include "eina_vpath.h"
#include "eina_thread.h"
/*============================================================================* /*============================================================================*
* Local * * Local *
@ -98,7 +99,7 @@ EAPI Eina_Error EINA_ERROR_NOT_IMPLEMENTED = 0;
EAPI unsigned int eina_seed = 0; EAPI unsigned int eina_seed = 0;
#ifdef EFL_HAVE_THREADS #ifdef EFL_HAVE_THREADS
EAPI pthread_t _eina_main_loop; EAPI Eina_Thread _eina_main_loop; //EAPI pthread_t _eina_main_loop;
#endif #endif
#ifdef MT #ifdef MT

View File

@ -140,16 +140,17 @@ eina_thread_cancel(Eina_Thread t)
EAPI Eina_Bool EAPI Eina_Bool
eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable) eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable)
{ {
int state = cancellable ? PTHREAD_CANCEL_ENABLE : PTHREAD_CANCEL_DISABLE; int state = cancellable ? EINA_THREAD_CANCEL_ENABLE : EINA_THREAD_CANCEL_DISABLE;
int old = 0; int old = 0;
int r; int r;
#ifndef _WIN32 #ifndef _WIN32
/* enforce deferred in case users changed to asynchronous themselves */ /* enforce deferred in case users changed to asynchronous themselves */
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old);
pthread_setcanceltype(EINA_THREAD_CANCEL_DEFERRED, &old);
r = pthread_setcancelstate(state, &old); r = pthread_setcancelstate(state, &old);
if (was_cancellable && r == 0) if (was_cancellable && r == 0)
*was_cancellable = (old == PTHREAD_CANCEL_ENABLE); *was_cancellable = (old == EINA_THREAD_CANCEL_ENABLE);
return r == 0; return r == 0;
#else #else
if(!state){ if(!state){
@ -185,7 +186,9 @@ eina_thread_cancellable_run(Eina_Thread_Cancellable_Run_Cb cb, Eina_Free_Cb clea
return ret; return ret;
} }
EAPI const void *EINA_THREAD_JOIN_CANCELED = PTHREAD_CANCELED;
EAPI const void *EINA_THREAD_JOIN_CANCELED = EINA_THREAD_CANCELED;
Eina_Bool Eina_Bool
eina_thread_init(void) eina_thread_init(void)

View File

@ -351,6 +351,23 @@ struct _Eina_Thread_Call
}; };
#ifdef _WIN32
# define EINA_THREAD_CANCEL_ENABLE 0
# define EINA_THREAD_CANCEL_DISABLE 1
# define EINA_THREAD_CANCEL_DEFERRED 0
# define EINA_THREAD_CANCEL_ASYNCHRONOUS 1
# define EINA_THREAD_CANCELED ((void *) -1)
#else
# define EINA_THREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE
# define EINA_THREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE
# define EINA_THREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED
# define EINA_THREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS
# define EINA_THREAD_CANCELED PTHREAD_CANCELED
#endif
/** /**
* @} * @}
*/ */

View File

@ -49,10 +49,16 @@
#endif #endif
#endif #endif
typedef struct _Eina_win32_thread_attr{ typedef struct _Eina_win32_thread_func{
void *data; void *data;
void *(*func)(void *data); void *(*func)(void *data);
}Eina_win32_thread_func;
typedef struct _Eina_win32_thread_attr{
LPSECURITY_ATTRIBUTES lpThreadAttributes;
SIZE_T dwStackSize;
DWORD dwCreationFlags;
}Eina_win32_thread_attr; }Eina_win32_thread_attr;
@ -69,18 +75,9 @@ _eina_thread_join(Eina_Thread t)
DWORD WINAPI _eina_thread_func(void *params) DWORD WINAPI _eina_thread_func(void *params)
{ {
// // Code return (DWORD) ((Eina_win32_thread_func *)params)->func( (void*) ((Eina_win32_thread_func *)params)->data);
//Eina_Thread_Call *c = params;
//void *r;
//r = c->func((void*) c->data, eina_thread_self());
//return (DWORD) r;
//return (DWORD) _eina_internal_call(params);
return (DWORD) ((Eina_win32_thread_attr *)params)->func( (void*) ((Eina_win32_thread_attr *)params)->data);
} }
@ -102,19 +99,35 @@ 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)
{ {
Eina_Bool ret; Eina_Bool ret;
Eina_win32_thread_attr thread_attr;
SECURITY_ATTRIBUTES sec_attributes;
sec_attributes.nLength = sizeof(SECURITY_ATTRIBUTES);
sec_attributes.lpSecurityDescriptor = NULL;
sec_attributes.bInheritHandle = EINA_TRUE;
thread_attr.lpThreadAttributes = &sec_attributes;
thread_attr.dwStackSize = 4000;
thread_attr.dwCreationFlags = 0;
LPDWORD threadID; LPDWORD threadID;
Eina_win32_thread_attr *thread_attr = (Eina_win32_thread_attr*) malloc(sizeof(Eina_win32_thread_attr)); //Eina_win32_thread_func *thread_func = (Eina_win32_thread_func*) malloc(sizeof(Eina_win32_thread_func));
Eina_win32_thread_func thread_func;
Eina_Thread_Call *c = (Eina_Thread_Call*)(data); Eina_Thread_Call *c = (Eina_Thread_Call*)(data);
thread_attr->func = func; thread_func.func = func;
thread_attr->data = data; thread_func.data = data;
*t =(HANDLE) CreateThread(NULL, 0, &_eina_thread_func,thread_attr,0,threadID);
free(thread_attr); *t =(HANDLE) CreateThread(thread_attr.lpThreadAttributes,thread_attr.dwStackSize, &_eina_thread_func,&thread_func,thread_attr.dwCreationFlags,threadID);
//free(thread_func);
_eina_thread_set_priority(c->prio,t); //SetThreadPriority(*t, c->prio); _eina_thread_set_priority(c->prio,t); //SetThreadPriority(*t, c->prio);

View File

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

View File

@ -142,79 +142,25 @@ UNIMPLEMENTED inline int pthread_getschedparam(void* a, ...)
#warning pthread_getschedparam is not implemented. #warning pthread_getschedparam is not implemented.
return 0; return 0;
} }
/*
UNIMPLEMENTED inline int pthread_self() UNIMPLEMENTED inline int pthread_self()
{ {
#warning pthread_self is not implemented. #warning pthread_self is not implemented.
return 0; return 0;
} }*/
UNIMPLEMENTED inline int pthread_setschedparam(void* c, void* d, void* e) UNIMPLEMENTED inline int pthread_setschedparam(void* c, void* d, void* e)
{ {
#warning pthread_ is not implemented. #warning pthread_ is not implemented.
return 0; 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_cancel(void* a, ...) UNIMPLEMENTED inline int pthread_cancel(void* a, ...)
{ {
#warning pthread_cancel is not implemented. #warning pthread_cancel is not implemented.
return 0; return 0;
} }
*/
UNIMPLEMENTED inline int pthread_setcancelstate(void* a, ...) UNIMPLEMENTED inline int pthread_setcancelstate(void* a, ...)
{ {
#warning pthread_setcancelstate is not implemented. #warning pthread_setcancelstate is not implemented.
@ -244,7 +190,7 @@ UNIMPLEMENTED inline int pthread_attr_init(void* a, ...)
#warning pthread_attr_init is not implemented. #warning pthread_attr_init is not implemented.
return 0; return 0;
} }
/*
UNIMPLEMENTED inline int pthread_join(void* a, ...) UNIMPLEMENTED inline int pthread_join(void* a, ...)
{ {
#warning pthread_join is not implemented. #warning pthread_join is not implemented.
@ -262,7 +208,7 @@ UNIMPLEMENTED inline int pthread_equal(void* a, ...)
#warning pthread_equal is not implemented. #warning pthread_equal is not implemented.
return 0; return 0;
} }
*/
UNIMPLEMENTED inline int pthread_setcanceltype(void* a, ...) UNIMPLEMENTED inline int pthread_setcanceltype(void* a, ...)
{ {
#warning pthread_setcanceltype is not implemented. #warning pthread_setcanceltype is not implemented.