static void do_notifier_select(struct thr_info *thr, struct timeval *tvp_timeout) { struct cgpu_info *cgpu = thr->cgpu; struct timeval tv_now; int maxfd; fd_set rfds; timer_set_now(&tv_now); FD_ZERO(&rfds); FD_SET(thr->notifier[0], &rfds); maxfd = thr->notifier[0]; FD_SET(thr->work_restart_notifier[0], &rfds); set_maxfd(&maxfd, thr->work_restart_notifier[0]); if (thr->mutex_request[1] != INVSOCK) { FD_SET(thr->mutex_request[0], &rfds); set_maxfd(&maxfd, thr->mutex_request[0]); } if (select(maxfd + 1, &rfds, NULL, NULL, select_timeout(tvp_timeout, &tv_now)) < 0) return; if (thr->mutex_request[1] != INVSOCK && FD_ISSET(thr->mutex_request[0], &rfds)) { // FIXME: This can only handle one request at a time! pthread_mutex_t *mutexp = &cgpu->device_mutex; notifier_read(thr->mutex_request); mutex_lock(mutexp); pthread_cond_signal(&cgpu->device_cond); pthread_cond_wait(&cgpu->device_cond, mutexp); mutex_unlock(mutexp); } if (FD_ISSET(thr->notifier[0], &rfds)) { notifier_read(thr->notifier); } if (FD_ISSET(thr->work_restart_notifier[0], &rfds)) notifier_read(thr->work_restart_notifier); }
/* init the CSF modules */ static int csf_init(void) { int rc; csf_conf_init(&main_conf); if (config_init() < 0) return CSF_ERR; else output_config(); /* start log */ if (main_conf.log_ident[0] == '\0') comm_handle.logp = logger_init(NULL, DEFAULT_WLOG_IDENT, LOG_CONS|LOG_PID, LOG_LOCAL6); else comm_handle.logp = logger_init(NULL, main_conf.log_ident, LOG_CONS|LOG_PID, LOG_LOCAL6); // comm_handle.mntp = monitor_init(NULL, main_conf.monitor_bind_ip, main_conf.monitor_port); comm_handle.sribp = request_info_init(&main_conf); if (main_conf.monitor_enable) { // if (monitor_start() < 0) { // WLOG_ERR("Monitor start failed."); // PRINT("Monitor start failed."); // } } if (main_conf.daemonize) daemonize(1, 1); set_maxfd(); /* * We prealloc the mempool * XXX We use pipeline_queue_size may not be suited? */ mp_init(main_conf.pipeline_queue_size / 10, main_conf.pipeline_queue_size / 2); rc = mod_config_init(&main_conf, &mod_queue_head, &gvcb, &comm_handle); if (rc != CSF_OK) { return (CSF_ERR); } /* * init pipeline module * (call the initialization function defined at protocol source file) */ if (!TAILQ_EMPTY(&mod_queue_head)) { rc = pipeline_init(&mod_queue_head, main_conf.pipeline_queue_size, main_conf.request_timeout); if (rc != PIPELINE_INIT_OK) { WLOG_ERR("Can not init pipeline."); PRINT("Can not init pipeline."); return (CSF_ERR); } } /*init protocol module*/ rc = app_proto_init(main_conf.protocol_module, main_conf.cp_ops, &gvcb, &comm_handle); if (rc < 0) return (CSF_ERR); return (CSF_OK); }