michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef PlayingRefChangeHandler_h__ michael@0: #define PlayingRefChangeHandler_h__ michael@0: michael@0: #include "nsThreadUtils.h" michael@0: #include "AudioNodeStream.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class PlayingRefChangeHandler : public nsRunnable michael@0: { michael@0: public: michael@0: enum ChangeType { ADDREF, RELEASE }; michael@0: PlayingRefChangeHandler(AudioNodeStream* aStream, ChangeType aChange) michael@0: : mStream(aStream) michael@0: , mChange(aChange) michael@0: { michael@0: } michael@0: michael@0: NS_IMETHOD Run() michael@0: { michael@0: nsRefPtr node; michael@0: { michael@0: // No need to keep holding the lock for the whole duration of this michael@0: // function, since we're holding a strong reference to it, so if michael@0: // we can obtain the reference, we will hold the node alive in michael@0: // this function. michael@0: MutexAutoLock lock(mStream->Engine()->NodeMutex()); michael@0: node = mStream->Engine()->Node(); michael@0: } michael@0: if (node) { michael@0: if (mChange == ADDREF) { michael@0: node->MarkActive(); michael@0: } else if (mChange == RELEASE) { michael@0: node->MarkInactive(); michael@0: } michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: private: michael@0: nsRefPtr mStream; michael@0: ChangeType mChange; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif michael@0: