content/media/webaudio/PlayingRefChangeHandler.h

branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
equal deleted inserted replaced
-1:000000000000 0:9a8a4f65f4ca
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 PlayingRefChangeHandler_h__
8 #define PlayingRefChangeHandler_h__
9
10 #include "nsThreadUtils.h"
11 #include "AudioNodeStream.h"
12
13 namespace mozilla {
14 namespace dom {
15
16 class PlayingRefChangeHandler : public nsRunnable
17 {
18 public:
19 enum ChangeType { ADDREF, RELEASE };
20 PlayingRefChangeHandler(AudioNodeStream* aStream, ChangeType aChange)
21 : mStream(aStream)
22 , mChange(aChange)
23 {
24 }
25
26 NS_IMETHOD Run()
27 {
28 nsRefPtr<AudioNode> node;
29 {
30 // No need to keep holding the lock for the whole duration of this
31 // function, since we're holding a strong reference to it, so if
32 // we can obtain the reference, we will hold the node alive in
33 // this function.
34 MutexAutoLock lock(mStream->Engine()->NodeMutex());
35 node = mStream->Engine()->Node();
36 }
37 if (node) {
38 if (mChange == ADDREF) {
39 node->MarkActive();
40 } else if (mChange == RELEASE) {
41 node->MarkInactive();
42 }
43 }
44 return NS_OK;
45 }
46
47 private:
48 nsRefPtr<AudioNodeStream> mStream;
49 ChangeType mChange;
50 };
51
52 }
53 }
54
55 #endif
56

mercurial