Skip to content

Commit faeec84

Browse files
Fan LinFan Lin
authored andcommitted
Fixed busy waiting issue by using blocked g_main_context_iteration() call
1 parent 6652284 commit faeec84

File tree

1 file changed

+3
-13
lines changed
  • build/devices/linemb/xsProj-glib

1 file changed

+3
-13
lines changed

build/devices/linemb/xsProj-glib/main.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,13 @@ int main(int argc, char *argv[]) {
159159

160160
// Start event loop
161161
GMainContext *main_context = g_main_context_default();
162-
GMainLoop *main_loop = g_main_loop_new(main_context, FALSE);
162+
g_main_loop_new(main_context, FALSE);
163163

164164
#if mxInstrument
165165
g_timeout_add_seconds(1, on_instrumentation_timeout, (void *)the);
166166
#endif
167167

168168
// g_main_loop_run(main_loop);
169-
int testTime = 0;
170169
while (TRUE)
171170
{
172171
// Set timer: trigger SIGALRM on timeout
@@ -177,22 +176,13 @@ int main(int argc, char *argv[]) {
177176
timer.it_interval.tv_usec = 0;
178177
setitimer(ITIMER_REAL, &timer, NULL);
179178

180-
// Record time before event handling
181-
guint64 start = g_get_monotonic_time();
182-
// Process one event non-blocking
183-
gboolean processed = g_main_context_iteration(NULL, FALSE);
184-
// Record time after event handling
185-
guint64 end = g_get_monotonic_time();
179+
// Process one event blocking
180+
g_main_context_iteration(NULL, TRUE);
186181

187182
// Disable timer
188183
timer.it_value.tv_sec = 0;
189184
timer.it_value.tv_usec = 0;
190185
setitimer(ITIMER_REAL, &timer, NULL);
191-
192-
if (processed)
193-
{
194-
// printf("process time: %" G_GUINT64_FORMAT " us\n", end - start);
195-
}
196186
}
197187

198188
xsDeleteMachine(the);

0 commit comments

Comments
 (0)