This source file includes following definitions.
- InitializeSharedMemory
- FetchFromBuffer
#include "shared_memory_seqlock_reader.h"
namespace internal {
SharedMemorySeqLockReaderBase::SharedMemorySeqLockReaderBase() { }
SharedMemorySeqLockReaderBase::~SharedMemorySeqLockReaderBase() { }
void*
SharedMemorySeqLockReaderBase::InitializeSharedMemory(
base::SharedMemoryHandle shared_memory_handle, size_t buffer_size) {
renderer_shared_memory_handle_ = shared_memory_handle;
if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_))
return 0;
renderer_shared_memory_.reset(new base::SharedMemory(
renderer_shared_memory_handle_, true));
return (renderer_shared_memory_->Map(buffer_size))
? renderer_shared_memory_->memory()
: 0;
}
bool SharedMemorySeqLockReaderBase::FetchFromBuffer(
content::OneWriterSeqLock* seqlock, void* final, void* temp, void* from,
size_t size) {
if (!base::SharedMemory::IsHandleValid(renderer_shared_memory_handle_))
return false;
int contention_count = -1;
base::subtle::Atomic32 version;
do {
version = seqlock->ReadBegin();
memcpy(temp, from, size);
++contention_count;
if (contention_count == kMaximumContentionCount)
break;
} while (seqlock->ReadRetry(version));
if (contention_count >= kMaximumContentionCount) {
return false;
}
memcpy(final, temp, size);
return true;
}
}