mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 15:27:34 +00:00
LibCore: Remove try_
prefix from fallible SharedCircularQueue methods
This commit is contained in:
parent
65fa7db2b5
commit
108ea2b921
6 changed files with 36 additions and 36 deletions
|
@ -22,7 +22,7 @@ namespace Audio {
|
|||
|
||||
ConnectionToServer::ConnectionToServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
||||
: IPC::ConnectionToServer<AudioClientEndpoint, AudioServerEndpoint>(*this, move(socket))
|
||||
, m_buffer(make<AudioQueue>(MUST(AudioQueue::try_create())))
|
||||
, m_buffer(make<AudioQueue>(MUST(AudioQueue::create())))
|
||||
, m_user_queue(make<UserSampleQueue>())
|
||||
, m_background_audio_enqueuer(Threading::Thread::construct([this]() {
|
||||
// All the background thread does is run an event loop.
|
||||
|
@ -105,7 +105,7 @@ void ConnectionToServer::custom_event(Core::CustomEvent&)
|
|||
m_user_queue->discard_samples(available_samples);
|
||||
|
||||
// FIXME: Could we receive interrupts in a good non-IPC way instead?
|
||||
auto result = m_buffer->try_blocking_enqueue(next_chunk, [this]() {
|
||||
auto result = m_buffer->blocking_enqueue(next_chunk, [this]() {
|
||||
nanosleep(&m_good_sleep_time, nullptr);
|
||||
});
|
||||
if (result.is_error())
|
||||
|
@ -115,12 +115,12 @@ void ConnectionToServer::custom_event(Core::CustomEvent&)
|
|||
|
||||
ErrorOr<void, AudioQueue::QueueStatus> ConnectionToServer::realtime_enqueue(Array<Sample, AUDIO_BUFFER_SIZE> samples)
|
||||
{
|
||||
return m_buffer->try_enqueue(samples);
|
||||
return m_buffer->enqueue(samples);
|
||||
}
|
||||
|
||||
ErrorOr<void> ConnectionToServer::blocking_realtime_enqueue(Array<Sample, AUDIO_BUFFER_SIZE> samples, Function<void()> wait_function)
|
||||
{
|
||||
return m_buffer->try_blocking_enqueue(samples, move(wait_function));
|
||||
return m_buffer->blocking_enqueue(samples, move(wait_function));
|
||||
}
|
||||
|
||||
unsigned ConnectionToServer::total_played_samples() const
|
||||
|
|
|
@ -62,16 +62,16 @@ public:
|
|||
SharedSingleProducerCircularQueue& operator=(SharedSingleProducerCircularQueue&& queue) = default;
|
||||
|
||||
// Allocates a new circular queue in shared memory.
|
||||
static ErrorOr<SharedSingleProducerCircularQueue<T, Size>> try_create()
|
||||
static ErrorOr<SharedSingleProducerCircularQueue<T, Size>> create()
|
||||
{
|
||||
auto fd = TRY(System::anon_create(sizeof(SharedMemorySPCQ), O_CLOEXEC));
|
||||
return try_create_internal(fd, true);
|
||||
return create_internal(fd, true);
|
||||
}
|
||||
|
||||
// Uses an existing circular queue from given shared memory.
|
||||
static ErrorOr<SharedSingleProducerCircularQueue<T, Size>> try_create(int fd)
|
||||
static ErrorOr<SharedSingleProducerCircularQueue<T, Size>> create(int fd)
|
||||
{
|
||||
return try_create_internal(fd, false);
|
||||
return create_internal(fd, false);
|
||||
}
|
||||
|
||||
constexpr size_t size() const { return Size; }
|
||||
|
@ -90,7 +90,7 @@ public:
|
|||
ALWAYS_INLINE constexpr size_t weak_head() const { return m_queue->m_queue->m_head.load(AK::MemoryOrder::memory_order_relaxed); }
|
||||
ALWAYS_INLINE constexpr size_t weak_tail() const { return m_queue->m_queue->m_tail.load(AK::MemoryOrder::memory_order_relaxed); }
|
||||
|
||||
ErrorOr<void, QueueStatus> try_enqueue(ValueType to_insert)
|
||||
ErrorOr<void, QueueStatus> enqueue(ValueType to_insert)
|
||||
{
|
||||
VERIFY(!m_queue.is_null());
|
||||
if (!can_enqueue())
|
||||
|
@ -108,11 +108,11 @@ public:
|
|||
}
|
||||
|
||||
// Repeatedly try to enqueue, using the wait_function to wait if it's not possible
|
||||
ErrorOr<void> try_blocking_enqueue(ValueType to_insert, Function<void()> wait_function)
|
||||
ErrorOr<void> blocking_enqueue(ValueType to_insert, Function<void()> wait_function)
|
||||
{
|
||||
ErrorOr<void, QueueStatus> result;
|
||||
while (true) {
|
||||
result = try_enqueue(to_insert);
|
||||
result = enqueue(to_insert);
|
||||
if (!result.is_error())
|
||||
break;
|
||||
if (result.error() != QueueStatus::Full)
|
||||
|
@ -123,7 +123,7 @@ public:
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<ValueType, QueueStatus> try_dequeue()
|
||||
ErrorOr<ValueType, QueueStatus> dequeue()
|
||||
{
|
||||
VERIFY(!m_queue.is_null());
|
||||
while (true) {
|
||||
|
@ -198,7 +198,7 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
static ErrorOr<SharedSingleProducerCircularQueue<T, Size>> try_create_internal(int fd, bool is_new)
|
||||
static ErrorOr<SharedSingleProducerCircularQueue<T, Size>> create_internal(int fd, bool is_new)
|
||||
{
|
||||
auto name = DeprecatedString::formatted("SharedSingleProducerCircularQueue@{:x}", fd);
|
||||
auto* raw_mapping = TRY(System::mmap(nullptr, sizeof(SharedMemorySPCQ), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0, 0, name));
|
||||
|
|
|
@ -137,7 +137,7 @@ template<Concepts::SharedSingleProducerCircularQueue T>
|
|||
ErrorOr<T> decode(Decoder& decoder)
|
||||
{
|
||||
auto anon_file = TRY(decoder.decode<IPC::File>());
|
||||
return T::try_create(anon_file.take_fd());
|
||||
return T::create(anon_file.take_fd());
|
||||
}
|
||||
|
||||
template<Concepts::Optional T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue