7 #ifndef PACKAGER_FILE_IO_CACHE_H_
8 #define PACKAGER_FILE_IO_CACHE_H_
13 #include <absl/synchronization/mutex.h>
15 #include <packager/macros/classes.h>
22 explicit IoCache(uint64_t cache_size);
31 uint64_t
Read(
void* buffer, uint64_t size);
40 uint64_t
Write(
const void* buffer, uint64_t size);
67 uint64_t BytesCachedInternal();
68 uint64_t BytesFreeInternal();
70 const uint64_t cache_size_;
72 absl::CondVar read_event_ ABSL_GUARDED_BY(mutex_);
73 absl::CondVar write_event_ ABSL_GUARDED_BY(mutex_);
74 std::vector<uint8_t> circular_buffer_ ABSL_GUARDED_BY(mutex_);
75 const uint8_t* end_ptr_ ABSL_GUARDED_BY(mutex_);
76 uint8_t* r_ptr_ ABSL_GUARDED_BY(mutex_);
77 uint8_t* w_ptr_ ABSL_GUARDED_BY(mutex_);
78 bool closed_ ABSL_GUARDED_BY(mutex_);
80 DISALLOW_COPY_AND_ASSIGN(
IoCache);
Declaration of class which implements a thread-safe circular buffer.
void Clear()
Empties the cache.
uint64_t Write(const void *buffer, uint64_t size)
uint64_t Read(void *buffer, uint64_t size)
void WaitUntilEmptyOrClosed()
Waits until the cache is empty or has been closed.
void Reopen()
Reopens the cache. Any data still in the cache will be lost.
All the methods that are virtual are virtual for mocking.