Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: Source/modules/webaudio/AudioNode.cpp

Issue 386403002: WebAudio: Split AudioNode::finishDeref into two parts. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 , m_nodeType(NodeTypeUnknown) 48 , m_nodeType(NodeTypeUnknown)
49 , m_context(context) 49 , m_context(context)
50 , m_sampleRate(sampleRate) 50 , m_sampleRate(sampleRate)
51 #if ENABLE(OILPAN) 51 #if ENABLE(OILPAN)
52 , m_keepAlive(adoptPtr(new Persistent<AudioNode>(this))) 52 , m_keepAlive(adoptPtr(new Persistent<AudioNode>(this)))
53 #endif 53 #endif
54 , m_lastProcessingTime(-1) 54 , m_lastProcessingTime(-1)
55 , m_lastNonSilentTime(-1) 55 , m_lastNonSilentTime(-1)
56 , m_normalRefCount(1) // start out with normal refCount == 1 (like WTF::RefC ounted class) 56 , m_normalRefCount(1) // start out with normal refCount == 1 (like WTF::RefC ounted class)
57 , m_connectionRefCount(0) 57 , m_connectionRefCount(0)
58 , m_wasDisconnected(false)
59 , m_isMarkedForDeletion(false) 58 , m_isMarkedForDeletion(false)
60 , m_isDisabled(false) 59 , m_isDisabled(false)
61 , m_channelCount(2) 60 , m_channelCount(2)
62 , m_channelCountMode(Max) 61 , m_channelCountMode(Max)
63 , m_channelInterpretation(AudioBus::Speakers) 62 , m_channelInterpretation(AudioBus::Speakers)
64 { 63 {
65 ScriptWrappable::init(this); 64 ScriptWrappable::init(this);
66 #if DEBUG_AUDIONODE_REFERENCES 65 #if DEBUG_AUDIONODE_REFERENCES
67 if (!s_isNodeCountInitialized) { 66 if (!s_isNodeCountInitialized) {
68 s_isNodeCountInitialized = true; 67 s_isNodeCountInitialized = true;
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 519
521 // Once AudioContext::uninitialize() is called there's no more chances for d eleteMarkedNodes() to get called, so we call here. 520 // Once AudioContext::uninitialize() is called there's no more chances for d eleteMarkedNodes() to get called, so we call here.
522 // We can't call in AudioContext::~AudioContext() since it will never be cal led as long as any AudioNode is alive 521 // We can't call in AudioContext::~AudioContext() since it will never be cal led as long as any AudioNode is alive
523 // because AudioNodes keep a reference to the context. 522 // because AudioNodes keep a reference to the context.
524 if (!context()->isInitialized()) 523 if (!context()->isInitialized())
525 context()->deleteMarkedNodes(); 524 context()->deleteMarkedNodes();
526 } 525 }
527 526
528 void AudioNode::breakConnection() 527 void AudioNode::breakConnection()
529 { 528 {
529 // The actually work for deref happens completely within the audio context's
Raymond Toy 2014/07/14 16:43:01 Typo: "actually" -> "actual"
tkent 2014/07/15 01:19:23 Done. Also fixed it in deref().
530 // graph lock. In the case of the audio thread, we must use a tryLock to
531 // avoid glitches.
532 bool hasLock = false;
533 bool mustReleaseLock = false;
534
535 if (context()->isAudioThread()) {
536 // Real-time audio thread must not contend lock (to avoid glitches).
537 hasLock = context()->tryLock(mustReleaseLock);
538 } else {
539 context()->lock(mustReleaseLock);
540 hasLock = true;
541 }
542
543 if (hasLock) {
544 breakConnectionWithLock();
545
546 if (mustReleaseLock)
547 context()->unlock();
548 } else {
549 // We were unable to get the lock, so put this in a list to finish up
550 // later.
551 ASSERT(context()->isAudioThread());
552 context()->addDeferredBreakConnection(*this);
553 }
554 }
555
556 void AudioNode::breakConnectionWithLock()
557 {
530 ASSERT(m_normalRefCount > 0); 558 ASSERT(m_normalRefCount > 0);
531 atomicDecrement(&m_connectionRefCount); 559 atomicDecrement(&m_connectionRefCount);
532 m_wasDisconnected = true; 560 if (m_connectionRefCount == 0 && m_normalRefCount > 1)
561 disableOutputsIfNecessary();
533 } 562 }
534 563
535 void AudioNode::finishDeref() 564 void AudioNode::finishDeref()
536 { 565 {
537 ASSERT(context()->isGraphOwner()); 566 ASSERT(context()->isGraphOwner());
538 567
539 ASSERT(m_normalRefCount > 0); 568 ASSERT(m_normalRefCount > 0);
540 atomicDecrement(&m_normalRefCount); 569 atomicDecrement(&m_normalRefCount);
541 570
542 #if DEBUG_AUDIONODE_REFERENCES 571 #if DEBUG_AUDIONODE_REFERENCES
543 fprintf(stderr, "%p: %d: AudioNode::deref() %d %d\n", this, nodeType(), m_no rmalRefCount, m_connectionRefCount); 572 fprintf(stderr, "%p: %d: AudioNode::deref() %d %d\n", this, nodeType(), m_no rmalRefCount, m_connectionRefCount);
544 #endif 573 #endif
545 574
546 if (m_wasDisconnected) {
547 if (m_connectionRefCount == 0 && m_normalRefCount > 0)
548 disableOutputsIfNecessary();
549 m_wasDisconnected = false;
550 }
551
552 if (!m_normalRefCount && !m_isMarkedForDeletion) { 575 if (!m_normalRefCount && !m_isMarkedForDeletion) {
553 // All references are gone - we need to go away. 576 // All references are gone - we need to go away.
554 for (unsigned i = 0; i < m_outputs.size(); ++i) 577 for (unsigned i = 0; i < m_outputs.size(); ++i)
555 output(i)->disconnectAll(); // This will deref() nodes we're connect ed to. 578 output(i)->disconnectAll(); // This will deref() nodes we're connect ed to.
556 579
557 // Mark for deletion at end of each render quantum or when context shuts 580 // Mark for deletion at end of each render quantum or when context shuts
558 // down. 581 // down.
559 context()->markForDeletion(this); 582 context()->markForDeletion(this);
560 m_isMarkedForDeletion = true; 583 m_isMarkedForDeletion = true;
561 } 584 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // it cannot be reattached. Therefore, the reference count 619 // it cannot be reattached. Therefore, the reference count
597 // will not go above zero again. 620 // will not go above zero again.
598 ASSERT(m_keepAlive); 621 ASSERT(m_keepAlive);
599 m_keepAlive = nullptr; 622 m_keepAlive = nullptr;
600 } 623 }
601 #endif 624 #endif
602 625
603 } // namespace WebCore 626 } // namespace WebCore
604 627
605 #endif // ENABLE(WEB_AUDIO) 628 #endif // ENABLE(WEB_AUDIO)
OLDNEW
« Source/modules/webaudio/AudioContext.cpp ('K') | « Source/modules/webaudio/AudioNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698