74
74
SLinkedList * ring_2_io_push_list;
75
75
SLinkedList * ring_2_io_pull_list;
76
76
SLinkedList * ring_2_workers_list;
78
78
SLinkedList * teardown_handler_list;
80
80
SMutex * teardown_handler_mutex;
107
107
s_main_loop_new () {
108
SMainLoop * self = malloc (sizeof (SMainLoop));
108
SMainLoop * self = s_malloc (sizeof (SMainLoop));
110
110
for (sint i = 0; i < S_MAIN_LOOP_RING_LAST; i++){
111
111
for (sint j = 0; j < S_MAIN_LOOP_STATE_LAST; j++){
112
112
self->mutex[i][j] = s_mutex_new ();
116
116
self->teardown_handler_mutex = s_mutex_new ();
118
118
s_mutex_lock (self->mutex[S_MAIN_LOOP_RING_NONE][S_MAIN_LOOP_STATE_NONE]);
120
120
self->ref_count = 1;
121
121
self->ring_1_state = S_MAIN_LOOP_STATE_EVENT;
122
122
self->ring_2_state = S_MAIN_LOOP_STATE_EVENT;
123
123
self->is_run = FALSE;
125
self->ring_1_event_handler_list = s_linked_list_new (FREEFUNC (free));
126
self->ring_1_io_push_list = s_linked_list_new (FREEFUNC (free));
127
self->ring_1_io_pull_list = s_linked_list_new (FREEFUNC (free));
128
self->ring_1_workers_list = s_linked_list_new (FREEFUNC (free));
130
self->ring_2_event_handler_list = s_linked_list_new (FREEFUNC (free));
131
self->ring_2_io_push_list = s_linked_list_new (FREEFUNC (free));
132
self->ring_2_io_pull_list = s_linked_list_new (FREEFUNC (free));
133
self->ring_2_workers_list = s_linked_list_new (FREEFUNC (free));
125
self->ring_1_event_handler_list = s_linked_list_new (FREEFUNC (s_free));
126
self->ring_1_io_push_list = s_linked_list_new (FREEFUNC (s_free));
127
self->ring_1_io_pull_list = s_linked_list_new (FREEFUNC (s_free));
128
self->ring_1_workers_list = s_linked_list_new (FREEFUNC (s_free));
130
self->ring_2_event_handler_list = s_linked_list_new (FREEFUNC (s_free));
131
self->ring_2_io_push_list = s_linked_list_new (FREEFUNC (s_free));
132
self->ring_2_io_pull_list = s_linked_list_new (FREEFUNC (s_free));
133
self->ring_2_workers_list = s_linked_list_new (FREEFUNC (s_free));
135
135
self->teardown_handler_list = s_linked_list_new (FREEFUNC (_s_main_loop_teardown_handerer_obj_free));
261
SMainLoopItem * item = malloc (sizeof (SMainLoopItem));
261
SMainLoopItem * item = s_malloc (sizeof (SMainLoopItem));
262
262
item->state = S_MAIN_LOOP_STATE_EVENT;
263
263
item->callback = event_handler;
264
264
item->user_data = user_data;
295
SMainLoopItem * item = malloc (sizeof (SMainLoopItem));
295
SMainLoopItem * item = s_malloc (sizeof (SMainLoopItem));
296
296
item->state = S_MAIN_LOOP_STATE_IO_PUSH;
297
297
item->callback = push_callback;
298
298
item->user_data = user_data;
329
SMainLoopItem * item = malloc (sizeof (SMainLoopItem));
329
SMainLoopItem * item = s_malloc (sizeof (SMainLoopItem));
330
330
item->state = S_MAIN_LOOP_STATE_IO_PULL;
331
331
item->callback = pull_callback;
332
332
item->user_data = user_data;
355
355
s_mutex_lock (self->mutex[ring][S_MAIN_LOOP_STATE_DO_WORKERS]);
356
356
s_dbg_print ("locked");
358
SMainLoopItem * item = malloc (sizeof (SMainLoopItem));
358
SMainLoopItem * item = s_malloc (sizeof (SMainLoopItem));
359
359
item->state = S_MAIN_LOOP_STATE_DO_WORKERS;
360
360
item->callback = worker_callback;
361
361
item->user_data = user_data;
388
388
print_backtrace ();
391
SMainLoopTeardownHandler * item = malloc (sizeof (SMainLoopTeardownHandler));
391
SMainLoopTeardownHandler * item = s_malloc (sizeof (SMainLoopTeardownHandler));
393
393
item->teardown_handler = teardown_handler;
394
394
item->obj_self = self_obj;