/work/obj-fuzz/dist/include/mozilla/layers/SynchronousTask.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_GFX_SYNCHRONOUSTASK_H |
8 | | #define MOZILLA_GFX_SYNCHRONOUSTASK_H |
9 | | |
10 | | #include "mozilla/ReentrantMonitor.h" // for ReentrantMonitor, etc |
11 | | |
12 | | namespace mozilla { |
13 | | namespace layers { |
14 | | |
15 | | // Helper that creates a monitor and a "done" flag, then enters the monitor. |
16 | | class MOZ_STACK_CLASS SynchronousTask |
17 | | { |
18 | | friend class AutoCompleteTask; |
19 | | |
20 | | public: |
21 | | explicit SynchronousTask(const char* name) |
22 | | : mMonitor(name), |
23 | | mAutoEnter(mMonitor), |
24 | | mDone(false) |
25 | 0 | {} |
26 | | |
27 | 0 | void Wait() { |
28 | 0 | while (!mDone) { |
29 | 0 | mMonitor.Wait(); |
30 | 0 | } |
31 | 0 | } |
32 | | |
33 | | private: |
34 | 0 | void Complete() { |
35 | 0 | mDone = true; |
36 | 0 | mMonitor.NotifyAll(); |
37 | 0 | } |
38 | | |
39 | | private: |
40 | | ReentrantMonitor mMonitor; |
41 | | ReentrantMonitorAutoEnter mAutoEnter; |
42 | | bool mDone; |
43 | | }; |
44 | | |
45 | | class MOZ_STACK_CLASS AutoCompleteTask |
46 | | { |
47 | | public: |
48 | | explicit AutoCompleteTask(SynchronousTask* aTask) |
49 | | : mTask(aTask), |
50 | | mAutoEnter(aTask->mMonitor) |
51 | 0 | { |
52 | 0 | } |
53 | 0 | ~AutoCompleteTask() { |
54 | 0 | mTask->Complete(); |
55 | 0 | } |
56 | | |
57 | | private: |
58 | | SynchronousTask* mTask; |
59 | | ReentrantMonitorAutoEnter mAutoEnter; |
60 | | }; |
61 | | |
62 | | } |
63 | | } |
64 | | |
65 | | #endif |