summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorcarlos <caiosignor@gmail.com>2020-03-24 17:02:27 -0300
committerJoão Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>2020-04-29 12:13:38 -0300
commit74dd7e2a4fdafae29077be51f37b5408e01162f0 (patch)
tree63593c9f118a9e360a98ed5c795ee39828ca088e /src/lib
parent268178b9d5e83a5face87275b3de4bbe94bcc230 (diff)
Apply suggestions of jptiz and lucas
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eina/eina_debug.c21
-rw-r--r--src/lib/eina/eina_debug_bt.c4
-rw-r--r--src/lib/eina/eina_debug_timer.c14
-rw-r--r--src/lib/eina/eina_main.c14
-rw-r--r--src/lib/eina/eina_sched.c142
-rw-r--r--src/lib/eina/eina_thread.c17
-rw-r--r--src/lib/eina/eina_thread_posix.c4
-rw-r--r--src/lib/eina/eina_thread_win32.c2
8 files changed, 92 insertions, 126 deletions
diff --git a/src/lib/eina/eina_debug.c b/src/lib/eina/eina_debug.c
index 6d077723bc..e4292ecbb2 100644
--- a/src/lib/eina/eina_debug.c
+++ b/src/lib/eina/eina_debug.c
@@ -556,17 +556,9 @@ _monitor(void *_data)
556 556
557 // set a name for this thread for system debugging 557 // set a name for this thread for system debugging
558#ifdef EINA_HAVE_PTHREAD_SETNAME 558#ifdef EINA_HAVE_PTHREAD_SETNAME
559/*
560# ifndef __linux__
561 pthread_set_name_np
562# else
563 pthread_setname_np
564# endif
565 (pthread_self(), "Edbg-mon");
566
567*/
568#endif
569 eina_thread_name_set(eina_thread_self(), "Edbg-mon"); 559 eina_thread_name_set(eina_thread_self(), "Edbg-mon");
560#endif
561
570 // sit forever processing commands or timeouts in the debug monitor 562 // sit forever processing commands or timeouts in the debug monitor
571 // thread - this is separate to the rest of the app so it shouldn't 563 // thread - this is separate to the rest of the app so it shouldn't
572 // impact the application specifically 564 // impact the application specifically
@@ -708,15 +700,14 @@ Eina_Bool
708eina_debug_init(void) 700eina_debug_init(void)
709{ 701{
710 702
711 Eina_Thread self;//pthread_t self; 703 Eina_Thread self;
712 704
713 eina_threads_init(); 705 eina_threads_init();
714 // For Windows support GetModuleFileName can be used 706 // For Windows support GetModuleFileName can be used
715 // set up thread things 707 // set up thread things
716 eina_spinlock_new(&_eina_debug_lock); 708 eina_spinlock_new(&_eina_debug_lock);
717 eina_spinlock_new(&_eina_debug_thread_lock); 709 eina_spinlock_new(&_eina_debug_thread_lock);
718 710 self = eina_thread_self();
719 self = eina_thread_self(); //self = pthread_self();
720 _eina_debug_thread_mainloop_set(&self); 711 _eina_debug_thread_mainloop_set(&self);
721 _eina_debug_thread_add(&self); 712 _eina_debug_thread_add(&self);
722 _eina_debug_cpu_init(); 713 _eina_debug_cpu_init();
@@ -740,7 +731,7 @@ Eina_Bool
740eina_debug_shutdown(void) 731eina_debug_shutdown(void)
741{ 732{
742 Eina_Debug_Session *session; 733 Eina_Debug_Session *session;
743 Eina_Thread self = eina_thread_self(); //pthread_t self = pthread_self(); 734 Eina_Thread self = eina_thread_self();
744 735
745 EINA_LIST_FREE(sessions, session) 736 EINA_LIST_FREE(sessions, session)
746 eina_debug_session_terminate(session); 737 eina_debug_session_terminate(session);
diff --git a/src/lib/eina/eina_debug_bt.c b/src/lib/eina/eina_debug_bt.c
index b30111d357..df96833c7d 100644
--- a/src/lib/eina/eina_debug_bt.c
+++ b/src/lib/eina/eina_debug_bt.c
@@ -197,8 +197,6 @@ _signal_handler(int sig EINA_UNUSED,
197 siginfo_t *si EINA_UNUSED, void *foo EINA_UNUSED) 197 siginfo_t *si EINA_UNUSED, void *foo EINA_UNUSED)
198{ 198{
199 int i, slot = 0; 199 int i, slot = 0;
200
201 //pthread_t self = pthread_self();
202 Eina_Thread self = eina_thread_self(); 200 Eina_Thread self = eina_thread_self();
203#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_SCHED_GETCPU) && defined(__clockid_t_defined) 201#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_SCHED_GETCPU) && defined(__clockid_t_defined)
204 clockid_t cid; 202 clockid_t cid;
@@ -296,7 +294,7 @@ _signal_shutdown(void)
296} 294}
297 295
298static void 296static void
299_collect_bt(Eina_Thread pth)// _collect_bt(pthread_t pth) 297_collect_bt(Eina_Thread pth)
300{ 298{
301 // this async signals the thread to switch to the deebug signal handler 299 // this async signals the thread to switch to the deebug signal handler
302 // and collect a backtrace and other info from inside the thread 300 // and collect a backtrace and other info from inside the thread
diff --git a/src/lib/eina/eina_debug_timer.c b/src/lib/eina/eina_debug_timer.c
index 4d97690b96..d4ff5e0c42 100644
--- a/src/lib/eina/eina_debug_timer.c
+++ b/src/lib/eina/eina_debug_timer.c
@@ -96,16 +96,10 @@ _monitor(void *_data EINA_UNUSED)
96 ret = epoll_ctl(epfd, EPOLL_CTL_ADD, event.data.fd, &event); 96 ret = epoll_ctl(epfd, EPOLL_CTL_ADD, event.data.fd, &event);
97 if (ret) perror("epoll_ctl/add"); 97 if (ret) perror("epoll_ctl/add");
98#ifdef EINA_HAVE_PTHREAD_SETNAME 98#ifdef EINA_HAVE_PTHREAD_SETNAME
99/* 99
100# ifndef __linux__ 100 eina_thread_name_set(eina_thread_self(), "Edbg-tim");
101 pthread_set_name_np
102# else
103 pthread_setname_np
104# endif
105 (pthread_self(), "Edbg-tim");
106*/
107#endif 101#endif
108 eina_thread_name_set(eina_thread_self(), "Edbg-tim"); 102
109 while (1) 103 while (1)
110 { 104 {
111 int timeout = -1; //in milliseconds 105 int timeout = -1; //in milliseconds
@@ -236,7 +230,7 @@ _eina_debug_timer_shutdown(void)
236 close(pipeToThread[0]); 230 close(pipeToThread[0]);
237 close(pipeToThread[1]); 231 close(pipeToThread[1]);
238 if (_thread_runs) 232 if (_thread_runs)
239 eina_thread_cancel(_thread);//pthread_cancel(_thread); 233 eina_thread_cancel(_thread);
240 234
241 _thread_runs = 0; 235 _thread_runs = 0;
242 eina_spinlock_release(&_lock); 236 eina_spinlock_release(&_lock);
diff --git a/src/lib/eina/eina_main.c b/src/lib/eina/eina_main.c
index 82a05daf95..4553436aa3 100644
--- a/src/lib/eina/eina_main.c
+++ b/src/lib/eina/eina_main.c
@@ -99,7 +99,7 @@ EAPI Eina_Error EINA_ERROR_NOT_IMPLEMENTED = 0;
99EAPI unsigned int eina_seed = 0; 99EAPI unsigned int eina_seed = 0;
100 100
101#ifdef EFL_HAVE_THREADS 101#ifdef EFL_HAVE_THREADS
102EAPI Eina_Thread _eina_main_loop; //EAPI pthread_t _eina_main_loop; 102EAPI Eina_Thread _eina_main_loop;
103#endif 103#endif
104 104
105#ifdef MT 105#ifdef MT
@@ -297,7 +297,7 @@ eina_init(void)
297#endif 297#endif
298 298
299#ifdef EFL_HAVE_THREADS 299#ifdef EFL_HAVE_THREADS
300 //_eina_main_loop = pthread_self(); 300
301 _eina_main_loop = eina_thread_self(); 301 _eina_main_loop = eina_thread_self();
302#endif 302#endif
303 303
@@ -391,7 +391,7 @@ eina_threads_init(void)
391 int ret; 391 int ret;
392 392
393#ifdef EINA_HAVE_DEBUG_THREADS 393#ifdef EINA_HAVE_DEBUG_THREADS
394 //assert(pthread_equal(_eina_main_loop, pthread_self())); 394
395 assert(eina_thread_equal(_eina_main_loop, eina_thread_self())); 395 assert(eina_thread_equal(_eina_main_loop, eina_thread_self()));
396#endif 396#endif
397 397
@@ -418,7 +418,7 @@ eina_threads_shutdown(void)
418 int ret; 418 int ret;
419 419
420#ifdef EINA_HAVE_DEBUG_THREADS 420#ifdef EINA_HAVE_DEBUG_THREADS
421 //assert(pthread_equal(_eina_main_loop, pthread_self())); 421
422 assert(eina_thread_equal(_eina_main_loop, eina_thread_self())); 422 assert(eina_thread_equal(_eina_main_loop, eina_thread_self()));
423 assert(_eina_main_thread_count > 0); 423 assert(_eina_main_thread_count > 0);
424#endif 424#endif
@@ -443,11 +443,11 @@ eina_main_loop_is(void)
443# ifdef __GNUC__ 443# ifdef __GNUC__
444 /* pthread_self() can't be optimized, it's a single asm "movl" */ 444 /* pthread_self() can't be optimized, it's a single asm "movl" */
445 if (__builtin_types_compatible_p(pthread_t, unsigned long int)) 445 if (__builtin_types_compatible_p(pthread_t, unsigned long int))
446 //return (pthread_self() == _eina_main_loop); 446
447 return (eina_thread_self() == _eina_main_loop); 447 return (eina_thread_self() == _eina_main_loop);
448 else 448 else
449# endif 449# endif
450 //if (pthread_equal(_eina_main_loop, pthread_self())) 450
451 if (eina_thread_equal(_eina_main_loop, eina_thread_self())) 451 if (eina_thread_equal(_eina_main_loop, eina_thread_self()))
452 return EINA_TRUE; 452 return EINA_TRUE;
453#endif 453#endif
@@ -459,7 +459,7 @@ EAPI void
459eina_main_loop_define(void) 459eina_main_loop_define(void)
460{ 460{
461#ifdef EFL_HAVE_THREADS 461#ifdef EFL_HAVE_THREADS
462 //_eina_main_loop = pthread_self(); 462
463 _eina_main_loop = eina_thread_self(); 463 _eina_main_loop = eina_thread_self();
464#endif 464#endif
465} 465}
diff --git a/src/lib/eina/eina_sched.c b/src/lib/eina/eina_sched.c
index 02bc1df7d8..891c02d260 100644
--- a/src/lib/eina/eina_sched.c
+++ b/src/lib/eina/eina_sched.c
@@ -17,15 +17,15 @@
17 */ 17 */
18 18
19#ifdef HAVE_CONFIG_H 19#ifdef HAVE_CONFIG_H
20# include "config.h" 20#include "config.h"
21#endif 21#endif
22#include "eina_thread.h" 22#include "eina_thread.h"
23//#include <pthread.h> 23
24#ifdef __linux__ 24#ifdef __linux__
25# include <sched.h> 25#include <sched.h>
26# include <sys/time.h> 26#include <sys/time.h>
27# include <sys/resource.h> 27#include <sys/resource.h>
28# include <errno.h> 28#include <errno.h>
29#endif 29#endif
30 30
31#include "eina_sched.h" 31#include "eina_sched.h"
@@ -34,97 +34,91 @@
34#define RTNICENESS 1 34#define RTNICENESS 1
35#define NICENESS 5 35#define NICENESS 5
36 36
37#ifndef _WIN32
38EAPI void 37EAPI void
39eina_sched_prio_drop(void) 38eina_sched_prio_drop(void)
40{ 39{
40#ifndef _WIN32
41 struct sched_param param; 41 struct sched_param param;
42 int pol, ret; 42 int pol, ret;
43 Eina_Thread pthread_id; 43 Eina_Thread pthread_id;
44 44
45 pthread_id = eina_thread_self(); //pthread_id = pthread_self(); 45 pthread_id = eina_thread_self();
46 ret = pthread_getschedparam(pthread_id, &pol, &param); 46 ret = pthread_getschedparam(pthread_id, &pol, &param);
47 if (ret) 47 if (ret)
48 { 48 {
49 EINA_LOG_ERR("Unable to query sched parameters"); 49 EINA_LOG_ERR("Unable to query sched parameters");
50 return; 50 return;
51 } 51 }
52 52
53 if (EINA_UNLIKELY(pol == SCHED_RR || pol == SCHED_FIFO)) 53 if (EINA_UNLIKELY(pol == SCHED_RR || pol == SCHED_FIFO))
54 { 54 {
55 param.sched_priority -= RTNICENESS; 55 param.sched_priority -= RTNICENESS;
56 56
57 /* We don't change the policy */ 57 /* We don't change the policy */
58 if (param.sched_priority < 1) 58 if (param.sched_priority < 1)
59 { 59 {
60 EINA_LOG_INFO("RT prio < 1, setting to 1 instead"); 60 EINA_LOG_INFO("RT prio < 1, setting to 1 instead");
61 param.sched_priority = 1; 61 param.sched_priority = 1;
62 } 62 }
63 63
64 pthread_setschedparam(pthread_id, pol, &param); 64 pthread_setschedparam(pthread_id, pol, &param);
65 } 65 }
66# ifdef __linux__ 66#ifdef __linux__
67 else 67 else
68 { 68 {
69 int prio; 69 int prio;
70 errno = 0; 70 errno = 0;
71 prio = getpriority(PRIO_PROCESS, 0); 71 prio = getpriority(PRIO_PROCESS, 0);
72 if (errno == 0) 72 if (errno == 0)
73 { 73 {
74 prio += NICENESS; 74 prio += NICENESS;
75 if (prio > 19) 75 if (prio > 19)
76 { 76 {
77 EINA_LOG_INFO("Max niceness reached; keeping max (19)"); 77 EINA_LOG_INFO("Max niceness reached; keeping max (19)");
78 prio = 19; 78 prio = 19;
79 } 79 }
80 80
81 setpriority(PRIO_PROCESS, 0, prio); 81 setpriority(PRIO_PROCESS, 0, prio);
82 } 82 }
83 } 83 }
84# endif 84#endif
85}
86#else 85#else
87EAPI void
88eina_sched_prio_drop(void)
89{
90 Eina_Thread pthread_id; 86 Eina_Thread pthread_id;
91 int sched_priority; 87 int sched_priority;
92 88
93 pthread_id = eina_thread_self(); //pthread_id = pthread_self(); 89 pthread_id = eina_thread_self();
94 90
95 sched_priority = GetThreadPriority((HANDLE)pthread_id); 91 sched_priority = GetThreadPriority((HANDLE)pthread_id);
96 92
97 if(EINA_UNLIKELY(sched_priority == THREAD_PRIORITY_TIME_CRITICAL)) 93 if (EINA_UNLIKELY(sched_priority == THREAD_PRIORITY_TIME_CRITICAL))
98 { 94 {
99 sched_priority -= RTNICENESS; 95 sched_priority -= RTNICENESS;
100 96
101 /* We don't change the policy */ 97 /* We don't change the policy */
102 if (sched_priority < 1) 98 if (sched_priority < 1)
103 {
104 EINA_LOG_INFO("RT prio < 1, setting to 1 instead");
105 sched_priority = 1;
106 }
107 if(!SetThreadPriority((HANDLE)pthread_id, sched_priority))
108 {
109 EINA_LOG_ERR("Unable to query sched parameters");
110 }
111 }
112 else
113 { 99 {
114 sched_priority += NICENESS; 100 EINA_LOG_INFO("RT prio < 1, setting to 1 instead");
115 101 sched_priority = 1;
116 /* We don't change the policy */
117 if (sched_priority > THREAD_PRIORITY_TIME_CRITICAL)
118 {
119 EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)");
120 sched_priority = THREAD_PRIORITY_TIME_CRITICAL;
121 }
122 if(!SetThreadPriority((HANDLE)pthread_id, sched_priority))
123 {
124 EINA_LOG_ERR("Unable to query sched parameters");
125 }
126 } 102 }
103 if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
104 {
105 EINA_LOG_ERR("Unable to query sched parameters");
106 }
107 }
108 else
109 {
110 sched_priority += NICENESS;
127 111
128 112 /* We don't change the policy */
113 if (sched_priority > THREAD_PRIORITY_TIME_CRITICAL)
114 {
115 EINA_LOG_INFO("Max niceness reached; keeping max (THREAD_PRIORITY_TIME_CRITICAL)");
116 sched_priority = THREAD_PRIORITY_TIME_CRITICAL;
117 }
118 if (!SetThreadPriority((HANDLE)pthread_id, sched_priority))
119 {
120 EINA_LOG_ERR("Unable to query sched parameters");
121 }
122 }
123#endif
129} 124}
130#endif \ No newline at end of file
diff --git a/src/lib/eina/eina_thread.c b/src/lib/eina/eina_thread.c
index 8e83cd798e..b4aeb287b8 100644
--- a/src/lib/eina/eina_thread.c
+++ b/src/lib/eina/eina_thread.c
@@ -33,14 +33,7 @@
33 33
34#include "eina_debug_private.h" 34#include "eina_debug_private.h"
35 35
36/*
37#ifndef _WIN32
38 36
39# include "eina_thread_posix.h"
40#else
41# include "eina_thread_win32.h"
42#endif
43*/
44#include <errno.h> 37#include <errno.h>
45#ifndef _WIN32 38#ifndef _WIN32
46# include <signal.h> 39# include <signal.h>
@@ -113,8 +106,7 @@ eina_thread_name_set(Eina_Thread t, const char *name)
113 } 106 }
114 else buf[0] = 0; 107 else buf[0] = 0;
115#ifndef __linux__ 108#ifndef __linux__
116 //pthread_set_name_np((pthread_t)t, buf); 109
117 //return EINA_TRUE;
118 return _eina_thread_set_name_win32(t, buf); 110 return _eina_thread_set_name_win32(t, buf);
119#else 111#else
120 if (pthread_setname_np((pthread_t)t, buf) == 0) return EINA_TRUE; 112 if (pthread_setname_np((pthread_t)t, buf) == 0) return EINA_TRUE;
@@ -130,11 +122,7 @@ EAPI Eina_Bool
130eina_thread_cancel(Eina_Thread t) 122eina_thread_cancel(Eina_Thread t)
131{ 123{
132 if (!t) return EINA_FALSE; 124 if (!t) return EINA_FALSE;
133 #ifndef _WIN32
134 return pthread_cancel((pthread_t)t) == 0;
135 #else
136 return _eina_thread_cancel(t); 125 return _eina_thread_cancel(t);
137 #endif
138} 126}
139 127
140EAPI Eina_Bool 128EAPI Eina_Bool
@@ -227,9 +215,6 @@ static void *_eina_internal_call(void *context)
227 self = pthread_self(); 215 self = pthread_self();
228 #endif 216 #endif
229 217
230 //self = GetCurrentThreadId();
231 //self = GetCurrentThread();
232
233 _eina_debug_thread_add(&self); 218 _eina_debug_thread_add(&self);
234 EINA_THREAD_CLEANUP_PUSH(_eina_debug_thread_del, &self); 219 EINA_THREAD_CLEANUP_PUSH(_eina_debug_thread_del, &self);
235 r = c->func((void*) c->data, eina_thread_self()); 220 r = c->func((void*) c->data, eina_thread_self());
diff --git a/src/lib/eina/eina_thread_posix.c b/src/lib/eina/eina_thread_posix.c
index de71f398af..e4a3f61cda 100644
--- a/src/lib/eina/eina_thread_posix.c
+++ b/src/lib/eina/eina_thread_posix.c
@@ -114,6 +114,10 @@ _eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
114 return pthread_equal((pthread_t)t1, (pthread_t)t2); 114 return pthread_equal((pthread_t)t1, (pthread_t)t2);
115} 115}
116 116
117Eina_Bool _eina_thread_cancel(Eina_Thread thread){
118 return pthread_cancel((pthread_t)thread) == 0;
119}
120
117inline Eina_Thread 121inline Eina_Thread
118_eina_thread_self(void) 122_eina_thread_self(void)
119{ 123{
diff --git a/src/lib/eina/eina_thread_win32.c b/src/lib/eina/eina_thread_win32.c
index d4da7bb223..3e78f2fd8d 100644
--- a/src/lib/eina/eina_thread_win32.c
+++ b/src/lib/eina/eina_thread_win32.c
@@ -1,5 +1,5 @@
1/* EINA - EFL data type library 1/* EINA - EFL data type library
2 * Copyright (C) 2012 Cedric Bail 2 * Copyright (C) 2020 Carlos Ré Signor
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public 5 * modify it under the terms of the GNU Lesser General Public