This source file includes following definitions.
- Create
- IsValidMap
- MapNoCheck
#include "mojo/system/raw_shared_buffer.h"
#include "base/logging.h"
namespace mojo {
namespace system {
RawSharedBuffer* RawSharedBuffer::Create(size_t num_bytes) {
DCHECK_GT(num_bytes, 0u);
RawSharedBuffer* rv = new RawSharedBuffer(num_bytes);
if (!rv->InitNoLock())
return NULL;
return rv;
}
scoped_ptr<RawSharedBufferMapping> RawSharedBuffer::Map(size_t offset,
size_t length) {
if (!IsValidMap(offset, length))
return scoped_ptr<RawSharedBufferMapping>();
return MapNoCheck(offset, length);
}
bool RawSharedBuffer::IsValidMap(size_t offset, size_t length) {
if (offset > num_bytes_ || length == 0)
return false;
if (length > num_bytes_ - offset)
return false;
return true;
}
scoped_ptr<RawSharedBufferMapping> RawSharedBuffer::MapNoCheck(size_t offset,
size_t length) {
DCHECK(IsValidMap(offset, length));
base::AutoLock locker(lock_);
return MapImplNoLock(offset, length);
}
RawSharedBuffer::RawSharedBuffer(size_t num_bytes) : num_bytes_(num_bytes) {
}
RawSharedBuffer::~RawSharedBuffer() {
}
}
}