static void
test_fork_handling(void *arg)
{
  struct fork_test_data *d = arg;
  u8 buf[64], buf2[32];
  int in_child = 0;

  DECLARE_STATE();

  (void)arg;

#ifndef OTTERY_STRUCT
  tt_int_op(ottery_seed_counter, ==, 0);
#endif

  INIT_STATE();

  OTTERY_PUBLIC_FN (random_buf)(OTTERY_STATE_ARG_OUT COMMA buf, 64);
  tt_int_op(STATE_FIELD(seed_counter), ==, 1);

  if ((d->child = fork()))
    {
      IN_PARENT(d);
#ifdef USING_ATFORK
      tt_int_op(ottery_fork_count, ==, 0);
#endif
      OTTERY_PUBLIC_FN (random_buf)(OTTERY_STATE_ARG_OUT COMMA buf, 32);
      tt_int_op(RNG_PTR->idx, ==, 96);
    }
static void HMG_entry_pal(ucos_msg_id_t msg, ucos_msg_param_t param)
{
   wei_sm_queue_param_s *sm_param = (wei_sm_queue_param_s*)param;

   /* Dispatch signal to the current state function. */
   do
   {
      if (stateVars.newState_fn != stateVars.currentState_fn)
      {
         /* Make a state transition. 
            Note that the init and exit signals will be propagated to any substate.
         */
         EXIT_STATE(stateVars.currentState_fn);
         INIT_STATE(stateVars.newState_fn);
         stateVars.currentState_fn = stateVars.newState_fn;
      }
      else
      {
         stateVars.newState_fn = EXECUTE_STATE(stateVars.currentState_fn);
      }

      do
      {
         if (stateVars.newSubState_fn != stateVars.subState_fn)
         {
            /* Make a state transition. 
               Note that the init and exit signals will be propagated to any substate.
            */          
            EXIT_STATE(stateVars.subState_fn);
            INIT_STATE(stateVars.newSubState_fn);
            stateVars.subState_fn = stateVars.newSubState_fn;
         }
         else
         {            
            stateVars.newSubState_fn = EXECUTE_STATE(stateVars.subState_fn);
         }
      } while (stateVars.newSubState_fn != stateVars.subState_fn);

   } while (stateVars.newState_fn != stateVars.currentState_fn);
   if(sm_param)
   {
      if(sm_param->type == WRAPPER_STRUCTURE) {
         WrapperFreeStructure(sm_param->p);
      }
      DriverEnvironment_Nonpaged_Free(sm_param);
   }  
}
Exemple #3
0
/* Create a new aggregation instance. */
static agg_instance_t *agg_instance_create (data_set_t const *ds, /* {{{ */
    value_list_t const *vl, aggregation_t *agg)
{
  agg_instance_t *inst;

  DEBUG ("aggregation plugin: Creating new instance.");

  inst = calloc (1, sizeof (*inst));
  if (inst == NULL)
  {
    ERROR ("aggregation plugin: calloc() failed.");
    return (NULL);
  }
  pthread_mutex_init (&inst->lock, /* attr = */ NULL);

  inst->ds_type = ds->ds[0].type;

  agg_instance_create_name (inst, vl, agg);

  inst->min = NAN;
  inst->max = NAN;

#define INIT_STATE(field) do { \
  inst->state_ ## field = NULL; \
  if (agg->calc_ ## field) { \
    inst->state_ ## field = calloc (1, sizeof (*inst->state_ ## field)); \
    if (inst->state_ ## field == NULL) { \
      agg_instance_destroy (inst); \
      free (inst); \
      ERROR ("aggregation plugin: calloc() failed."); \
      return (NULL); \
    } \
  } \
} while (0)

  INIT_STATE (num);
  INIT_STATE (sum);
  INIT_STATE (average);
  INIT_STATE (min);
  INIT_STATE (max);
  INIT_STATE (stddev);

#undef INIT_STATE

  pthread_mutex_lock (&agg_instance_list_lock);
  inst->next = agg_instance_list_head;
  agg_instance_list_head = inst;
  pthread_mutex_unlock (&agg_instance_list_lock);

  return (inst);
} /* }}} agg_instance_t *agg_instance_create */
/* Create a new aggregation instance. */
static agg_instance_t *agg_instance_create (data_set_t const *ds, /* {{{ */
    value_list_t const *vl, aggregation_t *agg)
{
  agg_instance_t *inst;

  DEBUG ("aggregation plugin: Creating new instance.");

  inst = malloc (sizeof (*inst));
  if (inst == NULL)
  {
    ERROR ("aggregation plugin: malloc() failed.");
    return (NULL);
  }
  memset (inst, 0, sizeof (*inst));
  pthread_mutex_init (&inst->lock, /* attr = */ NULL);

  inst->ds_type = ds->ds[0].type;

#define COPY_FIELD(field, group_mask) do { \
  sstrncpy (inst->ident.field, \
      (agg->group_by & group_mask) ? vl->field : agg->ident.field, \
      sizeof (inst->ident.field)); \
} while (0)

  COPY_FIELD (host, LU_GROUP_BY_HOST);
  COPY_FIELD (plugin, LU_GROUP_BY_PLUGIN);
  COPY_FIELD (plugin_instance, LU_GROUP_BY_PLUGIN_INSTANCE);
  COPY_FIELD (type, /* group_mask = */ 0);
  COPY_FIELD (type_instance, LU_GROUP_BY_TYPE_INSTANCE);

#undef COPY_FIELD

  inst->min = NAN;
  inst->max = NAN;

#define INIT_STATE(field) do { \
  inst->state_ ## field = NULL; \
  if (agg->calc_ ## field) { \
    inst->state_ ## field = malloc (sizeof (*inst->state_ ## field)); \
    if (inst->state_ ## field == NULL) { \
      agg_instance_destroy (inst); \
      ERROR ("aggregation plugin: malloc() failed."); \
      return (NULL); \
    } \
    memset (inst->state_ ## field, 0, sizeof (*inst->state_ ## field)); \
  } \
} while (0)

  INIT_STATE (num);
  INIT_STATE (sum);
  INIT_STATE (average);
  INIT_STATE (min);
  INIT_STATE (max);
  INIT_STATE (stddev);

#undef INIT_STATE

  pthread_mutex_lock (&agg_instance_list_lock);
  inst->next = agg_instance_list_head;
  agg_instance_list_head = inst;
  pthread_mutex_unlock (&agg_instance_list_lock);

  return (inst);
} /* }}} agg_instance_t *agg_instance_create */