Exemple #1
0
static RwTaskletPluginInstanceHandle *
rwlogd__component__instance_alloc(RwTaskletPluginComponent *self,
					RwTaskletPluginComponentHandle *h_component,
					struct rwtasklet_info_s * rwtasklet_info,
					RwTaskletPlugin_RWExecURL* instance_url)
{
  rwlogd_component_ptr_t component;
  rwlogd_instance_ptr_t instance;
  RwTaskletPluginInstanceHandle *h_instance;
  gpointer handle;

  // Validate input parameters
  component = (rwlogd_component_ptr_t) h_component->priv;
  RW_CF_TYPE_VALIDATE(component, rwlogd_component_ptr_t);

  // Allocate a new rwlogd_instance structure
  instance = RW_CF_TYPE_MALLOC0(sizeof(*instance), rwlogd_instance_ptr_t);
  RW_CF_TYPE_VALIDATE(instance, rwlogd_instance_ptr_t);

  // Save the rwtasklet_info structure
  instance->rwtasklet_info = rwtasklet_info;

  // Allocate a gobject for the handle
  handle = g_object_new(RW_TASKLET_PLUGIN_TYPE_INSTANCE_HANDLE, 0);
  h_instance = RW_TASKLET_PLUGIN_INSTANCE_HANDLE(handle);
  h_instance->priv = (gpointer) instance;

  // Return the handle to the rwtasklet instance
  return h_instance;
}
Exemple #2
0
CF_EXPORT void
rwsched_tasklet_CFRunLoopTimerInvalidate(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);
    RW_CF_TYPE_VALIDATE(rwsched_timer, rwsched_CFRunLoopTimerRef);

    rwsched_timer->invalidate_called = 1;
#if 1
    int i;
    for (i = 1 ; i < sched_tasklet->cftimer_array->len ; i++) {
        if (g_array_index(sched_tasklet->cftimer_array, rwsched_CFRunLoopTimerRef, i) == rwsched_timer) {
            g_array_remove_index (sched_tasklet->cftimer_array, i);
            break;
        }
    }
#else
    RW_ASSERT(rwsched_timer->index != 0);
    RW_ASSERT(sched_tasklet->cftimer_array->len > rwsched_timer->index);
    g_array_index(sched_tasklet->cftimer_array, rwsched_CFRunLoopTimerRef, rwsched_timer->index) = NULL;
    rwsched_timer->index = 0;
