Add ICU message format support
[chromium-blink-merge.git] / sandbox / win / src / win2k_threadpool.cc
blob051cfc1c89d23f626e703ff863430e1397a93156
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 Win2kThreadPool::Win2kThreadPool() {
12 ::InitializeCriticalSection(&lock_);
15 bool Win2kThreadPool::RegisterWait(const void* cookie, HANDLE waitable_object,
16 CrossCallIPCCallback callback,
17 void* context) {
18 if (0 == cookie) {
19 return false;
21 HANDLE pool_object = NULL;
22 // create a wait for a kernel object, with no timeout
23 if (!::RegisterWaitForSingleObject(&pool_object, waitable_object, callback,
24 context, INFINITE, WT_EXECUTEDEFAULT)) {
25 return false;
27 PoolObject pool_obj = {cookie, pool_object};
28 AutoLock lock(&lock_);
29 pool_objects_.push_back(pool_obj);
30 return true;
33 bool Win2kThreadPool::UnRegisterWaits(void* cookie) {
34 if (0 == cookie) {
35 return false;
37 AutoLock lock(&lock_);
38 bool success = true;
39 PoolObjects::iterator it = pool_objects_.begin();
40 while (it != pool_objects_.end()) {
41 if (it->cookie == cookie) {
42 HANDLE wait = it->wait;
43 it = pool_objects_.erase(it);
44 success &= (::UnregisterWaitEx(wait, INVALID_HANDLE_VALUE) != 0);
45 } else {
46 ++it;
49 return success;
52 size_t Win2kThreadPool::OutstandingWaits() {
53 AutoLock lock(&lock_);
54 return pool_objects_.size();
57 Win2kThreadPool::~Win2kThreadPool() {
58 // Here we used to unregister all the pool wait handles. Now, following the
59 // rest of the code we avoid lengthy or blocking calls given that the process
60 // is being torn down.
61 ::DeleteCriticalSection(&lock_);
64 } // namespace sandbox