Bug 1699062 - Flatten toolkit/themes/*/global/alerts/. r=desktop-theme-reviewers,dao
[gecko.git] / gfx / vr / gfxVRMutex.h
bloba54b8dc8b0d83bbcdfd47f6fafac608312441c0c
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 namespace mozilla {
11 namespace gfx {
13 #if defined(XP_WIN)
14 class WaitForMutex {
15 public:
16 explicit WaitForMutex(HANDLE handle) : mHandle(handle), mStatus(false) {
17 MOZ_ASSERT(mHandle);
19 DWORD dwWaitResult;
20 dwWaitResult = WaitForSingleObject(mHandle, // handle to mutex
21 INFINITE); // no time-out interval
23 switch (dwWaitResult) {
24 // The thread got ownership of the mutex
25 case WAIT_OBJECT_0:
26 mStatus = true;
27 break;
29 // The thread got ownership of an abandoned mutex
30 // The shmem is in an indeterminate state
31 case WAIT_ABANDONED:
32 mStatus = false;
33 break;
34 default:
35 mStatus = false;
36 break;
40 ~WaitForMutex() {
41 if (mHandle && !ReleaseMutex(mHandle)) {
42 # ifdef MOZILLA_INTERNAL_API
43 nsAutoCString msg;
44 msg.AppendPrintf("WaitForMutex %d ReleaseMutex error \"%lu\".", mHandle,
45 GetLastError());
46 NS_WARNING(msg.get());
47 # endif
48 MOZ_ASSERT(false, "Failed to release mutex.");
52 bool GetStatus() { return mStatus; }
54 private:
55 HANDLE mHandle;
56 bool mStatus;
58 #endif
60 } // namespace gfx
61 } // namespace mozilla
63 #endif /* GFX_VR_MUTEX_H */