Add unit tests for BufferedIOStream

This commit is contained in:
Simon Fels 2016-12-21 16:27:40 +01:00
commit dbbb8ab795
9 changed files with 177 additions and 24 deletions

View file

@ -1,19 +1,16 @@
/*
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef ANBOX_GRAPHICS_BUFFER_QUEUE_H_
#define ANBOX_GRAPHICS_BUFFER_QUEUE_H_
@ -32,6 +29,10 @@ class BufferQueue {
public:
BufferQueue(size_t capacity);
bool can_push_locked() const { return !closed_ && (count_ < capacity_); }
bool can_pop_locked() const { return count_ > 0U; }
bool is_closed_locked() const { return closed_; }
int try_push_locked(Buffer &&buffer);
int push_locked(Buffer &&buffer, std::unique_lock<std::mutex> &lock);
int try_pop_locked(Buffer *buffer);

View file

@ -105,6 +105,11 @@ void BufferedIOStream::post_data(Buffer &&data) {
in_queue_.push_locked(std::move(data), l);
}
bool BufferedIOStream::needs_data() {
std::unique_lock<std::mutex> l(lock_);
return !in_queue_.can_pop_locked();
}
void BufferedIOStream::thread_main() {
while (true) {
std::unique_lock<std::mutex> l(out_lock_);

View file

@ -44,6 +44,8 @@ class BufferedIOStream : public IOStream {
void forceStop() override;
void post_data(Buffer &&data);
bool needs_data();
private:
void thread_main();

View file

@ -22,6 +22,8 @@
#include "OpenGLESDispatch/EGLDispatch.h"
#include "ErrorLog.h"
#include <stdio.h>
namespace {

View file

@ -27,6 +27,8 @@
#include "anbox/logger.h"
#include "ErrorLog.h"
#include <stdio.h>
#include <glm/glm.hpp>