@@ -69,24 +69,35 @@ void LCUIWorker_PostTask(LCUI_Worker worker, LCUI_Task task)
69
69
LCUIMutex_Unlock (& worker -> mutex );
70
70
}
71
71
72
- LCUI_BOOL LCUIWorker_RunTask (LCUI_Worker worker )
72
+ LCUI_Task LCUIWorker_GetTask (LCUI_Worker worker )
73
73
{
74
74
LCUI_Task task ;
75
75
LinkedListNode * node ;
76
- LCUIMutex_Lock ( & worker -> mutex );
76
+
77
77
node = LinkedList_GetNode (& worker -> tasks , 0 );
78
- if (node ) {
79
- task = node -> data ;
80
- LinkedList_Unlink (& worker -> tasks , node );
81
- LCUIMutex_Unlock (& worker -> mutex );
82
- LCUITask_Run (task );
83
- LCUITask_Destroy (task );
84
- free (task );
85
- free (node );
86
- return TRUE;
78
+ if (!node ) {
79
+ return NULL ;
87
80
}
81
+ task = node -> data ;
82
+ LinkedList_Unlink (& worker -> tasks , node );
83
+ free (node );
84
+ return task ;
85
+ }
86
+
87
+ LCUI_BOOL LCUIWorker_RunTask (LCUI_Worker worker )
88
+ {
89
+ LCUI_Task task ;
90
+
91
+ LCUIMutex_Lock (& worker -> mutex );
92
+ task = LCUIWorker_GetTask (worker );
88
93
LCUIMutex_Unlock (& worker -> mutex );
89
- return FALSE;
94
+ if (!task ) {
95
+ return FALSE;
96
+ }
97
+ LCUITask_Run (task );
98
+ LCUITask_Destroy (task );
99
+ free (task );
100
+ return TRUE;
90
101
}
91
102
92
103
static void OnDeleteTask (void * arg )
@@ -106,10 +117,18 @@ static void LCUIWorker_ExecDestroy(LCUI_Worker worker)
106
117
107
118
static void LCUIWorker_Thread (void * arg )
108
119
{
120
+ LCUI_Task task ;
109
121
LCUI_Worker worker = arg ;
122
+
110
123
LCUIMutex_Lock (& worker -> mutex );
111
124
while (worker -> active ) {
112
- if (LCUIWorker_RunTask (worker )) {
125
+ task = LCUIWorker_GetTask (worker );
126
+ if (task ) {
127
+ LCUIMutex_Unlock (& worker -> mutex );
128
+ LCUITask_Run (task );
129
+ LCUITask_Destroy (task );
130
+ free (task );
131
+ LCUIMutex_Lock (& worker -> mutex );
113
132
continue ;
114
133
}
115
134
if (worker -> active ) {
0 commit comments