static int newmutex(lua_State *L) { srm_t *srm = (srm_t *) lua_newuserdata(L, sizeof(srm_t)); if (srm_init(srm) != 0) luaL_error(L, "unable to create mutex"); aux_setclass(L, "mutex", -1); return 1; }
/******************************************************************** * Parse command-line arguments (non -+ options) * * Returns: * ERR_OK: if success * >= ERR_OK: otherwise ********************************************************************/ static int s2_run(int argc, char **argv, int i) { int rval = ERR_OK, lval; int i_1 = i; Node *root = NULL; Process *proc = NULL; BOOL tp_created = FALSE; /* init progress bar */ Process::progress(-1,proc); #if defined(HAVE_SRM21) || defined(HAVE_SRM22) srm_init(); #endif lval = parse(opts.scr_fname, &root); DM_DBG(DM_N(1), "parser return value=%d\n", lval); UPDATE_MAX(rval, lval); if(rval > opts.s2_eval) { /* stop evaluation */ UPDATE_MAX(rval, ERR_NEXEC); goto cleanup; } /* create thread pool */ if(!tp_created) tp_init(opts.tp_size); tp_created = TRUE; /* pretty-print S2 tree ($ENV{VAR} are evaluated) */ if(opts.pp_fname) lval = pp_print(root); DM_DBG(DM_N(1), "pretty-printer return value=%d\n", lval); UPDATE_MAX(rval, lval); if(root) { Process::threads_init(); proc = new Process(root, NULL, NULL); if(!proc) { DM_ERR(ERR_SYSTEM, _("failed to create a Process: %s\n"), _(strerror(errno))); UPDATE_MAX(rval, ERR_SYSTEM); goto cleanup; } /* write ${0}..${n} variables */ const char *name = cmd_label(); proc->WriteVariable("0", name, TRUE); for(; i < argc; i++) { proc->WriteVariable(i2str(i - i_1 + 1).c_str(), argv[i], TRUE); } setenv("CLIENT_INFO", build_client_info(name), 1); lval = proc->eval(); Process::threads_destroy(); DM_DBG(DM_N(1), "evaluation return value=%d\n", lval); UPDATE_MAX(rval, lval); } /* after-evaluation print of the tree */ if(opts.e2_fname) lval = e2_print(root); DM_DBG(DM_N(2), "after-evaluation print return value=%d\n", lval); UPDATE_MAX(rval, lval); cleanup: /* cleanup */ DELETE(proc); /* free proc *first*, then root */ DELETE(root); /* destroy thread pool */ if(tp_created) tp_cleanup(); /* hide progress bar */ Process::progress(0,proc); DM_DBG(DM_N(1), "s2_run return value=%d\n", rval); return rval; }