Epoll* epoll_new(gint handle) { g_assert(handle >= MIN_DESCRIPTOR); Epoll* epoll = g_new0(Epoll, 1); MAGIC_INIT(epoll); descriptor_init(&(epoll->super), DT_EPOLL, &epollFunctions, handle); /* allocate backend needed for managing events for this descriptor */ epoll->watches = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, _epollwatch_free); epoll->reports = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, NULL); /* the application may want us to watch some system files, so we need a * real OS epoll fd so we can offload that task. */ epoll->osEpollDescriptor = epoll_create(1000); if(epoll->osEpollDescriptor == -1) { warning("error in epoll_create for OS events, errno=%i", errno); } /* keep track of which virtual application we need to notify of events */ Worker* worker = worker_getPrivate(); /* epoll_new should be called as a result of an application syscall */ g_assert(worker->cached_application); epoll->ownerApplication = worker->cached_application; return epoll; }
int main(int argc, char* argv[]) { gint error = 0; options_init(argc - 1, argv + 1); INFO("Starting up."); descriptor_init(); DEBUG("Disabling SIGPIPE."); signal(SIGPIPE, SIG_IGN); DEBUG("Creating ZeroMQ context."); gpointer zmq_context = zmq_init(options_zmq_io_threads()); if (zmq_context == NULL) { PERROR("main(zmq_init)"); error = 1; goto err0; } DEBUG("Creating server on port %s.", options_port()); gint socket = socket_server(options_port()); if (socket == -1) { error = 1; goto err1; } INFO("Initialising Lua API."); lua_api_init(zmq_context, argc - 1, argv + 1); lua_State* lua = lua_api_get(); DEBUG("Running " LUA_START_FILE); if (luaL_dofile(lua, LUA_START_FILE) == 1) { ERROR("%s", lua_tostring(lua, -1)); error = 1; goto err2; } io_mainloop(socket); err2: DEBUG("Closing server socket."); socket_close(socket); err1: DEBUG("Terminating ZeroMQ context."); /* This is separate from lua_api_deinit() to prevent zmq_term() from blocking forever. */ lua_zmq_deinit(); zmq_term(zmq_context); err0: DEBUG("Enabling SIGPIPE."); signal(SIGPIPE, SIG_DFL); options_deinit(); descriptor_deinit(); if (lua_api_get() != NULL) { DEBUG("Closing Lua state."); lua_api_deinit(); } return error; }
static PHP_MINIT_FUNCTION(protobuf) { map_field_init(TSRMLS_C); repeated_field_init(TSRMLS_C); gpb_type_init(TSRMLS_C); message_init(TSRMLS_C); descriptor_pool_init(TSRMLS_C); descriptor_init(TSRMLS_C); enum_descriptor_init(TSRMLS_C); util_init(TSRMLS_C); }
void transport_init(Transport* transport, TransportFunctionTable* vtable, enum DescriptorType type, gint handle) { g_assert(transport && vtable); descriptor_init(&(transport->super), type, &transport_functions, handle); MAGIC_INIT(transport); MAGIC_INIT(vtable); transport->vtable = vtable; }
/** * This function must be called by the user driver to register itself with * the base DMA driver. After doing required checks to verify the choice * of engine and BAR register, it initializes the engine and the BD ring * associated with the engine, and enables interrupts if required. * * Only one user is supported per engine at any given time. Incase the * engine has already been registered with another user driver, an error * will be returned. * * @param engine is the DMA engine the user driver wants to use. * @param bar is the BAR register the user driver wants to use. * @param uptr is a pointer to the function callbacks in the user driver. * @param pktsize is the size of packets that the user driver will normally * use. * * @return NULL incase of any error in completing the registration. * @return Handle with which the user driver is registered. * * @note This function should not be called in an interrupt context * *****************************************************************************/ void * DmaRegister(int engine, int bar, UserPtrs * uptr, int pktsize) { Dma_Engine * eptr; Xaddr barbase; int result; log_verbose(KERN_INFO "User register for engine %d, BAR %d, pktsize %d\n", engine, bar, pktsize); if(DriverState != INITIALIZED) { printk(KERN_ERR "DMA driver state %d - not ready\n", DriverState); return NULL; } if((bar < 0) || (bar > 5)) { printk(KERN_ERR "Requested BAR %d is not valid\n", bar); return NULL; } if(!((dmaData->engineMask) & (1LL << engine))) { printk(KERN_ERR "Requested engine %d does not exist\n", engine); return NULL; } eptr = &(dmaData->Dma[engine]); barbase = (Xaddr)(dmaData->barInfo[bar].baseVAddr); log_verbose("guodebug DmaReg: barbase = %p\n", barbase); if(eptr->EngineState != INITIALIZED) { printk(KERN_ERR "Requested engine %d is not free\n", engine); return NULL; } /* Later, add check for reasonable packet size !!!! */ /* Later, add check for mandatory user function pointers. For optional * ones, assign a stub function pointer. This is better than doing * a NULL value check in the performance path. !!!! */ /* Copy user-supplied parameters */ eptr->user = *uptr; eptr->pktSize = pktsize; /* Should check for errors returned here !!!! */ (uptr->UserInit)(barbase, uptr->privData); spin_lock_bh(&DmaLock); /* Should inform the user of the errors !!!! */ result = descriptor_init(eptr->pdev, eptr); if (result) { /* At this point, handle has not been returned to the user. * So, user refuses to prepare buffers. Will be trying again in * the poll_routine. So, do not abort here. */ printk(KERN_ERR "Cannot create BD ring, will try again later.\n"); //return NULL; } /* Change the state of the engine, and increment the user count */ eptr->EngineState = USER_ASSIGNED; dmaData->userCount ++ ; /* Start the DMA engine */ if (Dma_BdRingStart(&(eptr->BdRing)) == XST_FAILURE) { log_normal(KERN_ERR "DmaRegister: Could not start Dma channel\n"); return NULL; } #ifdef TH_BH_ISR printk("Now enabling interrupts\n"); Dma_mEngIntEnable(eptr); #endif spin_unlock_bh(&DmaLock); log_verbose(KERN_INFO "Returning user handle %p\n", eptr); return eptr; }