Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
static void setup_inotify_watcher(rwvx_instance_ptr_t rwvx)
{
  RW_ASSERT(rwvx);

  rwvx->pacemaker_inotify.fd = inotify_init();
  RW_ASSERT(rwvx->pacemaker_inotify.fd >= 0);
  int inotify_wd = inotify_add_watch(
      rwvx->pacemaker_inotify.fd,
      "/tmp/corosync",
      IN_MODIFY);
  RW_ASSERT(inotify_wd >= 0);

  CFSocketContext cf_context = { 0, rwvx, NULL, NULL, NULL };
  CFOptionFlags cf_callback_flags = kCFSocketReadCallBack;
  CFOptionFlags cf_option_flags = kCFSocketAutomaticallyReenableReadCallBack;

  // Release cfsource
  if (rwvx->pacemaker_inotify.cfsource) {
    RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsource, rwsched_CFRunLoopSourceRef);
    rwsched_tasklet_CFSocketReleaseRunLoopSource(
        rwvx->rwsched_tasklet,
        rwvx->pacemaker_inotify.cfsource);
  }
  // Release the cfsocket
  if (rwvx->pacemaker_inotify.cfsocket) {
    RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsocket, rwsched_CFSocketRef);

    // Invalidate the cfsocket
    rwsched_tasklet_CFSocketInvalidate(
        rwvx->rwsched_tasklet,
        rwvx->pacemaker_inotify.cfsocket);

    // Release the cfsocket
    rwsched_tasklet_CFSocketRelease(
        rwvx->rwsched_tasklet,
        rwvx->pacemaker_inotify.cfsocket);
  }

  rwvx->pacemaker_inotify.cfsocket = rwsched_tasklet_CFSocketCreateWithNative(
      rwvx->rwsched_tasklet,
      kCFAllocatorSystemDefault,
      rwvx->pacemaker_inotify.fd,
      cf_callback_flags,
      pacemaker_state_changed,
      &cf_context);
  RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsocket, rwsched_CFSocketRef);

  rwsched_tasklet_CFSocketSetSocketFlags(
      rwvx->rwsched_tasklet,
      rwvx->pacemaker_inotify.cfsocket,
      cf_option_flags);
  
  rwvx->pacemaker_inotify.cfsource = rwsched_tasklet_CFSocketCreateRunLoopSource(
      rwvx->rwsched_tasklet,
      kCFAllocatorSystemDefault,
      rwvx->pacemaker_inotify.cfsocket,
      0);
  RW_CF_TYPE_VALIDATE(rwvx->pacemaker_inotify.cfsource, rwsched_CFRunLoopSourceRef);
  
  rwsched_tasklet_CFRunLoopAddSource(
      rwvx->rwsched_tasklet,
      rwsched_tasklet_CFRunLoopGetCurrent(rwvx->rwsched_tasklet),
      rwvx->pacemaker_inotify.cfsource,
      rwvx->rwsched->main_cfrunloop_mode);
}
Ejemplo n.º 3
0
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);
}