/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/MainLoop.c

  • Committer: Gustav Hartvigsson
  • Date: 2016-02-01 14:29:35 UTC
  • mfrom: (121.1.4 simpletypesystem_gc)
  • Revision ID: gustav.hartvigsson@gmail.com-20160201142935-tz7ef63id2g3yfof
* Merged GC branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
  SLinkedList * ring_2_io_push_list;
75
75
  SLinkedList * ring_2_io_pull_list;
76
76
  SLinkedList * ring_2_workers_list;
77
 
  
 
77
 
78
78
  SLinkedList * teardown_handler_list;
79
 
  
 
79
 
80
80
  SMutex * teardown_handler_mutex;
81
81
};
82
82
 
105
105
 
106
106
SMainLoop *
107
107
s_main_loop_new () {
108
 
  SMainLoop * self = malloc (sizeof (SMainLoop));
 
108
  SMainLoop * self = s_malloc (sizeof (SMainLoop));
109
109
 
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 ();
113
113
    }
114
114
  }
115
 
  
 
115
 
116
116
  self->teardown_handler_mutex = s_mutex_new ();
117
 
  
 
117
 
118
118
  s_mutex_lock (self->mutex[S_MAIN_LOOP_RING_NONE][S_MAIN_LOOP_STATE_NONE]);
119
119
 
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;
124
 
  
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));
129
 
 
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));
 
124
 
 
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));
 
129
 
 
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));
134
134
 
135
135
  self->teardown_handler_list = s_linked_list_new (FREEFUNC (_s_main_loop_teardown_handerer_obj_free));
136
136
 
228
228
      s_mutex_free (self->mutex[i][j]);
229
229
    }
230
230
  }
231
 
  
 
231
 
232
232
  s_mutex_free (self->teardown_handler_mutex);
233
 
  
234
 
  free (self);
 
233
 
 
234
  s_free (self);
235
235
}
236
236
 
237
237
void
258
258
    return;
259
259
  }
260
260
 
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;
292
292
    return;
293
293
  }
294
294
 
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;
326
326
    return;
327
327
  }
328
328
 
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;
354
354
  //
355
355
  s_mutex_lock (self->mutex[ring][S_MAIN_LOOP_STATE_DO_WORKERS]);
356
356
  s_dbg_print ("locked");
357
 
  
358
 
  SMainLoopItem * item = malloc (sizeof (SMainLoopItem));
 
357
 
 
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 ();
389
389
  }
390
390
 
391
 
  SMainLoopTeardownHandler * item = malloc (sizeof (SMainLoopTeardownHandler));
 
391
  SMainLoopTeardownHandler * item = s_malloc (sizeof (SMainLoopTeardownHandler));
392
392
 
393
393
  item->teardown_handler = teardown_handler;
394
394
  item->obj_self = self_obj;
404
404
_s_main_loop_teardown_handerer_obj_free (SMainLoopTeardownHandler * self) {
405
405
  Callback callback = self->teardown_handler;
406
406
  callback (self->obj_self, self->user_data);
407
 
  free (self);
 
407
  s_free (self);
408
408
}
409
409
 
410
410
void