void bnf::Run( int worker_thread_count ) { run_flag_ = true; // session process thread boost::thread session_process(boost::bind(&bnf::SessionProcessThread, this)); // remove session thread boost::thread remove_session(boost::bind(&bnf::RemoveSessionThread, this)); // i/o worker thread for( int i = 0; i < worker_thread_count; i++ ) { thread_group_.create_thread(boost::bind(&bnf::WorkerThread, this)); LOG_INFO( "bnf - start worker therad." ); } LOG_INFO( "bnf - running." ); thread_group_.join_all(); LOG_INFO( "bnf - worker thread end." ); io_service_.stop(); // session process 종료Run PutSessionEvent( SessionEvent::ON_EXIT, NULL ); session_process.join(); LOG_INFO( "bnf - session process thread end." ); // remove session 종료 remove_session_queue_.push_signal(SessionBase::INVALID_SESSION_HANDLE); remove_session.join(); LOG_INFO( "bnf - remove session thread end." ); }
/*ARGSUSED*/ extern int main(int argc, char *argv[]) { XEvent ev; struct sigaction sa; int dpy_fd, max_fd; argv0 = argv[0]; mode = wm_initialising; setlocale(LC_ALL, ""); /* Open a connection to the X server. */ dpy = XOpenDisplay(NULL); if (dpy == 0) panic("can't open display."); parseResources(); /* Set up an error handler. */ XSetErrorHandler(errorHandler); /* Set up signal handlers. */ signal(SIGTERM, Terminate); signal(SIGINT, Terminate); signal(SIGHUP, Terminate); /* Ignore SIGCHLD. */ sa.sa_handler = SIG_IGN; #ifdef SA_NOCLDWAIT sa.sa_flags = SA_NOCLDWAIT; #else sa.sa_flags = 0; #endif sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, 0); /* Internalize useful atoms. */ wm_state = XInternAtom(dpy, "WM_STATE", False); wm_change_state = XInternAtom(dpy, "WM_CHANGE_STATE", False); wm_protocols = XInternAtom(dpy, "WM_PROTOCOLS", False); wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False); wm_take_focus = XInternAtom(dpy, "WM_TAKE_FOCUS", False); wm_colormaps = XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); compound_text = XInternAtom(dpy, "COMPOUND_TEXT", False); _mozilla_url = XInternAtom(dpy, "_MOZILLA_URL", False); motif_wm_hints = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); ewmh_init(); /* * Get fonts for our titlebar and our popup window. We try to * get Lucida, but if we can't we make do with fixed because everyone * has that. */ { /* FIXME: do these need to be freed? */ char **missing; char *def; int missing_count; font_set = XCreateFontSet(dpy, font_name, &missing, &missing_count, &def); if (font_set == NULL) font_set = XCreateFontSet(dpy, "fixed", &missing, &missing_count, &def); if (font_set == NULL) panic("unable to create font set for title font"); if (missing_count > 0) fprintf(stderr,"%s: warning: missing %d charset" "%s for title font\n", argv0, missing_count, (missing_count == 1)?"":"s"); font_set_ext = XExtentsOfFontSet(font_set); popup_font_set = XCreateFontSet(dpy, popup_font_name, &missing, &missing_count, &def); if (popup_font_set == NULL) popup_font_set = XCreateFontSet(dpy, "fixed", &missing, &missing_count, &def); if (popup_font_set == NULL) panic("unable to create font set for popup font"); if (missing_count > 0) fprintf(stderr,"%s: warning: missing %d charset" "%s for popup font\n", argv0, missing_count, (missing_count == 1)?"":"s"); popup_font_set_ext = XExtentsOfFontSet(popup_font_set); } initScreens(); ewmh_init_screens(); session_init(argc, argv); /* See if the server has the Shape Window extension. */ shape = serverSupportsShapes(); /* * Initialisation is finished, but we start off not interacting with the * user. */ mode = wm_idle; /* * The main event loop. */ dpy_fd = ConnectionNumber(dpy); max_fd = dpy_fd + 1; if (ice_fd > dpy_fd) max_fd = ice_fd + 1; for (;;) { fd_set readfds; FD_ZERO(&readfds); FD_SET(dpy_fd, &readfds); if (ice_fd > 0) FD_SET(ice_fd, &readfds); if (select(max_fd, &readfds, NULL, NULL, NULL) > -1) { if (FD_ISSET(dpy_fd, &readfds)) { while (XPending(dpy)) { XNextEvent(dpy, &ev); dispatch(&ev); } } if (ice_fd > 0 && FD_ISSET(ice_fd, &readfds)) { session_process(); } } } }