From ec63c53ed5c0b30da91fc1af9150b212f99257fc Mon Sep 17 00:00:00 2001 From: Yohann Connell Date: Fri, 13 Jul 2018 15:06:18 -0700 Subject: [PATCH] Removing dependence on base file atomicops.h This part of issue #346. Change-Id: Iab685145d10d6e6c99ff666e08bca3c36b6d5a66 --- packager/file/threaded_io_file.cc | 21 +++++++++------------ packager/file/threaded_io_file.h | 6 +++--- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packager/file/threaded_io_file.cc b/packager/file/threaded_io_file.cc index 86547e3cdd..ff8ca7313a 100644 --- a/packager/file/threaded_io_file.cc +++ b/packager/file/threaded_io_file.cc @@ -13,9 +13,6 @@ namespace shaka { -using base::subtle::NoBarrier_Load; -using base::subtle::NoBarrier_Store; - ThreadedIoFile::ThreadedIoFile(std::unique_ptr internal_file, Mode mode, uint64_t io_cache_size, @@ -74,11 +71,11 @@ int64_t ThreadedIoFile::Read(void* buffer, uint64_t length) { DCHECK(internal_file_); DCHECK_EQ(kInputMode, mode_); - if (NoBarrier_Load(&eof_) && !cache_.BytesCached()) + if (eof_.load(std::memory_order_relaxed) && !cache_.BytesCached()) return 0; - if (NoBarrier_Load(&internal_file_error_)) - return NoBarrier_Load(&internal_file_error_); + if (internal_file_error_.load(std::memory_order_relaxed)) + return internal_file_error_.load(std::memory_order_relaxed); uint64_t bytes_read = cache_.Read(buffer, length); position_ += bytes_read; @@ -90,8 +87,8 @@ int64_t ThreadedIoFile::Write(const void* buffer, uint64_t length) { DCHECK(internal_file_); DCHECK_EQ(kOutputMode, mode_); - if (NoBarrier_Load(&internal_file_error_)) - return NoBarrier_Load(&internal_file_error_); + if (internal_file_error_.load(std::memory_order_relaxed)) + return internal_file_error_.load(std::memory_order_relaxed); uint64_t bytes_written = cache_.Write(buffer, length); position_ += bytes_written; @@ -111,7 +108,7 @@ bool ThreadedIoFile::Flush() { DCHECK(internal_file_); DCHECK_EQ(kOutputMode, mode_); - if (NoBarrier_Load(&internal_file_error_)) + if (internal_file_error_.load(std::memory_order_relaxed)) return false; flushing_ = true; @@ -175,8 +172,8 @@ void ThreadedIoFile::RunInInputMode() { int64_t read_result = internal_file_->Read(&io_buffer_[0], io_buffer_.size()); if (read_result <= 0) { - NoBarrier_Store(&eof_, read_result == 0); - NoBarrier_Store(&internal_file_error_, read_result); + eof_.store(read_result == 0, std::memory_order_relaxed); + internal_file_error_.store(read_result, std::memory_order_relaxed); cache_.Close(); return; } @@ -206,7 +203,7 @@ void ThreadedIoFile::RunInOutputMode() { int64_t write_result = internal_file_->Write( &io_buffer_[bytes_written], write_bytes - bytes_written); if (write_result < 0) { - NoBarrier_Store(&internal_file_error_, write_result); + internal_file_error_.store(write_result, std::memory_order_relaxed); cache_.Close(); if (flushing_) { flushing_ = false; diff --git a/packager/file/threaded_io_file.h b/packager/file/threaded_io_file.h index 91eb2fb4e4..dacfe8c43d 100644 --- a/packager/file/threaded_io_file.h +++ b/packager/file/threaded_io_file.h @@ -7,8 +7,8 @@ #ifndef PACKAGER_FILE_THREADED_IO_FILE_H_ #define PACKAGER_FILE_THREADED_IO_FILE_H_ +#include #include -#include "packager/base/atomicops.h" #include "packager/base/synchronization/waitable_event.h" #include "packager/file/file.h" #include "packager/file/file_closer.h" @@ -55,10 +55,10 @@ class ThreadedIoFile : public File { std::vector io_buffer_; uint64_t position_; uint64_t size_; - base::subtle::Atomic32 eof_; + std::atomic eof_; bool flushing_; base::WaitableEvent flush_complete_event_; - base::subtle::Atomic32 internal_file_error_; + std::atomic internal_file_error_; // Signalled when thread task exits. base::WaitableEvent task_exit_event_;