| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SANDBOX_SRC_WIN2K_THREADPOOL_H_ | |
| 6 #define SANDBOX_SRC_WIN2K_THREADPOOL_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <algorithm> | |
| 11 #include <list> | |
| 12 #include "base/macros.h" | |
| 13 #include "sandbox/win/src/crosscall_server.h" | |
| 14 | |
| 15 namespace sandbox { | |
| 16 | |
| 17 // Win2kThreadPool a simple implementation of a thread provider as required | |
| 18 // for the sandbox IPC subsystem. See sandbox\crosscall_server.h for the details | |
| 19 // and requirements of this interface. | |
| 20 // | |
| 21 // Implementing the thread provider as a thread pool is desirable in the case | |
| 22 // of shared memory IPC because it can generate a large number of waitable | |
| 23 // events: as many as channels. A thread pool does not create a thread per | |
| 24 // event, instead maintains a few idle threads but can create more if the need | |
| 25 // arises. | |
| 26 // | |
| 27 // This implementation simply thunks to the nice thread pool API of win2k. | |
| 28 class Win2kThreadPool : public ThreadProvider { | |
| 29 public: | |
| 30 Win2kThreadPool(); | |
| 31 ~Win2kThreadPool() override; | |
| 32 | |
| 33 bool RegisterWait(const void* cookie, | |
| 34 HANDLE waitable_object, | |
| 35 CrossCallIPCCallback callback, | |
| 36 void* context) override; | |
| 37 | |
| 38 bool UnRegisterWaits(void* cookie) override; | |
| 39 | |
| 40 // Returns the total number of wait objects associated with | |
| 41 // the thread pool. | |
| 42 size_t OutstandingWaits(); | |
| 43 | |
| 44 private: | |
| 45 // record to keep track of a wait and its associated cookie. | |
| 46 struct PoolObject { | |
| 47 const void* cookie; | |
| 48 HANDLE wait; | |
| 49 }; | |
| 50 // The list of pool wait objects. | |
| 51 typedef std::list<PoolObject> PoolObjects; | |
| 52 PoolObjects pool_objects_; | |
| 53 // This lock protects the list of pool wait objects. | |
| 54 CRITICAL_SECTION lock_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(Win2kThreadPool); | |
| 57 }; | |
| 58 | |
| 59 } // namespace sandbox | |
| 60 | |
| 61 #endif // SANDBOX_SRC_WIN2K_THREADPOOL_H_ | |
| OLD | NEW |