summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcarlos <caiosignor@gmail.com>2020-04-17 15:43:19 -0300
committerJoão Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com>2020-04-29 12:13:38 -0300
commit9577601d06c60144761cc2488eb60e46b8d71056 (patch)
tree423f46d7b67ded8a76ee061d26a3cea68bf41706
parent2a29c410aa6c1d23b69649b0f685e6dbcf7bf7c5 (diff)
eina_inline_thread_win32 code convention
-rw-r--r--src/lib/eina/eina_inline_thread_win32.x143
1 files changed, 75 insertions, 68 deletions
diff --git a/src/lib/eina/eina_inline_thread_win32.x b/src/lib/eina/eina_inline_thread_win32.x
index 820b35645b..8046dba0a8 100644
--- a/src/lib/eina/eina_inline_thread_win32.x
+++ b/src/lib/eina/eina_inline_thread_win32.x
@@ -18,44 +18,42 @@
18#ifndef EINA_INLINE_THREAD_WIN32_H_ 18#ifndef EINA_INLINE_THREAD_WIN32_H_
19#define EINA_INLINE_THREAD_WIN32_H_ 19#define EINA_INLINE_THREAD_WIN32_H_
20 20
21
22
23typedef struct _Eina_Win32_Thread_Func 21typedef struct _Eina_Win32_Thread_Func
24{ 22{
25 void *data; 23 void *data;
26 void *(*func)(void *data); 24 void *(*func)(void *data);
27
28} Eina_Win32_Thread_Func; 25} Eina_Win32_Thread_Func;
29 26
30typedef struct _Eina_Win32_Thread_Attr 27typedef struct _Eina_Win32_Thread_Attr
31{ 28{
32 LPSECURITY_ATTRIBUTES lpThreadAttributes; 29 LPSECURITY_ATTRIBUTES lpThreadAttributes;
33 SIZE_T dwStackSize; 30 SIZE_T dwStackSize;
34 DWORD dwCreationFlags; 31 DWORD dwCreationFlags;
35} Eina_Win32_Thread_Attr; 32} Eina_Win32_Thread_Attr;
36 33
37static inline void * 34static inline void *
38_eina_thread_join(Eina_Thread t) 35_eina_thread_join(Eina_Thread t)
39{ 36{
37 int ret = (int)WaitForSingleObject(t, INFINITE);
40 38
41 int ret = (int)WaitForSingleObject(t, INFINITE); 39 if (ret != 0) return ret;
42 40 return NULL;
43 if (ret != 0) return ret;
44 return NULL;
45} 41}
46 42
47DWORD WINAPI _eina_thread_func(void *params) 43DWORD WINAPI
44_eina_thread_func(void *params)
48{ 45{
49 return (DWORD)((Eina_Win32_Thread_Func *)params)->func((void *)((Eina_Win32_Thread_Func *)params)->data); 46 return (DWORD)((Eina_Win32_Thread_Func *)params)->func((void *)
47((Eina_Win32_Thread_Func *)params)->data);
50} 48}
51 49
52static inline void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t) 50static inline void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thread *t)
53{ 51{
54 52
55 int nPriority = THREAD_PRIORITY_NORMAL; 53 int nPriority = THREAD_PRIORITY_NORMAL;
56 54
57 switch (prio) 55 switch (prio)
58 { 56 {
59 case EINA_THREAD_URGENT: 57 case EINA_THREAD_URGENT:
60 nPriority = THREAD_PRIORITY_HIGHEST; 58 nPriority = THREAD_PRIORITY_HIGHEST;
61 break; 59 break;
@@ -68,101 +66,110 @@ static inline void _eina_thread_set_priority(Eina_Thread_Priority prio, Eina_Thr
68 case EINA_THREAD_IDLE: 66 case EINA_THREAD_IDLE:
69 nPriority = THREAD_PRIORITY_IDLE; 67 nPriority = THREAD_PRIORITY_IDLE;
70 break; 68 break;
71 } 69 }
72 70
73 SetThreadPriority((HANDLE)*t, nPriority); 71 SetThreadPriority((HANDLE)*t, nPriority);
74} 72}
75 73
76static inline Eina_Bool 74static inline Eina_Bool
77_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data) 75_eina_thread_create(Eina_Thread *t, int affinity, void *(*func)(void *data), void *data)
78{ 76{
79 Eina_Bool ret; 77 Eina_Bool ret;
80 Eina_Win32_Thread_Attr thread_attr; 78 Eina_Win32_Thread_Attr thread_attr;
81 79
82 SECURITY_ATTRIBUTES sec_attributes; 80 SECURITY_ATTRIBUTES sec_attributes;
83 81
84 sec_attributes.nLength = sizeof(SECURITY_ATTRIBUTES); 82 sec_attributes.nLength = sizeof(SECURITY_ATTRIBUTES);
85 sec_attributes.lpSecurityDescriptor = NULL; 83 sec_attributes.lpSecurityDescriptor = NULL;
86 sec_attributes.bInheritHandle = EINA_TRUE; 84 sec_attributes.bInheritHandle = EINA_TRUE;
87 85
88 thread_attr.lpThreadAttributes = &sec_attributes; 86 thread_attr.lpThreadAttributes = &sec_attributes;
89 87
90 thread_attr.dwStackSize = 4000; 88 thread_attr.dwStackSize = 4000;
91 thread_attr.dwCreationFlags = 0; 89 thread_attr.dwCreationFlags = 0;
92 90
93 LPDWORD threadID; 91 LPDWORD threadID;
94 92
95 Eina_Win32_Thread_Func thread_func; 93 Eina_Win32_Thread_Func thread_func;
96 Eina_Thread_Call *c = (Eina_Thread_Call *)(data); 94 Eina_Thread_Call *c = (Eina_Thread_Call *)(data);
97 95
98 thread_func.func = func; 96 thread_func.func = func;
99 thread_func.data = data; 97 thread_func.data = data;
100 98
101 *t = CreateThread(thread_attr.lpThreadAttributes, thread_attr.dwStackSize, &_eina_thread_func, &thread_func, thread_attr.dwCreationFlags, threadID); 99 *t = CreateThread(thread_attr.lpThreadAttributes, thread_attr.dwStackSize, &_eina_thread_func, &thread_func, thread_attr.dwCreationFlags, threadID);
102 100
103 _eina_thread_set_priority(c->prio, t); 101 _eina_thread_set_priority(c->prio, t);
104 102
105 ret = (*t != NULL) ? EINA_TRUE : EINA_FALSE; 103 ret = (*t != NULL) ? EINA_TRUE : EINA_FALSE;
106 104
107 if (affinity >= 0 && ret) SetThreadAffinityMask(*t, (DWORD_PTR *)&affinity); 105 if (affinity >= 0 && ret) SetThreadAffinityMask(*t, (DWORD_PTR *)&affinity);
108 106
109 return ret; 107 return ret;
110} 108}
111 109
112static inline Eina_Bool 110static inline Eina_Bool
113_eina_thread_equal(Eina_Thread t1, Eina_Thread t2) 111_eina_thread_equal(Eina_Thread t1, Eina_Thread t2)
114{ 112{
115 DWORD t1_thread_id = GetThreadId(t1); 113 DWORD t1_thread_id = GetThreadId(t1);
116 DWORD t2_thread_id = GetThreadId(t2); 114 DWORD t2_thread_id = GetThreadId(t2);
117 115
118 return (t1_thread_id == t2_thread_id) ? EINA_TRUE : EINA_FALSE; 116 return (t1_thread_id == t2_thread_id) ? EINA_TRUE : EINA_FALSE;
119} 117}
120 118
121static inline Eina_Thread 119static inline Eina_Thread
122_eina_thread_self(void) 120_eina_thread_self(void)
123{ 121{
124 return (Eina_Thread)GetCurrentThread(); 122 return GetCurrentThread();
125} 123}
126 124
127static inline Eina_Bool _eina_thread_name_set(Eina_Thread thread, char *buf) 125static inline Eina_Bool
126_eina_thread_name_set(Eina_Thread thread, char *buf)
128{ 127{
129 HRESULT res = SetThreadDescription((HANDLE)thread, (PCWSTR)buf); 128 HRESULT res = SetThreadDescription((HANDLE)thread, (PCWSTR)buf);
130 return HRESULT_CODE(res); 129 return HRESULT_CODE(res);
131} 130}
132 131
133static inline Eina_Bool _eina_thread_cancel(Eina_Thread thread) 132static inline Eina_Bool
133_eina_thread_cancel(Eina_Thread thread)
134{ 134{
135 LPDWORD lpExitCode; 135 LPDWORD lpExitCode;
136 Eina_Bool success = GetExitCodeThread((HANDLE)thread, lpExitCode); 136 Eina_Bool success = GetExitCodeThread((HANDLE)thread, lpExitCode);
137 ExitThread(*lpExitCode); 137 ExitThread(*lpExitCode);
138 return !success; 138 return !success;
139} 139}
140static inline UNIMPLEMENTED void _eina_thread_setcanceltype(int type, int *oldtype) 140
141static inline UNIMPLEMENTED
142void _eina_thread_setcanceltype(int type, int *oldtype)
141{ 143{
142 #warning _eina_thread_setcanceltype is not implemented. 144 #warning _eina_thread_setcanceltype is not implemented.
143} 145}
144static inline UNIMPLEMENTED int _eina_thread_setcancelstate(int type, int *oldtype) 146
147static inline UNIMPLEMENTED
148int _eina_thread_setcancelstate(int type, int *oldtype)
145{ 149{
146 #warning _eina_thread_setcancelstate is not implemented. 150 #warning _eina_thread_setcancelstate is not implemented.
147 return 0; 151 return 0;
148} 152}
149static inline UNIMPLEMENTED void _eina_thread_cancel_checkpoint(void) 153static inline UNIMPLEMENTED
154void _eina_thread_cancel_checkpoint(void)
150{ 155{
151 #warning _eina_thread_cancel_checkpoint is not implemented. 156 #warning _eina_thread_cancel_checkpoint is not implemented.
152} 157}
158
153static inline Eina_Bool 159static inline Eina_Bool
154_eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable) 160_eina_thread_cancellable_set(Eina_Bool cancellable, Eina_Bool *was_cancellable)
155{ 161{
156 int state = cancellable ? EINA_THREAD_CANCEL_ENABLE : EINA_THREAD_CANCEL_DISABLE; 162 int state = cancellable ? EINA_THREAD_CANCEL_ENABLE :
157 if (!state) 163EINA_THREAD_CANCEL_DISABLE;
158 { 164 if (!state)
159 *was_cancellable = EINA_TRUE; 165 {
160 return EINA_FALSE; 166 *was_cancellable = EINA_TRUE;
161 } 167 return EINA_FALSE;
162 else 168 }
163 { 169 else
164 *was_cancellable = EINA_TRUE; 170 {
165 return EINA_TRUE; 171 *was_cancellable = EINA_TRUE;
166 } 172 return EINA_TRUE;
173 }
167} 174}
168#endif \ No newline at end of file 175#endif \ No newline at end of file