示例#1
0
文件: Timer.c 项目: demilich/utility
int timer2_cb(timer_id id, void *arg, int len)
{
	char tstr[200];
	static int i, ret;

	printf("hello [%s]/id %d: timer2_cb is here.\n", fmt_time(tstr),id);
	if (i > 10) {
		ret = del_timer(id);
		printf("timer2_cb: %s del_timer/id %d::ret=%d\n", fmt_time(tstr),id,ret);
	}
	i++;
	call_cnt++;

	return 0;
}
示例#2
0
文件: Timer.c 项目: demilich/utility
int main(void)
{
	char arg[50];
	char tstr[200];
	int ret;
	struct timespec time;
	time.tv_sec = 0,
	time.tv_nsec= 100000000;

	init_timer(MAX_TIMER_NUM);

	id[0] = add_timer(1, timer1_cb, NULL, 0);
	printf("Register timer id[0]=%d\n", id[0]);

	id[1] = add_timer(2, timer2_cb, arg, 50);
	printf("Register timer id[1]=%d\n", id[1]);

	while (1) {
		if (call_cnt > 10) {
			break;
		}

		nanosleep(&time, NULL);
	}

	ret = destroy_timer();
	printf("main: %s destroy_timer, ret=%d\n", fmt_time(tstr), ret);
	return 0;
}
示例#3
0
文件: Timer.c 项目: demilich/utility
int timer1_cb(timer_id id, void *arg, int len)
{
	char tstr[200];
	static int i, ret;

	/* XXX: Don't use standard IO in the signal handler context, I just use it demo the timer */
	printf("hello [%s]/id %d: timer1_cb is here.\n", fmt_time(tstr),id);
	if (i > 10) {
		ret = del_timer(id);
		printf("timer1_cb: %s del_timer/id %d::ret=%d\n", fmt_time(tstr),id,ret);
	}
	i++;
	call_cnt++;

	return 0;
}
示例#4
0
static K printatom(K x)
{
    switch (xt) {
        case  -1: printf("%db", x->g); break;
        case  -4: printf("0x%02x", x->g); break;
        case  -5: printf("%d", x->h); break;
        case  -6: printf("%d", x->i); break;
        case  -7: printf("%lld", x->j); break;
        case  -8: printf("%.2f", x->e); break;
        case  -9: printf("%.2f", x->f); break;
        case -10: printf("\"%c\"", x->g); break;
        case -11: printf("`%s", x->s); break;
        case -12: fmt_time("%Y.%m.%dD%H:%M:%S.", ((x->j) / 8.64e13 + 10957)*8.64e4, 0); break;
        case -13: printf("%04d.%02d", (x->i)/12+2000, (x->i)%12+1); break;
        case -14: fmt_time("%Y.%m.%d", ((x->i) + 10957)*8.64e4, 0); break;
        case -15: fmt_time("%Y.%m.%dD%H:%M:%S", ((x->f) + 10957)*8.64e4, 0); break;
        case -16: { fmt_time("%jD%H:%M:%S", (x->j)/1000000000, 1);
            printf(".%09lld", (x->j)%1000000000); break; }
        case -17: fmt_time("%H:%M", (x->i) * 60, 1); break;
        case -18: fmt_time("%H:%M:%S", x->i, 1); break;
        case -19: { fmt_time("%H:%M:%S", (x->i) / 1000, 1);
            printf(".%03d", (x->i)%1000); break; }
        default: return krr("notimplemented");
    }
    
    return (K) 0;
}
示例#5
0
文件: shell.c 项目: SnookEE/nvc
static void event_watch(uint64_t now, tree_t decl, watch_t *w, void *user)
{
   uint64_t value[1];
   rt_watch_value(w, value, 1, false);

   uint64_t last[1];
   rt_watch_value(w, last, 1, true);

   LOCAL_TEXT_BUF last_tb = pprint(decl, last, 1);
   LOCAL_TEXT_BUF now_tb  = pprint(decl, value, 1);
   printf("%s: update %s %s -> %s\n", fmt_time(rt_now(NULL)),
          istr(tree_ident(decl)), tb_get(last_tb), tb_get(now_tb));
}
示例#6
0
文件: shell.c 项目: SnookEE/nvc
static int shell_cmd_now(ClientData cd, Tcl_Interp *interp,
                         int objc, Tcl_Obj *const objv[])
{
   const char *help =
      "now - Display current simulation time\n"
      "\n"
      "Usage: now [-q]\n"
      "\n"
      "Prints the current simulation time to the standard output unless -q\n"
      "is specified. Returns the time as a string.\n"
      "\n"
      "Examples:\n"
      "  now               Print current time\n"
      "  set n [now -q]    Store current time in a variable\n";

   if (show_help(objc, objv, help))
      return TCL_OK;

   bool quiet = false;

   for (int i = 1; i < objc; i++) {
      const char *what = Tcl_GetString(objv[i]);
      if (strcmp(what, "-q") == 0)
         quiet = true;
      else
         return tcl_error(interp, "invalid argument '%s' "
                          "(try -help for usage)", what);
   }

   const uint64_t now = rt_now(NULL);

   if (!quiet)
      printf("%s\n", fmt_time(now));

   Tcl_SetObjResult(interp, Tcl_NewIntObj(now));
   return TCL_OK;
}