security/sandbox/win/src/win2k_threadpool.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial