/* ////////////////////////////////////////////////////////////////////////////////////// * main */ tb_int_t tb_demo_platform_cache_time_main(tb_int_t argc, tb_char_t** argv) { tb_trace_i("%lld %lld", tb_cache_time_spak(), tb_cache_time_mclock()); tb_sleep(1); tb_trace_i("%lld %lld", tb_cache_time_spak(), tb_cache_time_mclock()); tb_sleep(1); tb_trace_i("%lld %lld", tb_cache_time_spak(), tb_cache_time_mclock()); return 0; }
ATerm toolbus_start(int conn, const char *script, ATerm args) { int i, pid, cid; char *argv[MAX_ARGS]; char sockets[2][BUFSIZ]; WellKnownSocketPort = TB_PORT; if (mk_server_ports(0) == TB_ERROR) { ATerror("cannot create server ports, giving up!\n"); } else { fprintf(stderr, "server ports created at %d\n", WellKnownSocketPort); } pid = fork(); if (pid == -1) { ATerror("cannot fork toolbus-adapter, giving up!\n"); } else if (pid > 0) { /* Parent */ /* connect to child toolbus! */ int attempts = 0; do { cid = ATBconnect(NULL, NULL, WellKnownSocketPort, toolbus_adapter_handler); if (cid < 0) { tb_sleep(0, 500000); } } while (cid < 0 && attempts++ < MAX_ATTEMPTS); if (cid < 0) { return ATparse("snd-value(toolbus-error)"); } else { if (cid > max_cid) { max_cid = cid; } return ATmake("snd-value(toolbus-started(<int>))", cid); } } else { /* Child */ /*{{{ setup arguments */ int argc = 0; ATermList arg_list; sprintf(sockets[0], "%d", WellKnownLocalSocket); sprintf(sockets[1], "%d", WellKnownGlobalSocket); argv[argc++] = TBPROG; argv[argc++] = "-TB_USE_SOCKETS"; argv[argc++] = sockets[0]; argv[argc++] = sockets[1]; assert(ATgetType(args) == AT_LIST); arg_list = (ATermList)args; while (!ATisEmpty(arg_list)) { ATerm arg = ATgetFirst(arg_list); arg_list = ATgetNext(arg_list); if (ATgetType(arg) == AT_APPL) { argv[argc++] = ATgetName(ATgetAFun((ATermAppl)arg)); } else { argv[argc] = strdup(ATwriteToString(arg)); assert(argv[argc]); argc++; } } /* Jurgen added this (char*) cast to prevent a compiler warning. * But this code has more problems: we know that updating * argv[] arrays is not portable, so the following code is actually * wrong: */ argv[argc++] = (char*) script; argv[argc] = NULL; for (i=0; i<argc; i++) { fprintf(stderr, "argv[%d] = %s\n", i, argv[i]); } /*}}} */ if (execv(TBPROG, argv) < 0) { perror(TBPROG); ATerror("cannot execute toolbus executable, giving up!\n"); } } return NULL; }