1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/win/src/win2k_threadpool.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef SANDBOX_SRC_WIN2K_THREADPOOL_H_ 1.9 +#define SANDBOX_SRC_WIN2K_THREADPOOL_H_ 1.10 + 1.11 +#include <list> 1.12 +#include <algorithm> 1.13 +#include "sandbox/win/src/crosscall_server.h" 1.14 + 1.15 +namespace sandbox { 1.16 + 1.17 +// Win2kThreadPool a simple implementation of a thread provider as required 1.18 +// for the sandbox IPC subsystem. See sandbox\crosscall_server.h for the details 1.19 +// and requirements of this interface. 1.20 +// 1.21 +// Implementing the thread provider as a thread pool is desirable in the case 1.22 +// of shared memory IPC because it can generate a large number of waitable 1.23 +// events: as many as channels. A thread pool does not create a thread per 1.24 +// event, instead maintains a few idle threads but can create more if the need 1.25 +// arises. 1.26 +// 1.27 +// This implementation simply thunks to the nice thread pool API of win2k. 1.28 +class Win2kThreadPool : public ThreadProvider { 1.29 + public: 1.30 + Win2kThreadPool() { 1.31 + ::InitializeCriticalSection(&lock_); 1.32 + } 1.33 + virtual ~Win2kThreadPool(); 1.34 + 1.35 + virtual bool RegisterWait(const void* cookie, HANDLE waitable_object, 1.36 + CrossCallIPCCallback callback, 1.37 + void* context); 1.38 + 1.39 + virtual bool UnRegisterWaits(void* cookie); 1.40 + 1.41 + // Returns the total number of wait objects associated with 1.42 + // the thread pool. 1.43 + size_t OutstandingWaits(); 1.44 + 1.45 + private: 1.46 + // record to keep track of a wait and its associated cookie. 1.47 + struct PoolObject { 1.48 + const void* cookie; 1.49 + HANDLE wait; 1.50 + }; 1.51 + // The list of pool wait objects. 1.52 + typedef std::list<PoolObject> PoolObjects; 1.53 + PoolObjects pool_objects_; 1.54 + // This lock protects the list of pool wait objects. 1.55 + CRITICAL_SECTION lock_; 1.56 + DISALLOW_COPY_AND_ASSIGN(Win2kThreadPool); 1.57 +}; 1.58 + 1.59 +} // namespace sandbox 1.60 + 1.61 +#endif // SANDBOX_SRC_WIN2K_THREADPOOL_H_