Removing dependence on base file atomicops.h
This part of issue #346. Change-Id: Iab685145d10d6e6c99ff666e08bca3c36b6d5a66
This commit is contained in:
parent
ff5945688d
commit
ec63c53ed5
|
@ -13,9 +13,6 @@
|
||||||
|
|
||||||
namespace shaka {
|
namespace shaka {
|
||||||
|
|
||||||
using base::subtle::NoBarrier_Load;
|
|
||||||
using base::subtle::NoBarrier_Store;
|
|
||||||
|
|
||||||
ThreadedIoFile::ThreadedIoFile(std::unique_ptr<File, FileCloser> internal_file,
|
ThreadedIoFile::ThreadedIoFile(std::unique_ptr<File, FileCloser> internal_file,
|
||||||
Mode mode,
|
Mode mode,
|
||||||
uint64_t io_cache_size,
|
uint64_t io_cache_size,
|
||||||
|
@ -74,11 +71,11 @@ int64_t ThreadedIoFile::Read(void* buffer, uint64_t length) {
|
||||||
DCHECK(internal_file_);
|
DCHECK(internal_file_);
|
||||||
DCHECK_EQ(kInputMode, mode_);
|
DCHECK_EQ(kInputMode, mode_);
|
||||||
|
|
||||||
if (NoBarrier_Load(&eof_) && !cache_.BytesCached())
|
if (eof_.load(std::memory_order_relaxed) && !cache_.BytesCached())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (NoBarrier_Load(&internal_file_error_))
|
if (internal_file_error_.load(std::memory_order_relaxed))
|
||||||
return NoBarrier_Load(&internal_file_error_);
|
return internal_file_error_.load(std::memory_order_relaxed);
|
||||||
|
|
||||||
uint64_t bytes_read = cache_.Read(buffer, length);
|
uint64_t bytes_read = cache_.Read(buffer, length);
|
||||||
position_ += bytes_read;
|
position_ += bytes_read;
|
||||||
|
@ -90,8 +87,8 @@ int64_t ThreadedIoFile::Write(const void* buffer, uint64_t length) {
|
||||||
DCHECK(internal_file_);
|
DCHECK(internal_file_);
|
||||||
DCHECK_EQ(kOutputMode, mode_);
|
DCHECK_EQ(kOutputMode, mode_);
|
||||||
|
|
||||||
if (NoBarrier_Load(&internal_file_error_))
|
if (internal_file_error_.load(std::memory_order_relaxed))
|
||||||
return NoBarrier_Load(&internal_file_error_);
|
return internal_file_error_.load(std::memory_order_relaxed);
|
||||||
|
|
||||||
uint64_t bytes_written = cache_.Write(buffer, length);
|
uint64_t bytes_written = cache_.Write(buffer, length);
|
||||||
position_ += bytes_written;
|
position_ += bytes_written;
|
||||||
|
@ -111,7 +108,7 @@ bool ThreadedIoFile::Flush() {
|
||||||
DCHECK(internal_file_);
|
DCHECK(internal_file_);
|
||||||
DCHECK_EQ(kOutputMode, mode_);
|
DCHECK_EQ(kOutputMode, mode_);
|
||||||
|
|
||||||
if (NoBarrier_Load(&internal_file_error_))
|
if (internal_file_error_.load(std::memory_order_relaxed))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
flushing_ = true;
|
flushing_ = true;
|
||||||
|
@ -175,8 +172,8 @@ void ThreadedIoFile::RunInInputMode() {
|
||||||
int64_t read_result =
|
int64_t read_result =
|
||||||
internal_file_->Read(&io_buffer_[0], io_buffer_.size());
|
internal_file_->Read(&io_buffer_[0], io_buffer_.size());
|
||||||
if (read_result <= 0) {
|
if (read_result <= 0) {
|
||||||
NoBarrier_Store(&eof_, read_result == 0);
|
eof_.store(read_result == 0, std::memory_order_relaxed);
|
||||||
NoBarrier_Store(&internal_file_error_, read_result);
|
internal_file_error_.store(read_result, std::memory_order_relaxed);
|
||||||
cache_.Close();
|
cache_.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +203,7 @@ void ThreadedIoFile::RunInOutputMode() {
|
||||||
int64_t write_result = internal_file_->Write(
|
int64_t write_result = internal_file_->Write(
|
||||||
&io_buffer_[bytes_written], write_bytes - bytes_written);
|
&io_buffer_[bytes_written], write_bytes - bytes_written);
|
||||||
if (write_result < 0) {
|
if (write_result < 0) {
|
||||||
NoBarrier_Store(&internal_file_error_, write_result);
|
internal_file_error_.store(write_result, std::memory_order_relaxed);
|
||||||
cache_.Close();
|
cache_.Close();
|
||||||
if (flushing_) {
|
if (flushing_) {
|
||||||
flushing_ = false;
|
flushing_ = false;
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
#ifndef PACKAGER_FILE_THREADED_IO_FILE_H_
|
#ifndef PACKAGER_FILE_THREADED_IO_FILE_H_
|
||||||
#define PACKAGER_FILE_THREADED_IO_FILE_H_
|
#define PACKAGER_FILE_THREADED_IO_FILE_H_
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "packager/base/atomicops.h"
|
|
||||||
#include "packager/base/synchronization/waitable_event.h"
|
#include "packager/base/synchronization/waitable_event.h"
|
||||||
#include "packager/file/file.h"
|
#include "packager/file/file.h"
|
||||||
#include "packager/file/file_closer.h"
|
#include "packager/file/file_closer.h"
|
||||||
|
@ -55,10 +55,10 @@ class ThreadedIoFile : public File {
|
||||||
std::vector<uint8_t> io_buffer_;
|
std::vector<uint8_t> io_buffer_;
|
||||||
uint64_t position_;
|
uint64_t position_;
|
||||||
uint64_t size_;
|
uint64_t size_;
|
||||||
base::subtle::Atomic32 eof_;
|
std::atomic<bool> eof_;
|
||||||
bool flushing_;
|
bool flushing_;
|
||||||
base::WaitableEvent flush_complete_event_;
|
base::WaitableEvent flush_complete_event_;
|
||||||
base::subtle::Atomic32 internal_file_error_;
|
std::atomic<int32_t> internal_file_error_;
|
||||||
// Signalled when thread task exits.
|
// Signalled when thread task exits.
|
||||||
base::WaitableEvent task_exit_event_;
|
base::WaitableEvent task_exit_event_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue