Bug 1760967 [wpt PR 33319] - Pin remaining dependencies in tools/ci/requirements_buil...
[gecko.git] / gfx / vr / gfxVRMutex.h
blobc1145a34d9f16c2966b7432e609bd5048a7b456d
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/. */
7 #ifndef GFX_VR_MUTEX_H
8 #define GFX_VR_MUTEX_H
10 #if defined(XP_WIN)
11 # include "nsTString.h"
12 #endif
14 namespace mozilla {
15 namespace gfx {
17 #if defined(XP_WIN)
18 class WaitForMutex {
19 public:
20 explicit WaitForMutex(HANDLE handle) : mHandle(handle), mStatus(false) {
21 MOZ_ASSERT(mHandle);
23 DWORD dwWaitResult;
24 dwWaitResult = WaitForSingleObject(mHandle, // handle to mutex
25 INFINITE); // no time-out interval
27 switch (dwWaitResult) {
28 // The thread got ownership of the mutex
29 case WAIT_OBJECT_0:
30 mStatus = true;
31 break;
33 // The thread got ownership of an abandoned mutex
34 // The shmem is in an indeterminate state
35 case WAIT_ABANDONED:
36 mStatus = false;
37 break;
38 default:
39 mStatus = false;
40 break;
44 ~WaitForMutex() {
45 if (mHandle && !ReleaseMutex(mHandle)) {
46 # ifdef MOZILLA_INTERNAL_API
47 nsAutoCString msg;
48 msg.AppendPrintf("WaitForMutex %d ReleaseMutex error \"%lu\".", mHandle,
49 GetLastError());
50 NS_WARNING(msg.get());
51 # endif
52 MOZ_ASSERT(false, "Failed to release mutex.");
56 bool GetStatus() { return mStatus; }
58 private:
59 HANDLE mHandle;
60 bool mStatus;
62 #endif
64 } // namespace gfx
65 } // namespace mozilla
67 #endif /* GFX_VR_MUTEX_H */