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.

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

mercurial