security/sandbox/win/src/win2k_threadpool.cc

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 #include "sandbox/win/src/win2k_threadpool.h"
michael@0 6
michael@0 7 #include "sandbox/win/src/win_utils.h"
michael@0 8
michael@0 9 namespace sandbox {
michael@0 10
michael@0 11 bool Win2kThreadPool::RegisterWait(const void* cookie, HANDLE waitable_object,
michael@0 12 CrossCallIPCCallback callback,
michael@0 13 void* context) {
michael@0 14 if (0 == cookie) {
michael@0 15 return false;
michael@0 16 }
michael@0 17 HANDLE pool_object = NULL;
michael@0 18 // create a wait for a kernel object, with no timeout
michael@0 19 if (!::RegisterWaitForSingleObject(&pool_object, waitable_object, callback,
michael@0 20 context, INFINITE, WT_EXECUTEDEFAULT)) {
michael@0 21 return false;
michael@0 22 }
michael@0 23 PoolObject pool_obj = {cookie, pool_object};
michael@0 24 AutoLock lock(&lock_);
michael@0 25 pool_objects_.push_back(pool_obj);
michael@0 26 return true;
michael@0 27 }
michael@0 28
michael@0 29 bool Win2kThreadPool::UnRegisterWaits(void* cookie) {
michael@0 30 if (0 == cookie) {
michael@0 31 return false;
michael@0 32 }
michael@0 33 AutoLock lock(&lock_);
michael@0 34 bool success = true;
michael@0 35 PoolObjects::iterator it = pool_objects_.begin();
michael@0 36 while (it != pool_objects_.end()) {
michael@0 37 if (it->cookie == cookie) {
michael@0 38 HANDLE wait = it->wait;
michael@0 39 it = pool_objects_.erase(it);
michael@0 40 success &= (::UnregisterWaitEx(wait, INVALID_HANDLE_VALUE) != 0);
michael@0 41 } else {
michael@0 42 ++it;
michael@0 43 }
michael@0 44 }
michael@0 45 return success;
michael@0 46 }
michael@0 47
michael@0 48 size_t Win2kThreadPool::OutstandingWaits() {
michael@0 49 AutoLock lock(&lock_);
michael@0 50 return pool_objects_.size();
michael@0 51 }
michael@0 52
michael@0 53 Win2kThreadPool::~Win2kThreadPool() {
michael@0 54 // Here we used to unregister all the pool wait handles. Now, following the
michael@0 55 // rest of the code we avoid lengthy or blocking calls given that the process
michael@0 56 // is being torn down.
michael@0 57 ::DeleteCriticalSection(&lock_);
michael@0 58 }
michael@0 59
michael@0 60 } // namespace sandbox

mercurial