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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.cpp

Issue 2638413004: Don't run removeFinishedSourceNodes with the context lock. (Closed)
Patch Set: Created 3 years, 11 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
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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 // Quadratic worst case, but sizes of both vectors are considered 639 // Quadratic worst case, but sizes of both vectors are considered
640 // manageable, especially |m_finishedSourceNodes| is likely to be short. 640 // manageable, especially |m_finishedSourceNodes| is likely to be short.
641 for (AudioNode* node : m_finishedSourceNodes) { 641 for (AudioNode* node : m_finishedSourceNodes) {
642 size_t i = m_activeSourceNodes.find(node); 642 size_t i = m_activeSourceNodes.find(node);
643 if (i != kNotFound) 643 if (i != kNotFound)
644 m_activeSourceNodes.remove(i); 644 m_activeSourceNodes.remove(i);
645 } 645 }
646 m_finishedSourceNodes.clear(); 646 m_finishedSourceNodes.clear();
647 } 647 }
648 648
649 void BaseAudioContext::releaseFinishedSourceNodes() { 649 bool BaseAudioContext::releaseFinishedSourceNodes() {
650 ASSERT(isGraphOwner()); 650 ASSERT(isGraphOwner());
651 DCHECK(isAudioThread()); 651 DCHECK(isAudioThread());
652 bool didRemove = false; 652 bool didRemove = false;
653 for (AudioHandler* handler : m_finishedSourceHandlers) { 653 for (AudioHandler* handler : m_finishedSourceHandlers) {
654 for (AudioNode* node : m_activeSourceNodes) { 654 for (AudioNode* node : m_activeSourceNodes) {
655 if (m_finishedSourceNodes.contains(node)) 655 if (m_finishedSourceNodes.contains(node))
656 continue; 656 continue;
657 if (handler == &node->handler()) { 657 if (handler == &node->handler()) {
658 handler->breakConnection(); 658 handler->breakConnection();
659 m_finishedSourceNodes.add(node); 659 m_finishedSourceNodes.add(node);
660 didRemove = true; 660 didRemove = true;
661 break; 661 break;
662 } 662 }
663 } 663 }
664 } 664 }
665 if (didRemove) 665 return didRemove;
666 Platform::current()->mainThread()->getWebTaskRunner()->postTask(
667 BLINK_FROM_HERE,
668 crossThreadBind(&BaseAudioContext::removeFinishedSourceNodes,
669 wrapCrossThreadPersistent(this)));
670
671 m_finishedSourceHandlers.clear();
hongchan 2017/01/19 12:47:43 We don't have this line in the patchset anymore. I
Raymond Toy 2017/01/20 19:36:10 Fixed.
672 } 666 }
673 667
674 void BaseAudioContext::notifySourceNodeStartedProcessing(AudioNode* node) { 668 void BaseAudioContext::notifySourceNodeStartedProcessing(AudioNode* node) {
675 DCHECK(isMainThread()); 669 DCHECK(isMainThread());
676 AutoLocker locker(this); 670 AutoLocker locker(this);
677 671
678 m_activeSourceNodes.push_back(node); 672 m_activeSourceNodes.push_back(node);
679 node->handler().makeConnection(); 673 node->handler().makeConnection();
680 } 674 }
681 675
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 } 728 }
735 729
736 void BaseAudioContext::handlePostRenderTasks() { 730 void BaseAudioContext::handlePostRenderTasks() {
737 DCHECK(isAudioThread()); 731 DCHECK(isAudioThread());
738 732
739 // Must use a tryLock() here too. Don't worry, the lock will very rarely be 733 // Must use a tryLock() here too. Don't worry, the lock will very rarely be
740 // contended and this method is called frequently. The worst that can happen 734 // contended and this method is called frequently. The worst that can happen
741 // is that there will be some nodes which will take slightly longer than usual 735 // is that there will be some nodes which will take slightly longer than usual
742 // to be deleted or removed from the render graph (in which case they'll 736 // to be deleted or removed from the render graph (in which case they'll
743 // render silence). 737 // render silence).
738 bool didRemove = false;
744 if (tryLock()) { 739 if (tryLock()) {
745 // Take care of AudioNode tasks where the tryLock() failed previously. 740 // Take care of AudioNode tasks where the tryLock() failed previously.
746 deferredTaskHandler().breakConnections(); 741 deferredTaskHandler().breakConnections();
747 742
748 // Dynamically clean up nodes which are no longer needed. 743 // Dynamically clean up nodes which are no longer needed.
749 releaseFinishedSourceNodes(); 744 didRemove = releaseFinishedSourceNodes();
750 745
751 deferredTaskHandler().handleDeferredTasks(); 746 deferredTaskHandler().handleDeferredTasks();
752 deferredTaskHandler().requestToDeleteHandlersOnMainThread(); 747 deferredTaskHandler().requestToDeleteHandlersOnMainThread();
753 748
754 unlock(); 749 unlock();
755 } 750 }
751
752 if (didRemove) {
753 Platform::current()->mainThread()->getWebTaskRunner()->postTask(
754 BLINK_FROM_HERE,
755 crossThreadBind(&BaseAudioContext::removeFinishedSourceNodes,
756 wrapCrossThreadPersistent(this)));
757 }
756 } 758 }
757 759
758 void BaseAudioContext::resolvePromisesForResumeOnMainThread() { 760 void BaseAudioContext::resolvePromisesForResumeOnMainThread() {
759 DCHECK(isMainThread()); 761 DCHECK(isMainThread());
760 AutoLocker locker(this); 762 AutoLocker locker(this);
761 763
762 for (auto& resolver : m_resumeResolvers) { 764 for (auto& resolver : m_resumeResolvers) {
763 if (m_contextState == Closed) { 765 if (m_contextState == Closed) {
764 resolver->reject(DOMException::create( 766 resolver->reject(DOMException::create(
765 InvalidStateError, "Cannot resume a context that has been closed")); 767 InvalidStateError, "Cannot resume a context that has been closed"));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 } 894 }
893 895
894 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const { 896 SecurityOrigin* BaseAudioContext::getSecurityOrigin() const {
895 if (getExecutionContext()) 897 if (getExecutionContext())
896 return getExecutionContext()->getSecurityOrigin(); 898 return getExecutionContext()->getSecurityOrigin();
897 899
898 return nullptr; 900 return nullptr;
899 } 901 }
900 902
901 } // namespace blink 903 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698