/src/mozilla-central/gfx/layers/apz/util/APZThreadUtils.cpp
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 | | #include "mozilla/layers/APZThreadUtils.h" |
8 | | |
9 | | namespace mozilla { |
10 | | namespace layers { |
11 | | |
12 | | static bool sThreadAssertionsEnabled = true; |
13 | | static MessageLoop* sControllerThread; |
14 | | |
15 | | /*static*/ void |
16 | 0 | APZThreadUtils::SetThreadAssertionsEnabled(bool aEnabled) { |
17 | 0 | sThreadAssertionsEnabled = aEnabled; |
18 | 0 | } |
19 | | |
20 | | /*static*/ bool |
21 | 0 | APZThreadUtils::GetThreadAssertionsEnabled() { |
22 | 0 | return sThreadAssertionsEnabled; |
23 | 0 | } |
24 | | |
25 | | /*static*/ void |
26 | | APZThreadUtils::SetControllerThread(MessageLoop* aLoop) |
27 | 0 | { |
28 | 0 | // We must either be setting the initial controller thread, or removing it, |
29 | 0 | // or re-using an existing controller thread. |
30 | 0 | MOZ_ASSERT(!sControllerThread || !aLoop || sControllerThread == aLoop); |
31 | 0 | sControllerThread = aLoop; |
32 | 0 | } |
33 | | |
34 | | /*static*/ void |
35 | 0 | APZThreadUtils::AssertOnControllerThread() { |
36 | 0 | if (!GetThreadAssertionsEnabled()) { |
37 | 0 | return; |
38 | 0 | } |
39 | 0 | |
40 | 0 | MOZ_ASSERT(sControllerThread == MessageLoop::current()); |
41 | 0 | } |
42 | | |
43 | | /*static*/ void |
44 | | APZThreadUtils::RunOnControllerThread(already_AddRefed<Runnable> aTask) |
45 | 0 | { |
46 | 0 | RefPtr<Runnable> task = aTask; |
47 | 0 |
|
48 | 0 | if (!sControllerThread) { |
49 | 0 | // Could happen on startup |
50 | 0 | NS_WARNING("Dropping task posted to controller thread"); |
51 | 0 | return; |
52 | 0 | } |
53 | 0 |
|
54 | 0 | if (sControllerThread == MessageLoop::current()) { |
55 | 0 | task->Run(); |
56 | 0 | } else { |
57 | 0 | sControllerThread->PostTask(task.forget()); |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | /*static*/ bool |
62 | | APZThreadUtils::IsControllerThread() |
63 | 0 | { |
64 | 0 | return sControllerThread == MessageLoop::current(); |
65 | 0 | } |
66 | | |
67 | | NS_IMPL_ISUPPORTS(GenericNamedTimerCallbackBase, nsITimerCallback, nsINamed) |
68 | | |
69 | | } // namespace layers |
70 | | } // namespace mozilla |