int fiber_event_init() { fiber_spinlock_lock(&fiber_loop_spinlock); assert("libev version mismatch" && ev_version_major () == EV_VERSION_MAJOR && ev_version_minor () >= EV_VERSION_MINOR); active_threads = fiber_manager_get_kernel_thread_count(); write_barrier();//needed so active_threads is set before fiber_loop (see fiber_poll_events_blocking - active_threads should never be decremented before it's been set) fiber_loop = ev_loop_new(EVFLAG_AUTO); assert(fiber_loop); fiber_spinlock_unlock(&fiber_loop_spinlock); return fiber_loop ? FIBER_SUCCESS : FIBER_ERROR; }
int main(int argc, char **argv) { int option; char *end; struct slave_options options; struct ev_loop *loop; options.sl_id = NULL; options.sl_port = YABS_DEFAULT_DESPATCHER_PORT; options.sl_server = NULL; options.sl_servertype = YABS_SERVER_STDIN; options.sl_verbose = 0; while ((option = getopt(argc, argv, "hi:p:vV")) != -1) { switch (option) { case 'h': show_usage(); exit(0); break; case 'i': if (options.sl_id) free(options.sl_id); options.sl_id = strdup(optarg); break; case 'p': options.sl_port = strtoul(optarg, &end, 10); if (options.sl_port == 0 || *end != '\0') errx(1, "Invalid port number \"%s\"", optarg); break; case 'v': options.sl_verbose++; break; case 'V': (void) printf(YABS_SLAVE_NAME " " YABS_SLAVE_VERSION "\n"); exit(0); break; case '?': show_usage(); exit(1); break; default: errx(1, "FATAL: Unrecognized option value %c (%d)", option, option); break; } } /* Use the local host name as the ID string. */ if (options.sl_id == NULL) { if ((options.sl_id = malloc(HOST_NAME_MAX)) == NULL) err(1, "malloc failed: [%s,%d]", __FILE__, __LINE__); if (gethostname(options.sl_id, HOST_NAME_MAX) < 0) err(1, "gethostname failed: [%s,%d]", __FILE__, __LINE__); options.sl_id[HOST_NAME_MAX - 1] = '\0'; } YABS_VERBOSE(options, 0, YABS_SLAVE_NAME " host:%s version:" YABS_SLAVE_VERSION " protocol-version:" YABS_PROTOCOL_VERSION " libev-version:%d.%d", options.sl_id, ev_version_major(), ev_version_minor()); if ((loop = ev_default_loop(0)) == NULL) err(1, "libev initialization failed"); ev_run(loop, 0); return (0); }
static int ev_version(lua_State *L) { lua_pushinteger(L, ev_version_major()); lua_pushinteger(L, ev_version_minor()); return 2; }
/** * Entry point into the 'ev' lua library. Validates that the * dynamically linked libev version matches, creates the object * registry, and creates the table returned by require(). */ LUALIB_API int luaopen_ev(lua_State *L) { assert(ev_version_major() == EV_VERSION_MAJOR && ev_version_minor() >= EV_VERSION_MINOR); create_obj_registry(L); luaL_register(L, "ev", R); luaopen_ev_loop(L); lua_setfield(L, -2, "Loop"); luaopen_ev_timer(L); lua_setfield(L, -2, "Timer"); luaopen_ev_io(L); lua_setfield(L, -2, "IO"); luaopen_ev_signal(L); lua_setfield(L, -2, "Signal"); luaopen_ev_idle(L); lua_setfield(L, -2, "Idle"); luaopen_ev_child(L); lua_setfield(L, -2, "Child"); luaopen_ev_stat(L); lua_setfield(L, -2, "Stat"); lua_pushnumber(L, EV_READ); lua_setfield(L, -2, "READ"); lua_pushnumber(L, EV_WRITE); lua_setfield(L, -2, "WRITE"); lua_pushnumber(L, EV_TIMEOUT); lua_setfield(L, -2, "TIMEOUT"); lua_pushnumber(L, EV_SIGNAL); lua_setfield(L, -2, "SIGNAL"); lua_pushnumber(L, EV_IDLE); lua_setfield(L, -2, "IDLE"); lua_pushnumber(L, EV_CHILD); lua_setfield(L, -2, "CHILD"); lua_pushnumber(L, EV_STAT); lua_setfield(L, -2, "STAT"); lua_pushnumber(L, EV_MINPRI); lua_setfield(L, -2, "MINPRI"); lua_pushnumber(L, EV_MAXPRI); lua_setfield(L, -2, "MAXPRI"); lua_pushnumber(L, SIGHUP); lua_setfield(L, -2, "SIGHUP"); lua_pushnumber(L, SIGINT); lua_setfield(L, -2, "SIGINT"); lua_pushnumber(L, SIGQUIT); lua_setfield(L, -2, "SIGQUIT"); lua_pushnumber(L, SIGILL); lua_setfield(L, -2, "SIGILL"); lua_pushnumber(L, SIGTRAP); lua_setfield(L, -2, "SIGTRAP"); lua_pushnumber(L, SIGABRT); lua_setfield(L, -2, "SIGABRT"); lua_pushnumber(L, SIGIOT); lua_setfield(L, -2, "SIGIOT"); lua_pushnumber(L, SIGBUS); lua_setfield(L, -2, "SIGBUS"); lua_pushnumber(L, SIGFPE); lua_setfield(L, -2, "SIGFPE"); lua_pushnumber(L, SIGUSR1); lua_setfield(L, -2, "SIGUSR1"); lua_pushnumber(L, SIGSEGV); lua_setfield(L, -2, "SIGSEGV"); lua_pushnumber(L, SIGUSR2); lua_setfield(L, -2, "SIGUSR2"); lua_pushnumber(L, SIGPIPE); lua_setfield(L, -2, "SIGPIPE"); lua_pushnumber(L, SIGALRM); lua_setfield(L, -2, "SIGALRM"); lua_pushnumber(L, SIGTERM); lua_setfield(L, -2, "SIGTERM"); lua_pushnumber(L, SIGSTKFLT); lua_setfield(L, -2, "SIGSTKFLT"); lua_pushnumber(L, SIGCHLD); lua_setfield(L, -2, "SIGCHLD"); lua_pushnumber(L, SIGCONT); lua_setfield(L, -2, "SIGCONT"); lua_pushnumber(L, SIGTSTP); lua_setfield(L, -2, "SIGTSTP"); lua_pushnumber(L, SIGTTIN); lua_setfield(L, -2, "SIGTTIN"); lua_pushnumber(L, SIGTTOU); lua_setfield(L, -2, "SIGTTOU"); lua_pushnumber(L, SIGURG); lua_setfield(L, -2, "SIGURG"); lua_pushnumber(L, SIGXCPU); lua_setfield(L, -2, "SIGXCPU"); lua_pushnumber(L, SIGXFSZ); lua_setfield(L, -2, "SIGXFSZ"); lua_pushnumber(L, SIGVTALRM); lua_setfield(L, -2, "SIGVTALRM"); lua_pushnumber(L, SIGPROF); lua_setfield(L, -2, "SIGPROF"); lua_pushnumber(L, SIGWINCH); lua_setfield(L, -2, "SIGWINCH"); lua_pushnumber(L, SIGIO); lua_setfield(L, -2, "SIGIO"); lua_pushnumber(L, SIGPOLL); lua_setfield(L, -2, "SIGPOLL"); lua_pushnumber(L, SIGPWR); lua_setfield(L, -2, "SIGPWR"); lua_pushnumber(L, SIGSYS); lua_setfield(L, -2, "SIGSYS"); return 1; }
static PyObject * pyev_abi_version(PyObject *module) { return Py_BuildValue("(ii)", ev_version_major(), ev_version_minor()); }
/* Procedure exposed in Python to provide libev's ABI version */ static PyObject *py_libev_version(PyObject *self, PyObject *args) { PyObject *pyres=Py_BuildValue("ii", ev_version_major(), ev_version_minor()); return pyres; }