| 178 | |
| 179 | |
| 180 | void EventLoop::initialize() |
| 181 | { |
| 182 | static Once* initialized = new Once(); |
| 183 | |
| 184 | if (initialized->once()) { |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | // We need to initialize Libevent differently depending on the |
| 189 | // operating system threading support. |
| 190 | #if defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED) |
| 191 | if (evthread_use_pthreads() < 0) { |
| 192 | LOG(FATAL) << "Failed to initialize, evthread_use_pthreads"; |
| 193 | } |
| 194 | #elif defined(EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED) |
| 195 | if (evthread_use_windows_threads() < 0) { |
| 196 | LOG(FATAL) << "Failed to initialize, evthread_use_windows_threads"; |
| 197 | } |
| 198 | #else |
| 199 | #error "Libevent must be compiled with either pthread or Windows thread support" |
| 200 | #endif |
| 201 | |
| 202 | base = event_base_new(); |
| 203 | |
| 204 | if (base == nullptr) { |
| 205 | LOG(FATAL) << "Failed to initialize, event_base_new"; |
| 206 | } |
| 207 | |
| 208 | initialized->done(); |
| 209 | } |
| 210 | |
| 211 | } // namespace process { |