#endif
    // Call the native CFRunLoop function
    CFRunLoopTimerInvalidate(rwsched_timer->cf_object);
}
Exemple #3
0
void
rwsched_dispatch_set_target_queue(rwsched_tasklet_ptr_t sched_tasklet,
                                  rwsched_dispatch_object_t object,
                                  rwsched_dispatch_queue_t queue)
{
#else
void
rwsched_dispatch_set_target_queue(rwsched_tasklet_ptr_t sched_tasklet,
                                  void *obj,
                                  rwsched_dispatch_queue_t queue)
{
  rwsched_dispatch_object_t object = (rwsched_dispatch_object_t) obj;
#endif
  // 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);
  RW_ASSERT_TYPE(queue, rwsched_dispatch_queue_t);

  // If libdispatch is enabled for the entire instance, then call the libdispatch routine
  if (instance->use_libdispatch_only) {
    dispatch_set_target_queue(object._object->header.libdispatch_object._do,
			      queue->header.libdispatch_object._dq);
    return;
  }

  // Not yet implemented
  RW_CRASH();
}
Exemple #4
0
rwmsg_toytask_t *
rwmsg_toytask_create(rwmsg_toysched_t *ts)
{
  rwmsg_toysched_t *toysched = ts;
  rwsched_instance_ptr_t instance;
  rwmsg_toytask_t *toytask;
  static int toytask_id;
  
  // Get the rwsched instance from toysched
  instance = toysched->rwsched_instance;
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);

  // Allocate memory for the new toytask
  toytask = RW_CF_TYPE_MALLOC0(sizeof(*toytask), rwtoytask_tasklet_ptr_t);
  RW_CF_TYPE_VALIDATE(toytask, rwtoytask_tasklet_ptr_t);
  toytask->rwsched_tasklet_info = rwsched_tasklet_new(instance);

  // Save the toysched instance struture within the toytask
  toytask->toysched = ts;

  // Get the next toytask id for this toytask
  toytask_id++;

  // Return the toytask pointer
  return toytask;
}
Exemple #5
0
rwsched_dispatch_queue_t
rwsched_dispatch_queue_create(rwsched_tasklet_ptr_t sched_tasklet,
                              const char *label,
                              dispatch_queue_attr_t attr)
{
  struct rwsched_dispatch_queue_s *queue;

  // 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);

  // Allocate memory for the dispatch queue
  queue = (rwsched_dispatch_queue_t) RW_MALLOC0_TYPE(sizeof(*queue), rwsched_dispatch_queue_t);
  RW_ASSERT_TYPE(queue, rwsched_dispatch_queue_t);

  // If libdispatch is enabled for the entire instance, then call the libdispatch routine
  if (instance->use_libdispatch_only) {
    queue->header.libdispatch_object._dq = dispatch_queue_create(label, attr);
    RW_ASSERT(queue->header.libdispatch_object._dq);

    rwsched_tasklet_ref(sched_tasklet);
    ck_pr_inc_32(&sched_tasklet->counters.queues);

    return queue;
  }

  // Not yet implemented
  RW_CRASH();
  return NULL;
}
void
rwsched_cfrunloop_relocate_timers_to_main_mode(rwsched_tasklet_ptr_t sched_tasklet)
{
  //unsigned int i, j;
  unsigned int i;
  rwsched_CFRunLoopTimerRef rwsched_object;
  rwsched_instance_ptr_t instance;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t);

  for (i = 1 ; i < sched_tasklet->cftimer_array->len ; i++) {
    if ((rwsched_object = g_array_index(sched_tasklet->cftimer_array, rwsched_CFRunLoopTimerRef, i)) != NULL) {
      RW_CF_TYPE_VALIDATE(rwsched_object, rwsched_CFRunLoopTimerRef);
      instance = rwsched_object->callback_context.instance;
      RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);
      //CFRunLoopRemoveTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->deferred_cfrunloop_mode);
      if (rwsched_object->onetime_timer_fired_while_blocked) {
        //(rwsched_object->cf_callout)(rwsched_object, rwsched_object->cf_context.info);
        RW_ASSERT(rwsched_object->onetime_timer);
        rwsched_object->cf_object = CFRunLoopTimerCreate(rwsched_object->ott.allocator,
                                                         CFAbsoluteTimeGetCurrent()+0.000001,
                                                         0,
                                                         rwsched_object->ott.flags,
                                                         rwsched_object->ott.order,
                                                         rwsched_cftimer_callout_intercept,
                                                         &rwsched_object->tmp_context);
        rwsched_object->onetime_timer_fired_while_blocked = 0;
      }
      CFRunLoopAddTimer(rwsched_tasklet_CFRunLoopGetCurrent(sched_tasklet), rwsched_object->cf_object, instance->main_cfrunloop_mode);
    }
  }
}
Exemple #7
0
static void
rwmsgbroker__component__instance_start(RwTaskletPluginComponent *self,
					RwTaskletPluginComponentHandle *h_component,
					RwTaskletPluginInstanceHandle *h_instance)
{
  rwmsgbroker_component_ptr_t component;
  rwmsgbroker_instance_ptr_t instance;
  rwcal_module_ptr_t rwcal;

  // Validate input parameters
  component = (rwmsgbroker_component_ptr_t) h_component->priv;
  RW_CF_TYPE_VALIDATE(component, rwmsgbroker_component_ptr_t);
  instance = (rwmsgbroker_instance_ptr_t) h_instance->priv;
  RW_CF_TYPE_VALIDATE(instance, rwmsgbroker_instance_ptr_t);

  // The instance is started so print a debug message
  RWTRACE_INFO(instance->rwtasklet_info->rwtrace_instance,
	             RWTRACE_CATEGORY_RWTASKLET,
	             "RW.MsgBroker -- Tasklet [%d] is started on VM [%d]!",
               instance->rwtasklet_info->identity.rwtasklet_instance_id, //0);
               instance->rwtasklet_info->rwvcs->identity.rwvm_instance_id);

  rwvcs_instance_ptr_t rwvcs = instance->rwtasklet_info->rwvcs;
  RW_ASSERT(rwvcs);
  int rwvm_instance_id = rwvcs->identity.rwvm_instance_id;
  RW_ASSERT(rwvcs->pb_rwmanifest
            && rwvcs->pb_rwmanifest->init_phase
            && rwvcs->pb_rwmanifest->init_phase->settings
            && rwvcs->pb_rwmanifest->init_phase->settings->rwmsg);
  int multi_broker = (rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker &&
                      rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker->has_enable &&
                      rwvcs->pb_rwmanifest->init_phase->settings->rwmsg->multi_broker->enable);

  char *ext_ip_address = instance->rwtasklet_info->rwvcs->identity.vm_ip_address;
  RWTRACE_INFO(instance->rwtasklet_info->rwtrace_instance,
               RWTRACE_CATEGORY_RWTASKLET,
               "RW.MsgBroker -- Tasklet [%d] is started on VM [%d] ip-addr [%s] multi_broker [%d]!\n",
               instance->rwtasklet_info->identity.rwtasklet_instance_id,
               rwvm_instance_id, ext_ip_address,
               multi_broker);

  int sid = 1;
  rwcal = ((rwvx_instance_t*)(instance->rwtasklet_info->rwvx))->rwcal_module;
  instance->broker = rwmsg_broker_create(sid,
                                         (multi_broker?rwvm_instance_id:0),
                                         ext_ip_address,
                                         instance->rwtasklet_info->rwsched_instance,
                                         instance->rwtasklet_info->rwsched_tasklet_info,
                                         rwcal,
                                         rwtasklet_info_is_collapse_thread(instance->rwtasklet_info), /* mainq */
                                         instance->rwtasklet_info->rwmsg_endpoint,
                                         instance->rwtasklet_info);

  RW_ASSERT(instance->broker);

  rw_status_t rs;
  rs = rwmsg_broker_dts_registration (instance);
  RW_ASSERT(rs == RW_STATUS_SUCCESS);
}
Exemple #8
0
void
rwdtsperf_instance_free(rwdtsperf_component_ptr_t component,
			                  rwdtsperf_instance_ptr_t instance)
{
  // Validate input parameters
  RW_CF_TYPE_VALIDATE(component, rwdtsperf_component_ptr_t);
  RW_CF_TYPE_VALIDATE(instance, rwdtsperf_instance_ptr_t);
}
Exemple #9
0
rwsched_tasklet_t *
rwsched_tasklet_new(rwsched_instance_t *instance)
{
  rwsched_tasklet_ptr_t sched_tasklet;
  //int i;

  // Validate input paraemters
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);

  // Allocate memory for the new sched_tasklet sched_tasklet structure and track it
  sched_tasklet = RW_CF_TYPE_MALLOC0(sizeof(*sched_tasklet), rwsched_tasklet_ptr_t);
  RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t);

  rwsched_instance_ref(instance);
  sched_tasklet->instance = instance;
  sched_tasklet->rwresource_track_handle = RW_RESOURCE_TRACK_CREATE_CONTEXT("Tasklet Context");

  // Look for an unused entry in tasklet_array (start the indexes at 1 for now)
  int i; for (i = 1 ; i < instance->tasklet_array->len ; i++) {
    if (g_array_index(instance->tasklet_array, rwsched_tasklet_ptr_t, i) == NULL) {
      g_array_index(instance->tasklet_array, rwsched_tasklet_ptr_t, i) = sched_tasklet;
      break;
    }
  }
  if (i >= instance->tasklet_array->len) {
    // Insert a new element at the end of the array
    g_array_append_val(instance->tasklet_array, sched_tasklet);
  }


