| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BIN_EVENTHANDLER_H_ | 5 #ifndef BIN_EVENTHANDLER_H_ |
| 6 #define BIN_EVENTHANDLER_H_ | 6 #define BIN_EVENTHANDLER_H_ |
| 7 | 7 |
| 8 #include "bin/builtin.h" | 8 #include "bin/builtin.h" |
| 9 #include "bin/thread_pool.h" | |
| 10 | 9 |
| 11 // Flags used to provide information and actions to the eventhandler | 10 // Flags used to provide information and actions to the eventhandler |
| 12 // when sending a message about a file descriptor. These flags should | 11 // when sending a message about a file descriptor. These flags should |
| 13 // be kept in sync with the constants in socket_impl.dart. For more | 12 // be kept in sync with the constants in socket_impl.dart. For more |
| 14 // information see the comments in socket_impl.dart | 13 // information see the comments in socket_impl.dart |
| 15 enum MessageFlags { | 14 enum MessageFlags { |
| 16 kInEvent = 0, | 15 kInEvent = 0, |
| 17 kOutEvent = 1, | 16 kOutEvent = 1, |
| 18 kErrorEvent = 2, | 17 kErrorEvent = 2, |
| 19 kCloseEvent = 3, | 18 kCloseEvent = 3, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 35 #else | 34 #else |
| 36 #error Unknown target os. | 35 #error Unknown target os. |
| 37 #endif | 36 #endif |
| 38 | 37 |
| 39 class EventHandler { | 38 class EventHandler { |
| 40 public: | 39 public: |
| 41 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data) { | 40 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data) { |
| 42 delegate_.SendData(id, dart_port, data); | 41 delegate_.SendData(id, dart_port, data); |
| 43 } | 42 } |
| 44 | 43 |
| 45 static void AsyncTaskHandler(ThreadPool::Task args) { | |
| 46 if (Dart_IsVMFlagSet("trace_thread_pool")) { | |
| 47 printf("Got async task\n"); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 static void Initialize() { | |
| 52 if (Dart_IsVMFlagSet("enable_thread_pool")) { | |
| 53 ASSERT(thread_pool_ == NULL); | |
| 54 thread_pool_ = new ThreadPool(&EventHandler::AsyncTaskHandler); | |
| 55 thread_pool_->Start(); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 static void Terminate() { | |
| 60 if (Dart_IsVMFlagSet("enable_thread_pool")) { | |
| 61 if (thread_pool_ != NULL) { | |
| 62 thread_pool_->Shutdown(); | |
| 63 } | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 static EventHandler* StartEventHandler() { | 44 static EventHandler* StartEventHandler() { |
| 68 EventHandler* handler = new EventHandler(); | 45 EventHandler* handler = new EventHandler(); |
| 69 handler->delegate_.StartEventHandler(); | 46 handler->delegate_.StartEventHandler(); |
| 70 return handler; | 47 return handler; |
| 71 } | 48 } |
| 72 | 49 |
| 73 private: | 50 private: |
| 74 EventHandlerImplementation delegate_; | 51 EventHandlerImplementation delegate_; |
| 75 static ThreadPool* thread_pool_; | |
| 76 }; | 52 }; |
| 77 | 53 |
| 78 | 54 |
| 79 #endif // BIN_EVENTHANDLER_H_ | 55 #endif // BIN_EVENTHANDLER_H_ |
| OLD | NEW |