Changeset View
Changeset View
Standalone View
Standalone View
source/lib/file/io/io.h
/* Copyright (c) 2017 Wildfire Games | /* Copyright (c) 2017 Wildfire Games | ||||
Stan: 2020 | |||||
* | * | ||||
* 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 21 Lines | |||||
#include "lib/config2.h" | #include "lib/config2.h" | ||||
#include "lib/alignment.h" | #include "lib/alignment.h" | ||||
#include "lib/bits.h" | #include "lib/bits.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/file/file.h" | #include "lib/file/file.h" | ||||
#include "lib/sysdep/filesystem.h" // wtruncate | #include "lib/sysdep/filesystem.h" // wtruncate | ||||
#include "lib/posix/posix_aio.h" // LIO_READ, LIO_WRITE | #include "lib/posix/posix_aio.h" // LIO_READ, LIO_WRITE | ||||
#include "lib/allocators/unique_range.h" | #include "lib/allocators/unique_ptr_aligned.h" | ||||
namespace ERR | namespace ERR | ||||
{ | { | ||||
const Status IO = -110301; | const Status IO = -110301; | ||||
} | } | ||||
namespace io { | namespace io { | ||||
// @return memory suitable for use as an I/O buffer (address is a | // @return memory suitable for use as an I/O buffer (address is a | ||||
// 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 unique_ptr_aligned Allocate(size_t size, size_t alignment = maxSectorSize) | ||||
{ | { | ||||
return 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, | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
INLINE aiocb& operator[](size_t counter) | INLINE aiocb& operator[](size_t counter) | ||||
{ | { | ||||
return controlBlocks[counter % ARRAY_SIZE(controlBlocks)]; | return controlBlocks[counter % ARRAY_SIZE(controlBlocks)]; | ||||
} | } | ||||
private: | private: | ||||
UniqueRange buffers; | unique_ptr_aligned buffers; | ||||
aiocb controlBlocks[Parameters::maxQueueDepth]; | aiocb controlBlocks[Parameters::maxQueueDepth]; | ||||
}; | }; | ||||
#pragma pack(pop) | #pragma pack(pop) | ||||
LIB_API Status Issue(aiocb& cb, size_t queueDepth); | LIB_API Status Issue(aiocb& cb, size_t queueDepth); | ||||
LIB_API Status WaitUntilComplete(aiocb& cb, size_t queueDepth); | LIB_API Status WaitUntilComplete(aiocb& cb, size_t queueDepth); | ||||
▲ Show 20 Lines • Show All 141 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
2020