#ifdef _CF_
  // Allocate an array of cftimer pointers and track it
  rwsched_CFRunLoopTimerRef cftimer = NULL;
  sched_tasklet->cftimer_array = g_array_sized_new(TRUE, TRUE, sizeof(void *), 256);
  g_array_append_val(sched_tasklet->cftimer_array, cftimer);

  // Allocate an array of cfsocket pointers and track it
  rwsched_CFSocketRef cfsocket = NULL;
  sched_tasklet->cfsocket_array = g_array_sized_new(TRUE, TRUE, sizeof(void *), 256);
  g_array_append_val(sched_tasklet->cfsocket_array, cfsocket);

  // Allocate an array of cfsocket pointers and track it
  rwsched_CFRunLoopSourceRef cfsource = NULL;
  sched_tasklet->cfsource_array = g_array_sized_new(TRUE, TRUE, sizeof(void *), 256);
  g_array_append_val(sched_tasklet->cfsource_array, cfsource);

  // Allocate an array of dispatch_what pointers and track it
  rwsched_dispatch_what_ptr_t dispatch_what = NULL;
  sched_tasklet->dispatch_what_array = g_array_sized_new(TRUE, TRUE, sizeof(void *), 256);
  g_array_append_val(sched_tasklet->dispatch_what_array, dispatch_what);
