static void rwsched_instance_free_int(rwsched_instance_t *instance) { // Validate input paraemters RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); //FIXME if (!g_atomic_int_dec_and_test(&instance->ref_cnt)) { return; } #if 1 RW_FREE_TYPE(instance->default_rwqueue, rwsched_dispatch_queue_t); RW_FREE_TYPE(instance->main_rwqueue, rwsched_dispatch_queue_t); long i; for (i=0; i<RWSCHED_DISPATCH_QUEUE_GLOBAL_CT; i++) { instance->global_rwqueue[i].rwq->header.libdispatch_object._dq = NULL; RW_FREE_TYPE(instance->global_rwqueue[i].rwq, rwsched_dispatch_queue_t); instance->global_rwqueue[i].rwq = NULL; } ck_pr_dec_32(&g_rwsched_instance_count); if (instance->rwlog_instance) { rwlog_close(instance->rwlog_instance, FALSE); } //NO-FREE RW_CF_TYPE_FREE(instance, rwsched_instance_ptr_t); #endif }
uint64_t rwmsg_toyfd_del(rwmsg_toytask_t *toy, uint64_t id) { rwsched_instance_ptr_t instance; rwmsg_toytask_t *toytask = toy; CFSocketContext cf_context = { 0, NULL, NULL, NULL, NULL }; rwsched_CFSocketRef cfsocket; struct rwmsg_toyfd_s *toyfd; rwsched_CFRunLoopSourceRef cfsource = NULL; // Validate input parameters RW_CF_TYPE_VALIDATE(toytask, rwtoytask_tasklet_ptr_t); // Get the rwsched instance from the toytask instance = toytask->toysched->rwsched_instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); // Lookup the cfsocket corresponding to id RW_ASSERT(id < toytask->rwsched_tasklet_info->cfsocket_array->len); cfsocket = g_array_index(toytask->rwsched_tasklet_info->cfsocket_array, rwsched_CFSocketRef, id); RW_ASSERT(cfsocket->index == id); rwsched_tasklet_CFSocketGetContext(toytask->rwsched_tasklet_info, cfsocket, &cf_context); // Free the cfsocket rwsched_tasklet_CFSocketInvalidate(toytask->rwsched_tasklet_info, cfsocket); rwsched_tasklet_CFSocketRelease(toytask->rwsched_tasklet_info, cfsocket); toyfd = cf_context.info; // Free the cfsource if ((cfsource = toyfd->read_context.source.cfsource)) { RW_CF_TYPE_VALIDATE(cfsource, rwsched_CFRunLoopSourceRef); //rwsched_tasklet_CFRunLoopRemoveSource(toytask->rwsched_tasklet_info, cfsource, instance->main_cfrunloop_mode); rwsched_tasklet_CFSocketReleaseRunLoopSource(toytask->rwsched_tasklet_info, cfsource); toyfd->read_context.source.cfsource = NULL; } else if ((cfsource = toyfd->write_context.source.cfsource)) { RW_CF_TYPE_VALIDATE(cfsource, rwsched_CFRunLoopSourceRef); //rwsched_tasklet_CFRunLoopRemoveSource(toytask->rwsched_tasklet_info, cfsource, instance->main_cfrunloop_mode); rwsched_tasklet_CFSocketReleaseRunLoopSource(toytask->rwsched_tasklet_info, cfsource); toyfd->write_context.source.cfsource = NULL; } // Free the toyfd RW_CF_TYPE_FREE(toyfd, rwmsg_toyfd_ptr_t); // Return the callback id return id; }
uint64_t rwmsg_toytimer_del(rwmsg_toytask_t *toy, uint64_t id) { rwsched_instance_ptr_t instance; rwmsg_toytask_t *toytask = toy; CFRunLoopTimerContext cf_context = { 0, NULL, NULL, NULL, NULL }; rwsched_CFRunLoopTimerRef cftimer; struct rwmsg_toytimer_s *toytimer; // Validate input parameters RW_CF_TYPE_VALIDATE(toytask, rwtoytask_tasklet_ptr_t); // Get the rwsched instance from the toytask instance = toytask->toysched->rwsched_instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); // Lookup the cftimer corresponding to id #if 1 RW_ASSERT(1 < toytask->rwsched_tasklet_info->cftimer_array->len); unsigned int i; for (i = 1 ; i < toytask->rwsched_tasklet_info->cftimer_array->len ; i++) { cftimer = g_array_index(toytask->rwsched_tasklet_info->cftimer_array, rwsched_CFRunLoopTimerRef, i); if (id == cftimer->index) { break; } } RW_ASSERT(i < toytask->rwsched_tasklet_info->cftimer_array->len); #else RW_ASSERT(id < toytask->rwsched_tasklet_info->cftimer_array->len); cftimer = g_array_index(toytask->rwsched_tasklet_info->cftimer_array, rwsched_CFRunLoopTimerRef, id); RW_ASSERT(cftimer->index == id); #endif rwsched_tasklet_CFRunLoopTimerGetContext(toytask->rwsched_tasklet_info, cftimer, &cf_context); // Invalidate the cftimer //rwsched_tasklet_CFRunLoopTimerInvalidate(toytask->rwsched_tasklet_info, cftimer); rwsched_tasklet_CFRunLoopTimerRelease(toytask->rwsched_tasklet_info, cftimer); // Free the toytimer toytimer = cf_context.info; RW_CF_TYPE_FREE(toytimer, rwmsg_toytimer_ptr_t); // Return the callback id return id; }
CF_EXPORT void rwsched_tasklet_CFRunLoopTimerRelease(rwsched_tasklet_ptr_t sched_tasklet, rwsched_CFRunLoopTimerRef rwsched_timer) { // Validate input paraemters RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); rwsched_instance_ptr_t instance = sched_tasklet->instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); rwsched_timer->release_called = 1; if (rwsched_timer->index) rwsched_tasklet_CFRunLoopTimerInvalidate(sched_tasklet, rwsched_timer); // Call the native CFRunLoop function CFRelease(rwsched_timer->cf_object); RW_CF_TYPE_FREE(rwsched_timer, rwsched_CFRunLoopTimerRef); rwsched_tasklet_unref(sched_tasklet); rwsched_instance_unref(instance); }
void rwmsg_toytask_destroy(rwmsg_toytask_t *toy) { rwsched_instance_ptr_t instance; rwsched_tasklet_ptr_t sched_tasklet; rwmsg_toytask_t *toytask = toy; // Validate input parameters RW_CF_TYPE_VALIDATE(toytask, rwtoytask_tasklet_ptr_t); // Get the rwsched instance from the toytask instance = toytask->toysched->rwsched_instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); // Get the rwsched sched_tasklet from the toytask sched_tasklet = toytask->rwsched_tasklet_info; RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); // Free the rwsched sched_tasklet rwsched_tasklet_free(sched_tasklet); // Free the task structure RW_CF_TYPE_FREE(toytask, rwtoytask_tasklet_ptr_t); }
static void rwsched_tasklet_free_int(rwsched_tasklet_t *sched_tasklet) { RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t); rwsched_instance_ptr_t instance = sched_tasklet->instance; RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t); if (!g_atomic_int_dec_and_test(&sched_tasklet->ref_cnt)) { return; } int i; for (i = 0 ; i < RWSCHED_MAX_SIGNALS; i++) { if (sched_tasklet->signal_dtor[i]) { sched_tasklet->signal_dtor[i](sched_tasklet->signal_dtor_ud[i]); } sched_tasklet->signal_dtor[i]= NULL; sched_tasklet->signal_dtor_ud[i]= NULL; } for (i = 1 ; i < instance->tasklet_array->len ; i++) { if (g_array_index(instance->tasklet_array, rwsched_tasklet_ptr_t, i) == sched_tasklet) { g_array_remove_index (instance->tasklet_array, i); break; } } rwsched_CFRunLoopTimerRef rw_timer; while ((rw_timer = g_array_index(sched_tasklet->cftimer_array, rwsched_CFRunLoopTimerRef, 1)) != NULL) { RW_CF_TYPE_VALIDATE(rw_timer, rwsched_CFRunLoopTimerRef); rwsched_tasklet_CFRunLoopTimerInvalidate(sched_tasklet, rw_timer); g_array_remove_index (sched_tasklet->cftimer_array, 1); } g_array_free(sched_tasklet->cftimer_array, TRUE); rwsched_CFSocketRef rw_socket; while ((rw_socket = g_array_index(sched_tasklet->cfsocket_array, rwsched_CFSocketRef, 1)) != NULL) { RW_CF_TYPE_VALIDATE(rw_socket, rwsched_CFSocketRef); rwsched_tasklet_CFSocketRelease(sched_tasklet, rw_socket); //g_array_remove_index (sched_tasklet->cfsocket_array, 1); } g_array_free(sched_tasklet->cfsocket_array, TRUE); rwsched_CFRunLoopSourceRef rw_source; while ((rw_source = g_array_index(sched_tasklet->cfsource_array, rwsched_CFRunLoopSourceRef, 1)) != NULL) { RW_CF_TYPE_VALIDATE(rw_source, rwsched_CFRunLoopSourceRef); rwsched_tasklet_CFSocketReleaseRunLoopSource(sched_tasklet, rw_source); g_array_remove_index (sched_tasklet->cfsource_array, 1); } g_array_free(sched_tasklet->cfsource_array, TRUE); rwsched_dispatch_what_ptr_t what; while ((what = g_array_index(sched_tasklet->dispatch_what_array, rwsched_dispatch_what_ptr_t, 1)) != NULL) { RW_FREE_TYPE(what, rwsched_dispatch_what_ptr_t); g_array_remove_index (sched_tasklet->dispatch_what_array, 1); } g_array_free(sched_tasklet->dispatch_what_array, TRUE); ck_pr_dec_32(&g_rwsched_tasklet_count); //NO-FREE RW_CF_TYPE_FREE(sched_tasklet, rwsched_tasklet_ptr_t); rwsched_instance_unref(instance); }