security/sandbox/win/src/win2k_threadpool.cc

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/sandbox/win/src/win2k_threadpool.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     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 +#include "sandbox/win/src/win2k_threadpool.h"
     1.9 +
    1.10 +#include "sandbox/win/src/win_utils.h"
    1.11 +
    1.12 +namespace sandbox {
    1.13 +
    1.14 +bool Win2kThreadPool::RegisterWait(const void* cookie, HANDLE waitable_object,
    1.15 +                                   CrossCallIPCCallback callback,
    1.16 +                                   void* context) {
    1.17 +  if (0 == cookie) {
    1.18 +    return false;
    1.19 +  }
    1.20 +  HANDLE pool_object = NULL;
    1.21 +  // create a wait for a kernel object, with no timeout
    1.22 +  if (!::RegisterWaitForSingleObject(&pool_object, waitable_object, callback,
    1.23 +                                     context, INFINITE, WT_EXECUTEDEFAULT)) {
    1.24 +    return false;
    1.25 +  }
    1.26 +  PoolObject pool_obj = {cookie, pool_object};
    1.27 +  AutoLock lock(&lock_);
    1.28 +  pool_objects_.push_back(pool_obj);
    1.29 +  return true;
    1.30 +}
    1.31 +
    1.32 +bool Win2kThreadPool::UnRegisterWaits(void* cookie) {
    1.33 +  if (0 == cookie) {
    1.34 +    return false;
    1.35 +  }
    1.36 +  AutoLock lock(&lock_);
    1.37 +  bool success = true;
    1.38 +  PoolObjects::iterator it = pool_objects_.begin();
    1.39 +  while (it != pool_objects_.end()) {
    1.40 +    if (it->cookie == cookie) {
    1.41 +      HANDLE wait = it->wait;
    1.42 +      it = pool_objects_.erase(it);
    1.43 +      success &= (::UnregisterWaitEx(wait, INVALID_HANDLE_VALUE) != 0);
    1.44 +    } else {
    1.45 +      ++it;
    1.46 +    }
    1.47 +  }
    1.48 +  return success;
    1.49 +}
    1.50 +
    1.51 +size_t Win2kThreadPool::OutstandingWaits() {
    1.52 +  AutoLock lock(&lock_);
    1.53 +  return pool_objects_.size();
    1.54 +}
    1.55 +
    1.56 +Win2kThreadPool::~Win2kThreadPool() {
    1.57 +  // Here we used to unregister all the pool wait handles. Now, following the
    1.58 +  // rest of the code we avoid lengthy or blocking calls given that the process
    1.59 +  // is being torn down.
    1.60 +  ::DeleteCriticalSection(&lock_);
    1.61 +}
    1.62 +
    1.63 +}  // namespace sandbox

mercurial