Ejemplo n.º 1
0
void test_microsecond()
{
  ulonglong t1= my_timer_microseconds();
  ulonglong t2;
  int i;
  int backward= 0;
  int nonzero= 0;

  for (i=0 ; i < LOOP_COUNT ; i++)
  {
    t2= my_timer_microseconds();
    if (t1 > t2)
      backward++;
    if (t2 != 0)
      nonzero++;
    t1= t2;
  }

  ok((backward == 0), "The microsecond timer is increasing");

  if (myt.microseconds.routine != 0)
    ok((nonzero != 0), "The microsecond timer is implemented");
  else
    ok((nonzero == 0), "The microsecond timer is not implemented and returns 0");
}
Ejemplo n.º 2
0
int change_master(chassis *srv) {
        FILE *fp;
        gchar buf[32];
        int child_ret, ret = -1;
        guint64 now, time_interval;

        chassis_plugin *p = srv->modules->pdata[1];/*proxy plugin*/
        chassis_plugin_config *config = p->config;
        if(access(config->change_master_script, F_OK | X_OK)) {
                g_message("%s: the change master script is not exist or have no permission to execute", G_STRLOC);
                return ret;
        }
        if(g_atomic_int_compare_and_exchange(&(config->is_changing_master), 0, 1) == FALSE) {
                g_message("%s:other thread is changing master, do not change.", G_STRLOC);
                return 1;
        }
        time_interval = 1 * 60 * 1000 * 1000;/*one minute*/
        now = my_timer_microseconds();
        if(now < config->last_change_time + time_interval) {
                g_message("%s:change master so frequently, do not change.", G_STRLOC);
                return -2;
        }
        GString *command = g_string_new("sh ");
        g_string_append(command, config->change_master_script);
        fp = popen(command->str, "r");
        if(fp == NULL) {
                g_message("%s:popen error, errno = %d", G_STRLOC, errno);
                g_string_free(command, TRUE);
                return ret;
        }
        fgets(buf, sizeof(buf), fp);
        child_ret = atoi(buf);
        if(child_ret == 0) {
                g_message("%s:change master successfully", G_STRLOC);
                config->last_change_time = my_timer_microseconds();
                ret = 0;
        }else {
                g_message("%s:change master unsuccessfully", G_STRLOC);
        }
        g_atomic_int_set(&(config->is_changing_master), 0);
        pclose(fp);

        return ret;
}
Ejemplo n.º 3
0
void chassis_timestamp_init_now(chassis_timestamp_t *ts,
        const char *name,
        const char *filename,
        gint line) {

    ts->name = name;
    ts->filename = filename;
    ts->line = line;
    ts->usec = my_timer_microseconds();
    ts->cycles = my_timer_cycles();
    ts->ticks = my_timer_ticks();
}
Ejemplo n.º 4
0
guint64 chassis_get_rel_microseconds() {
    return my_timer_microseconds();
}