Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/lib/file/io/io.h
/* Copyright (c) 2011 Wildfire Games | /* Copyright (c) 2017 Wildfire Games | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
Show All 39 Lines | |||||
// multiple of alignment, size is rounded up to a multiple of alignment) | // multiple of alignment, size is rounded up to a multiple of alignment) | ||||
// @param alignment is automatically increased if smaller than the | // @param alignment is automatically increased if smaller than the | ||||
// UniqueRange requirement. | // UniqueRange requirement. | ||||
// | // | ||||
// use this instead of the file cache for write buffers that are | // use this instead of the file cache for write buffers that are | ||||
// never reused (avoids displacing other items). | // never reused (avoids displacing other items). | ||||
static inline UniqueRange Allocate(size_t size, size_t alignment = maxSectorSize) | static inline UniqueRange Allocate(size_t size, size_t alignment = maxSectorSize) | ||||
{ | { | ||||
return std::move(AllocateAligned(size, alignment)); | return AllocateAligned(size, alignment); | ||||
} | } | ||||
#pragma pack(push, 1) | #pragma pack(push, 1) | ||||
// required information for any I/O (this is basically the same as aiocb, | // required information for any I/O (this is basically the same as aiocb, | ||||
// but also applies to synchronous I/O and has shorter/nicer names.) | // but also applies to synchronous I/O and has shorter/nicer names.) | ||||
struct Operation | struct Operation | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | |||||
public: | public: | ||||
ControlBlockRingBuffer(const Operation& op, const Parameters& p) | ControlBlockRingBuffer(const Operation& op, const Parameters& p) | ||||
: controlBlocks() // zero-initialize | : controlBlocks() // zero-initialize | ||||
{ | { | ||||
const size_t blockSize = p.blockSize? p.blockSize : (size_t)op.size; | const size_t blockSize = p.blockSize? p.blockSize : (size_t)op.size; | ||||
const bool temporaryBuffersRequested = (op.buf == 0); | const bool temporaryBuffersRequested = (op.buf == 0); | ||||
if(temporaryBuffersRequested) | if(temporaryBuffersRequested) | ||||
buffers = std::move(io::Allocate(blockSize * p.queueDepth, p.alignment)); | buffers = io::Allocate(blockSize * p.queueDepth, p.alignment); | ||||
for(size_t i = 0; i < ARRAY_SIZE(controlBlocks); i++) | for(size_t i = 0; i < ARRAY_SIZE(controlBlocks); i++) | ||||
{ | { | ||||
aiocb& cb = operator[](i); | aiocb& cb = operator[](i); | ||||
cb.aio_fildes = op.fd; | cb.aio_fildes = op.fd; | ||||
cb.aio_nbytes = blockSize; | cb.aio_nbytes = blockSize; | ||||
cb.aio_lio_opcode = op.opcode; | cb.aio_lio_opcode = op.opcode; | ||||
if(temporaryBuffersRequested) | if(temporaryBuffersRequested) | ||||
▲ Show 20 Lines • Show All 160 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator