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