| OLD | NEW |
| 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 20 matching lines...) Expand all Loading... |
| 31 #include "wtf/PassRefPtr.h" | 31 #include "wtf/PassRefPtr.h" |
| 32 #include "wtf/RefPtr.h" | 32 #include "wtf/RefPtr.h" |
| 33 #include "wtf/ThreadSafeRefCounted.h" | 33 #include "wtf/ThreadSafeRefCounted.h" |
| 34 #include "wtf/Threading.h" | 34 #include "wtf/Threading.h" |
| 35 #include "wtf/ThreadingPrimitives.h" | 35 #include "wtf/ThreadingPrimitives.h" |
| 36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class AbstractAudioContext; | 40 class AbstractAudioContext; |
| 41 class OfflineAudioContext; |
| 41 class AudioHandler; | 42 class AudioHandler; |
| 42 class AudioNodeOutput; | 43 class AudioNodeOutput; |
| 43 class AudioSummingJunction; | 44 class AudioSummingJunction; |
| 44 | 45 |
| 45 // DeferredTaskHandler manages the major part of pre- and post- rendering tasks, | 46 // DeferredTaskHandler manages the major part of pre- and post- rendering tasks, |
| 46 // and provides a lock mechanism against the audio rendering graph. A | 47 // and provides a lock mechanism against the audio rendering graph. A |
| 47 // DeferredTaskHandler object is created when an AbstractAudioContext object is
created. | 48 // DeferredTaskHandler object is created when an AbstractAudioContext object is
created. |
| 48 // | 49 // |
| 49 // DeferredTaskHandler outlives the AbstractAudioContext only if all of the foll
owing | 50 // DeferredTaskHandler outlives the AbstractAudioContext only if all of the foll
owing |
| 50 // conditions match: | 51 // conditions match: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // TODO(hongchan): Use no-barrier load here. (crbug.com/247328) | 104 // TODO(hongchan): Use no-barrier load here. (crbug.com/247328) |
| 104 // | 105 // |
| 105 // It is okay to use a relaxed (no-barrier) load here. Because the data | 106 // It is okay to use a relaxed (no-barrier) load here. Because the data |
| 106 // referenced by m_audioThread is not actually being used, thus we do not | 107 // referenced by m_audioThread is not actually being used, thus we do not |
| 107 // need a barrier between the load of m_audioThread and of that data. | 108 // need a barrier between the load of m_audioThread and of that data. |
| 108 bool isAudioThread() const { return currentThread() == acquireLoad(&m_audioT
hread); } | 109 bool isAudioThread() const { return currentThread() == acquireLoad(&m_audioT
hread); } |
| 109 | 110 |
| 110 void lock(); | 111 void lock(); |
| 111 bool tryLock(); | 112 bool tryLock(); |
| 112 void unlock(); | 113 void unlock(); |
| 114 |
| 115 // This locks the audio render thread for OfflineAudioContext rendering. |
| 116 // MUST NOT be used in the real-time audio context. |
| 117 void offlineLock(); |
| 118 |
| 113 #if ENABLE(ASSERT) | 119 #if ENABLE(ASSERT) |
| 114 // Returns true if this thread owns the context's lock. | 120 // Returns true if this thread owns the context's lock. |
| 115 bool isGraphOwner(); | 121 bool isGraphOwner(); |
| 116 #endif | 122 #endif |
| 117 | 123 |
| 118 class MODULES_EXPORT AutoLocker { | 124 class MODULES_EXPORT AutoLocker { |
| 119 STACK_ALLOCATED(); | 125 STACK_ALLOCATED(); |
| 120 public: | 126 public: |
| 121 explicit AutoLocker(DeferredTaskHandler& handler) | 127 explicit AutoLocker(DeferredTaskHandler& handler) |
| 122 : m_handler(handler) | 128 : m_handler(handler) |
| 123 { | 129 { |
| 124 m_handler.lock(); | 130 m_handler.lock(); |
| 125 } | 131 } |
| 126 explicit AutoLocker(AbstractAudioContext*); | 132 explicit AutoLocker(AbstractAudioContext*); |
| 127 | 133 |
| 128 ~AutoLocker() { m_handler.unlock(); } | 134 ~AutoLocker() { m_handler.unlock(); } |
| 129 | 135 |
| 130 private: | 136 private: |
| 131 DeferredTaskHandler& m_handler; | 137 DeferredTaskHandler& m_handler; |
| 132 }; | 138 }; |
| 133 | 139 |
| 140 // This is for locking offline render thread (which is considered as the |
| 141 // audio thread) with unlocking on self-destruction at the end of the scope. |
| 142 // Also note that it uses lock() rather than tryLock() because the timing |
| 143 // MUST be accurate on offline rendering. |
| 144 class MODULES_EXPORT OfflineGraphAutoLocker { |
| 145 STACK_ALLOCATED(); |
| 146 public: |
| 147 explicit OfflineGraphAutoLocker(OfflineAudioContext*); |
| 148 |
| 149 ~OfflineGraphAutoLocker() { m_handler.unlock(); } |
| 150 |
| 151 private: |
| 152 DeferredTaskHandler& m_handler; |
| 153 }; |
| 154 |
| 134 private: | 155 private: |
| 135 DeferredTaskHandler(); | 156 DeferredTaskHandler(); |
| 136 void updateAutomaticPullNodes(); | 157 void updateAutomaticPullNodes(); |
| 137 void updateChangedChannelCountMode(); | 158 void updateChangedChannelCountMode(); |
| 138 void handleDirtyAudioSummingJunctions(); | 159 void handleDirtyAudioSummingJunctions(); |
| 139 void handleDirtyAudioNodeOutputs(); | 160 void handleDirtyAudioNodeOutputs(); |
| 140 void deleteHandlersOnMainThread(); | 161 void deleteHandlersOnMainThread(); |
| 141 | 162 |
| 142 // For the sake of thread safety, we maintain a seperate Vector of automatic | 163 // For the sake of thread safety, we maintain a seperate Vector of automatic |
| 143 // pull nodes for rendering in m_renderingAutomaticPullNodes. It will be | 164 // pull nodes for rendering in m_renderingAutomaticPullNodes. It will be |
| (...skipping 21 matching lines...) Expand all Loading... |
| 165 Vector<RefPtr<AudioHandler>> m_deletableOrphanHandlers; | 186 Vector<RefPtr<AudioHandler>> m_deletableOrphanHandlers; |
| 166 | 187 |
| 167 // Graph locking. | 188 // Graph locking. |
| 168 RecursiveMutex m_contextGraphMutex; | 189 RecursiveMutex m_contextGraphMutex; |
| 169 volatile ThreadIdentifier m_audioThread; | 190 volatile ThreadIdentifier m_audioThread; |
| 170 }; | 191 }; |
| 171 | 192 |
| 172 } // namespace blink | 193 } // namespace blink |
| 173 | 194 |
| 174 #endif // DeferredTaskHandler_h | 195 #endif // DeferredTaskHandler_h |
| OLD | NEW |