| 56 | } |
| 57 | |
| 58 | int EventDispatcher::Start(const bthread_attr_t* thread_attr) { |
| 59 | if (_event_dispatcher_fd < 0) { |
| 60 | LOG(FATAL) << "kqueue was not created"; |
| 61 | return -1; |
| 62 | } |
| 63 | |
| 64 | if (_tid != 0) { |
| 65 | LOG(FATAL) << "Already started this dispatcher(" << this |
| 66 | << ") in bthread=" << _tid; |
| 67 | return -1; |
| 68 | } |
| 69 | |
| 70 | // Set _thread_attr before creating kqueue thread to make sure |
| 71 | // everyting seems sane to the thread. |
| 72 | if (thread_attr) { |
| 73 | _thread_attr = *thread_attr; |
| 74 | } |
| 75 | |
| 76 | //_thread_attr is used in StartInputEvent(), assign flag NEVER_QUIT to it will cause new bthread |
| 77 | // that created by kevent() never to quit. |
| 78 | // Only event dispatcher thread has flag BTHREAD_GLOBAL_PRIORITY. |
| 79 | bthread_attr_t kqueue_thread_attr = |
| 80 | _thread_attr | BTHREAD_NEVER_QUIT | BTHREAD_GLOBAL_PRIORITY; |
| 81 | bthread_attr_set_name(&kqueue_thread_attr, "EventDispatcher::RunThis"); |
| 82 | |
| 83 | // Polling thread uses the same attr for consumer threads (NORMAL right |
| 84 | // now). Previously, we used small stack (32KB) which may be overflowed |
| 85 | // when the older comlog (e.g. 3.1.85) calls com_openlog_r(). Since this |
| 86 | // is also a potential issue for consumer threads, using the same attr |
| 87 | // should be a reasonable solution. |
| 88 | int rc = bthread_start_background( |
| 89 | &_tid, &kqueue_thread_attr, RunThis, this); |
| 90 | if (rc) { |
| 91 | LOG(FATAL) << "Fail to create kqueue thread: " << berror(rc); |
| 92 | return -1; |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | bool EventDispatcher::Running() const { |
| 98 | return !_stop && _event_dispatcher_fd >= 0 && _tid != 0; |
nothing calls this directly
no test coverage detected