/work/obj-fuzz/dist/include/VRThread.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 GFX_VR_THREAD_H |
8 | | #define GFX_VR_THREAD_H |
9 | | |
10 | | #include "ThreadSafeRefcountingWithMainThreadDestruction.h" |
11 | | #include "base/thread.h" // for Thread |
12 | | |
13 | | namespace mozilla { |
14 | | namespace gfx { |
15 | | |
16 | | class VRListenerThreadHolder final |
17 | | { |
18 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_MAIN_THREAD_DESTRUCTION(VRListenerThreadHolder) |
19 | | |
20 | | public: |
21 | | VRListenerThreadHolder(); |
22 | | |
23 | | base::Thread* GetThread() const { |
24 | | return mThread; |
25 | | } |
26 | | |
27 | | static VRListenerThreadHolder* GetSingleton(); |
28 | | |
29 | 0 | static bool IsActive() { |
30 | 0 | return GetSingleton() && Loop(); |
31 | 0 | } |
32 | | |
33 | | static void Start(); |
34 | | static void Shutdown(); |
35 | | static MessageLoop* Loop(); |
36 | | static bool IsInVRListenerThread(); |
37 | | |
38 | | private: |
39 | | ~VRListenerThreadHolder(); |
40 | | |
41 | | base::Thread* const mThread; |
42 | | |
43 | | static base::Thread* CreateThread(); |
44 | | static void DestroyThread(base::Thread* aThread); |
45 | | }; |
46 | | |
47 | | base::Thread* VRListenerThread(); |
48 | | |
49 | | class VRThread final |
50 | | { |
51 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VRThread) |
52 | | |
53 | | public: |
54 | | explicit VRThread(const nsCString& aName); |
55 | | |
56 | | void Start(); |
57 | | void Shutdown(); |
58 | | void SetLifeTime(uint32_t aLifeTime); |
59 | | uint32_t GetLifeTime(); |
60 | | void CheckLife(TimeStamp aCheckTimestamp); |
61 | | void PostTask(already_AddRefed<Runnable> aTask); |
62 | | void PostDelayedTask(already_AddRefed<Runnable> aTask, uint32_t aTime); |
63 | | const nsCOMPtr<nsIThread> GetThread() const; |
64 | | bool IsActive(); |
65 | | |
66 | | protected: |
67 | | ~VRThread(); |
68 | | |
69 | | private: |
70 | | nsCOMPtr<nsIThread> mThread; |
71 | | TimeStamp mLastActiveTime; |
72 | | nsCString mName; |
73 | | uint32_t mLifeTime; |
74 | | Atomic<bool> mStarted; |
75 | | }; |
76 | | |
77 | | } // namespace gfx |
78 | | } // namespace mozilla |
79 | | |
80 | | #endif // GFX_VR_THREAD_H |