Skip to content

Commit

Permalink
Replace std::queue with std::deque
Browse files Browse the repository at this point in the history
  • Loading branch information
sbooth committed Jan 15, 2025
1 parent 05be6a4 commit 66a4d57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Sources/CSFBAudioEngine/Player/AudioPlayerNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#import <array>
#import <atomic>
#import <deque>
#import <memory>
#import <mutex>
#import <queue>

#import <os/log.h>

Expand Down
13 changes: 6 additions & 7 deletions Sources/CSFBAudioEngine/Player/SFBAudioPlayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#import <atomic>
#import <cmath>
#import <deque>
#import <mutex>
#import <queue>

#import <objc/runtime.h>

Expand All @@ -28,7 +28,7 @@
/// Objective-C associated object key indicating if a decoder has been canceled
constexpr char _decoderIsCanceledKey = '\0';

using DecoderQueue = std::queue<id <SFBPCMDecoding>>;
using DecoderQueue = std::deque<id <SFBPCMDecoding>>;
const os_log_t _audioPlayerLog = os_log_create("org.sbooth.AudioEngine", "AudioPlayer");

enum AudioPlayerFlags : unsigned int {
Expand Down Expand Up @@ -665,23 +665,22 @@ - (BOOL)internalDecoderQueueIsEmpty
- (void)clearInternalDecoderQueue
{
std::lock_guard<SFB::UnfairLock> lock(_queueLock);
while(!_queuedDecoders.empty())
_queuedDecoders.pop();
_queuedDecoders.resize(0);
}

- (void)pushDecoderToInternalQueue:(id <SFBPCMDecoding>)decoder
{
std::lock_guard<SFB::UnfairLock> lock(_queueLock);
_queuedDecoders.push(decoder);
_queuedDecoders.push_back(decoder);
}

- (id <SFBPCMDecoding>)popDecoderFromInternalQueue
{
std::lock_guard<SFB::UnfairLock> lock(_queueLock);
id <SFBPCMDecoding> decoder = nil;
std::lock_guard<SFB::UnfairLock> lock(_queueLock);
if(!_queuedDecoders.empty()) {
decoder = _queuedDecoders.front();
_queuedDecoders.pop();
_queuedDecoders.pop_front();
}
return decoder;
}
Expand Down

0 comments on commit 66a4d57

Please sign in to comment.