00001 /* 00002 * Scale Stack 00003 * 00004 * Copyright 2010 Eric Day 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00024 #ifndef SCALESTACK_EVENT_LIBEVENT_THREAD_H 00025 #define SCALESTACK_EVENT_LIBEVENT_THREAD_H 00026 00027 #include <event.h> 00028 #include <stdint.h> 00029 #include <vector> 00030 00031 #include <scalestack/threading/mutex.h> 00032 #include <scalestack/threading/thread.h> 00033 00034 namespace scalestack 00035 { 00036 namespace event 00037 { 00038 namespace libevent 00039 { 00040 00041 class handler_provider; 00042 00046 extern "C" void thread_handle_notify(int file_descriptor, 00047 short events, 00048 void* context); 00049 00050 class thread: private threading::thread 00051 { 00052 public: 00053 00060 thread(kernel::module& module, size_t thread_index); 00061 00062 ~thread(); 00063 00069 void shutdown(void); 00070 00076 void check_handler_provider(handler_provider* handler_provider); 00077 00082 struct event_base* get_event_base(void); 00083 00087 const struct timeval& get_now(void); 00088 00089 private: 00090 00094 thread(const thread&); 00095 00099 thread& operator=(const thread&); 00100 00104 void run(void); 00105 00109 void _add_notify_pipe(void); 00110 00114 void _remove_notify_pipe(void); 00115 00119 void _send_notify(void); 00120 00124 void _handle_notify(int file_descriptor, short events); 00125 00126 typedef std::vector<handler_provider*> handler_providers; 00127 00128 bool _shutdown; 00129 uint8_t _handler_providers_index; 00130 size_t _thread_index; 00131 struct event_base* _base; 00132 int _notify_pipe[2]; 00133 struct event _notify_event; 00134 struct timeval _notify_timeout; 00135 struct timeval _now; 00136 threading::mutex _handler_providers_mutex; 00137 handler_providers _handler_providers[2]; 00138 00139 friend void thread_handle_notify(int file_descriptor, 00140 short events, 00141 void* context); 00142 }; 00143 00144 } /* namespace libevent */ 00145 } /* namespace event */ 00146 } /* namespace scalestack */ 00147 00148 #endif /* SCALESTACK_EVENT_LIBEVENT_THREAD_H */
1.6.3