1 // Copyright (C) 2016 The Android Open Source Project
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef ANBOX_GRAPHICS_BUFFER_QUEUE_H_
16 #define ANBOX_GRAPHICS_BUFFER_QUEUE_H_
18 #include "anbox/common/small_vector.h"
20 #include <condition_variable>
26 using Buffer = anbox::common::SmallFixedVector<char, 512>;
30 BufferQueue(size_t capacity);
32 bool can_push_locked() const { return !closed_ && (count_ < capacity_); }
33 bool can_pop_locked() const { return count_ > 0U; }
34 bool is_closed_locked() const { return closed_; }
36 int wait_until_not_empty_locked(std::unique_lock<std::mutex> &lock);
38 int try_push_locked(Buffer &&buffer);
39 int push_locked(Buffer &&buffer, std::unique_lock<std::mutex> &lock);
40 int try_pop_locked(Buffer *buffer);
41 int pop_locked(Buffer *buffer, std::unique_lock<std::mutex> &lock);
49 std::unique_ptr<Buffer[]> buffers_;
51 std::condition_variable can_push_;
52 std::condition_variable can_pop_;
55 } // namespace graphics