#endif

  rwsched_tasklet_ref(sched_tasklet);
  ck_pr_inc_32(&g_rwsched_tasklet_count);

  // Return the allocated sched_tasklet sched_tasklet structure
  return sched_tasklet;
}
Exemple #10
0
void
rwdtsperf_instance_start(rwdtsperf_component_ptr_t component,
			    rwdtsperf_instance_ptr_t instance)
{
  // Validate input parameters
  RW_CF_TYPE_VALIDATE(component, rwdtsperf_component_ptr_t);
  RW_CF_TYPE_VALIDATE(instance, rwdtsperf_instance_ptr_t);

  rwdtsperf_register_dts_callbacks (instance);
}
Exemple #11
0
rwsched_dispatch_queue_t
rwsched_dispatch_get_default_queue(rwsched_tasklet_ptr_t sched_tasklet)
{
  // 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);

  RW_ASSERT_TYPE(instance->default_rwqueue, rwsched_dispatch_queue_t);
  return instance->default_rwqueue;
}
Exemple #12
0
CF_EXPORT Boolean
rwsched_tasklet_CFRunLoopTimerIsValid(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);

    // Call the native CFRunLoop function
    return CFRunLoopTimerIsValid(rwsched_timer->cf_object);
}
Exemple #13
0
CF_EXPORT void
rwsched_tasklet_CFRunLoopSourceInvalidate(rwsched_tasklet_ptr_t sched_tasklet,
        rwsched_CFRunLoopSourceRef source)
{
    // 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);
    RW_CF_TYPE_VALIDATE(source, rwsched_CFRunLoopSourceRef);

    // Call the native CFRunLoop function
    CFRunLoopSourceInvalidate(source->cf_object);
}
Exemple #14
0
uint64_t
rwmsg_toyRtimer_add(rwmsg_toytask_t *toy, int ms, toytimer_cb_t cb, void *ud)
{
  rwsched_instance_ptr_t instance;
  rwmsg_toytask_t *toytask = toy;
  struct rwmsg_toytimer_s *toytimer;
  //uint64_t nsec;

  // 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);

  // Allocate a toytimer container type and track it
  toytimer = RW_CF_TYPE_MALLOC0(sizeof(*toytimer), rwmsg_toytimer_ptr_t);
  RW_CF_TYPE_VALIDATE(toytimer, rwmsg_toytimer_ptr_t);
  
  // Create a CF runloop timer
  CFRunLoopTimerContext cf_context = { 0, NULL, NULL, NULL, NULL };
  double timer_interval = ms * .001;
  rwsched_CFRunLoopRef runloop = rwsched_tasklet_CFRunLoopGetCurrent(toytask->rwsched_tasklet_info);
  rwsched_CFRunLoopTimerRef cftimer;

  // Create a CFRunLoopTimer as a runloop source for the toytimer
  cf_context.info = toytimer;
  cftimer = rwsched_tasklet_CFRunLoopTimerCreate(toytask->rwsched_tasklet_info,
					 kCFAllocatorDefault,
					 CFAbsoluteTimeGetCurrent() + timer_interval,
					 timer_interval,
					 0,
					 0,
					 rwmsg_toysched_Rtimer_callback,
					 &cf_context);
  RW_CF_TYPE_VALIDATE(cftimer, rwsched_CFRunLoopTimerRef);
  rwsched_tasklet_CFRunLoopAddTimer(toytask->rwsched_tasklet_info, runloop, cftimer, instance->main_cfrunloop_mode);

  // Fill in the toytimer structure
  toytimer->id = cftimer->index;
  toytimer->cb = cb;
  toytimer->ud = ud;

  // Fill in the toytimer context structure
  toytimer->context.toytask = toy;
  toytimer->context.source.cftimer = cftimer;
  toytimer->context.u.toytimer.toytimer = toytimer;

  // Return the callback id
  return (uint64_t) toytimer->id;
}
Exemple #15
0
CF_EXPORT void
rwsched_tasklet_CFRunLoopTimerSetNextFireDate(
    rwsched_tasklet_t *sched_tasklet,
    rwsched_CFRunLoopTimerRef rwsched_timer,
    CFAbsoluteTime fireDate)
{
    // 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);
    RW_CF_TYPE_VALIDATE(rwsched_timer, rwsched_CFRunLoopTimerRef);

    CFRunLoopTimerSetNextFireDate(rwsched_timer->cf_object, fireDate);
}
Exemple #16
0
void
rwsched_dispatch_main_until(rwsched_tasklet_ptr_t sched_tasklet,
                            double sec,
                            uint32_t *exitnow) {
  // 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);

  struct timeval start_tv;
  gettimeofday(&start_tv, NULL);
  struct timeval now_tv = start_tv;

  int evfd = dispatch_get_main_queue_eventfd_np();
  RW_ASSERT(evfd >= 0);

  int flags = fcntl(evfd, F_GETFL);
  flags |= O_NONBLOCK;
  fcntl(evfd, F_SETFL, flags);

  while (seconds_elapsed(&start_tv, &now_tv) < sec) {
      if (exitnow && *exitnow) 
        break;

      int secleft = MAX(0, (sec - seconds_elapsed(&start_tv, &now_tv)));
      struct pollfd pfd = { .fd = evfd, .events = POLLIN, .revents = 0 };
      if (0 < poll(&pfd, 1, secleft * 1000)) {
	uint64_t evct = 0;
	int rval = 0;
	rval = read(evfd, &evct, sizeof(evct));
	if (rval == 8) {
	  dispatch_main_queue_drain_np();
	}
      }
      
      gettimeofday(&now_tv, NULL);
  }
}

void
rwsched_dispatch_main_iteration(rwsched_tasklet_ptr_t sched_tasklet) {
 
  // Validate input paraemters
  RW_CF_TYPE_VALIDATE(sched_tasklet, rwsched_tasklet_ptr_t);
  rwsched_instance_t *instance = sched_tasklet->instance;
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);

  dispatch_main_queue_drain_np();
}
Exemple #17
0
CF_EXPORT void
rwsched_tasklet_CFRunLoopRemoveTimer(rwsched_tasklet_ptr_t sched_tasklet,
                                     rwsched_CFRunLoopRef rl,
                                     rwsched_CFRunLoopTimerRef rwsched_timer,
                                     CFStringRef mode)
{
    // 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);
    RW_CF_TYPE_VALIDATE(rwsched_timer, rwsched_CFRunLoopTimerRef);

    // Call the native CFRunLoop function
    CFRunLoopRemoveTimer(rl, rwsched_timer->cf_object, mode);
}
Exemple #18
0
int
rwmsg_toytask_block(rwmsg_toytask_t *toy, uint64_t id, int timeout_ms)
{
  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;

  // 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);
  toyfd = cf_context.info;

  rwsched_CFRunLoopSourceRef wakeup_source;
  double secondsToWait = timeout_ms * .001;
  wakeup_source = rwsched_tasklet_CFRunLoopRunTaskletBlock(toytask->rwsched_tasklet_info,
						   cfsocket->callback_context.cfsource,
						   secondsToWait);

  // Set the return value based on which dispatch source woke up on the semaphore
  int revents = 0;
  if (wakeup_source == NULL) {
    revents = 0;
  }
  else if (wakeup_source == toyfd->read_context.source.source) {
    revents = POLLIN;
  }
  else if (wakeup_source == toyfd->write_context.source.source) {
    revents = POLLOUT;
  }
  else {
    // This should never happen as one of the sources should have signaled the semahpore to wake it up
    RW_CRASH();
  }

  // Return the revents value to the caller
  return revents;
}
rw_status_t rwtasklet_register_uagent_client(rwuagent_client_info_ptr_t rwuagent_info)
{
  rw_status_t status;
  rwtasklet_info_ptr_t rwtasklet_info = rwuagent_info->rwtasklet_info;

  RW_CF_TYPE_VALIDATE(rwuagent_info, rwuagent_client_info_ptr_t);

  // Instantiate a Test service client and bind this to the client channel
  RW_UAGENT__INITCLIENT(&rwuagent_info->rwuacli);

  RW_ASSERT(rwtasklet_info->rwmsg_endpoint);

  // Create a client channel pointing at the Test service's path
  // Instantiate a Test service client and connect this to the client channel
  rwuagent_info->dest = rwmsg_destination_create(rwtasklet_info->rwmsg_endpoint,
                                                 RWMSG_ADDRTYPE_UNICAST,
                                                 RWUAGENT_PATH);
  RW_ASSERT(rwuagent_info->dest);

  // Create a client channel that rwcli uses to recieve messages
  rwuagent_info->cc = rwmsg_clichan_create(rwtasklet_info->rwmsg_endpoint);
  RW_ASSERT(rwuagent_info->cc);

  // Bind a single service for uagent
  rwmsg_clichan_add_service(rwuagent_info->cc, &rwuagent_info->rwuacli.base);

  // Bind this srvchan to rwsched's taskletized cfrunloop
  // This will result in events executing in the cfrunloop context
  // rwsched_CFRunLoopRef runloop = rwsched_tasklet_CFRunLoopGetCurrent(tenv.rwsched);
  status = rwmsg_clichan_bind_rwsched_cfrunloop(rwuagent_info->cc,
                                                rwtasklet_info->rwsched_tasklet_info);
  RW_ASSERT(status == RW_STATUS_SUCCESS);

  return status;
}
Exemple #20
0
static void
rwmsg_toysched_Rtimer_callback(rwsched_CFRunLoopTimerRef timer, void *info)
{
  UNUSED(timer);
  struct rwmsg_toytimer_s *toytimer = (struct rwmsg_toytimer_s *) info;
  rwmsg_toytask_t *toytask;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(toytimer, rwmsg_toytimer_ptr_t);
  toytask = toytimer->context.toytask;
  RW_CF_TYPE_VALIDATE(toytask, rwtoytask_tasklet_ptr_t);

  // Invoke the user specified callback
  RW_ASSERT(toytimer->cb);
  toytimer->cb(toytimer->id, toytimer->ud);
}
Exemple #21
0
rwsched_dispatch_queue_t
rwsched_dispatch_get_main_queue(rwsched_instance_ptr_t instance)
{
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);
  RW_ASSERT_TYPE(instance->main_rwqueue, rwsched_dispatch_queue_t);
  return instance->main_rwqueue;
}
Exemple #22
0
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
}
Exemple #23
0
int
rwsched_instance_get_latency_check(rwsched_instance_t *instance) 
{
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);

  return instance->latency.check_threshold_ms;
}
Exemple #24
0
CF_EXPORT void
rwsched_tasklet_CFRunLoopAddSource(rwsched_tasklet_ptr_t sched_tasklet,
                                   rwsched_CFRunLoopRef rl,
                                   rwsched_CFRunLoopSourceRef source,
                                   CFStringRef mode)
{
    // 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);
    // RW_CF_TYPE_VALIDATE(rl, rwsched_CFRunLoopRef);
    RW_CF_TYPE_VALIDATE(source, rwsched_CFRunLoopSourceRef);

    // Call the native CFRunLoop function
    CFRunLoopAddSource(rl, source->cf_object, mode);
}
Exemple #25
0
rw_status_t
rwvcs_variable_list_evaluate(rwvcs_instance_ptr_t instance,
                             size_t n_variable,
                             char **variable)
{
  int i;
  char *expression;
  rw_status_t status = RW_STATUS_SUCCESS;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(instance, rwvcs_instance_ptr_t);

  // Evaluate each variable in the list
  for (i = 0 ; i < n_variable ; i++) {
    expression = variable[i];
    RWTRACE_INFO(instance->rwvx->rwtrace,
                 RWTRACE_CATEGORY_RWVCS,
                 "Variable list evaluate - expression = %s\n",
                 expression);
    status = instance->rwpython_util.iface->python_run_string(
        instance->rwpython_util.cls,
        expression);
    RW_ASSERT(status == RW_STATUS_SUCCESS);
  }

  // The variable list evaluation was successful
  return RW_STATUS_SUCCESS;
}
Exemple #26
0
void
rwdtsperf_instance_stop(rwdtsperf_component_ptr_t component,
			                  rwdtsperf_instance_ptr_t instance)
{
  xact_config_t *xact_cfg;

  // Validate input parameters
  RW_CF_TYPE_VALIDATE(component, rwdtsperf_component_ptr_t);
  RW_CF_TYPE_VALIDATE(instance, rwdtsperf_instance_ptr_t);

  xact_cfg = &(instance->config.xact_cfg);

  xact_cfg->running = false;
  xact_cfg->xact_max_with_outstanding = 0;
  rwdts_api_deinit(instance->dts_h);
}
Exemple #27
0
static void
rwlogd__component__instance_start(RwTaskletPluginComponent *self,
					RwTaskletPluginComponentHandle *h_component,
					RwTaskletPluginInstanceHandle *h_instance)
{
  rwlogd_component_ptr_t component;
  rwlogd_instance_ptr_t instance;

  // Validate input parameters
  component = (rwlogd_component_ptr_t) h_component->priv;
  RW_CF_TYPE_VALIDATE(component, rwlogd_component_ptr_t);
  instance = (rwlogd_instance_ptr_t) h_instance->priv;
  RW_CF_TYPE_VALIDATE(instance, rwlogd_instance_ptr_t);

  rwlogd_start_tasklet(instance, true,NULL,NULL,NULL);
}
Exemple #28
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;
}
Exemple #29
0
void
rwsched_instance_set_latency_check(rwsched_instance_t *instance, int threshold_ms) 
{
  RW_CF_TYPE_VALIDATE(instance, rwsched_instance_ptr_t);
  RW_ASSERT(threshold_ms >= 0);

  instance->latency.check_threshold_ms = threshold_ms;
}
Exemple #30
0
CF_EXPORT void
rwsched_tasklet_CFRunLoopTimerGetContext(rwsched_tasklet_ptr_t sched_tasklet,
        rwsched_CFRunLoopTimerRef rwsched_timer,
        rwsched_CFRunLoopTimerContext *context)
{
    // 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);
    RW_CF_TYPE_VALIDATE(rwsched_timer, rwsched_CFRunLoopTimerRef);

    // Call the native CFRunLoop function
    CFRunLoopTimerGetContext(rwsched_timer->cf_object, context);

    // Use our internal context structure for now
    context->info = rwsched_timer->cf_context.info;
}