Commit cc526ece authored by Paal Kvamme's avatar Paal Kvamme
Browse files

Prepare for more smart pointers: Clarify which places depend on the value type sent in delivery_t.

parent d80f9217
......@@ -499,7 +499,7 @@ ZgyInternalBulk::readToExistingBuffer(
brick.survey_position.j0,
brick.survey_position.k0};
const BrickStatus bstatus = brick.status;
auto deliverance = [this,result,start,as_float,bpos,bstatus](const void* raw, std::int64_t rawsize) {
auto deliverance = [this,result,start,as_float,bpos,bstatus](ReadRequest::data_t raw, std::int64_t rawsize) {
this->_deliverOneBrick
(result, start, bpos, raw, rawsize,
bstatus, as_float);
......@@ -983,7 +983,7 @@ ZgyInternalBulk::_deliverOneBrick(
const std::shared_ptr<DataBuffer>& result,
const std::array<std::int64_t,3>& start,
const std::array<std::int64_t,3>& startpos,
const void *raw, std::int64_t rawsize,
ReadRequest::data_t raw, std::int64_t rawsize,
BrickStatus brickstatus, bool as_float) const
{
if (_logger(5))
......
......@@ -16,6 +16,7 @@
#include "../declspec.h"
#include "enum.h"
#include "file.h" // Only for the ReadRequest::data_t typedef
#include <memory>
#include <functional>
......@@ -153,7 +154,7 @@ private:
const std::shared_ptr<DataBuffer>& result,
const std::array<std::int64_t,3>& start,
const std::array<std::int64_t,3>& startpos,
const void *raw, std::int64_t rawsize,
ReadRequest::data_t raw, std::int64_t rawsize,
BrickStatus brickstatus, bool as_float) const;
// --- WRITE SUPPORT ---
......
......@@ -158,7 +158,7 @@ FileADT::_validate_readv(const ReadList& requests, std::int64_t eof, OpenMode mo
void
FileADT::_deliver(
const ReadRequest::delivery_t& fn,
const void *data,
ReadRequest::data_t data,
std::int64_t offset,
std::int64_t size,
bool transient)
......
......@@ -100,7 +100,8 @@ enum class UsageHint
class ReadRequest
{
public:
typedef std::function<void(const void*, std::int64_t)> delivery_t;
typedef const void* data_t;
typedef std::function<void(data_t, std::int64_t)> delivery_t;
std::int64_t offset;
std::int64_t size;
delivery_t delivery;
......@@ -233,7 +234,7 @@ protected:
static void _validate_write(const void *data, std::int64_t offset, std::int64_t size, OpenMode mode);
static void _validate_readv(const ReadList& requests, std::int64_t eof, OpenMode mode);
public: // Actually internal. Used by ConsolidateRequests.
static void _deliver(const ReadRequest::delivery_t& fn, const void *data, std::int64_t offset, std::int64_t size, bool transient);
static void _deliver(const ReadRequest::delivery_t& fn, ReadRequest::data_t data, std::int64_t offset, std::int64_t size, bool transient);
public:
static std::shared_ptr<FileADT> factory(const std::string& filename, OpenMode mode, const OpenZGY::IOContext *iocontext);
......
......@@ -357,7 +357,7 @@ ConsolidateRequests::_consolidated_delivery(
// more performant by having other methods use smart pointers as
// well. But the value of that is questionable.
std::shared_ptr<const ReadList> group_ptr(new ReadList(group));
return [group_ptr,begin](const void *data, std::int64_t size) {
return [group_ptr,begin](ReadRequest::data_t data, std::int64_t size) {
for (const ReadRequest& rr : *group_ptr) {
if (rr.delivery) {
std::int64_t end = std::min(rr.offset + rr.size - begin, size);
......
......@@ -45,17 +45,15 @@ namespace InternalZGY {
* The net effect is similar to using parallel loops at the
* end of SeismicStoreFile::xx_readv() and also in in the
* ConsolidateRequests::_consolidated_delivery() method.
* In that case no additional buffer copy would have been needed. The first place is
* for when bricks were not consolidated and the second for
* when that did happen. The problem is that this may lead
* In that case no additional buffer copy would have been needed.
* The first place is for when bricks were not consolidated and the
* second for when that did happen. The problem is that this may lead
* to nested parallelization.
*
* Hence the code in this file. Which is in any case better
* due to being more modular. The extra buffer copies are bad
* though.
*/
FileParallelizer::FileParallelizer(std::shared_ptr<FileADT> relay, std::int64_t cputhreads)
: FileRelay(relay)
, _cputhreads(cputhreads)
......@@ -103,8 +101,6 @@ FileParallelizer::xx_readv(
// from the caller and pass the transient_ok=false needed here.
// A future caching module might make this trickier.
// The new request list sends the data to our buffers instead of to caller.
ReadList newrequests(requests);
std::vector<std::shared_ptr<char>> buffers(requestcount);
......@@ -113,7 +109,7 @@ FileParallelizer::xx_readv(
std::shared_ptr<char> bufptr(new char[buflen]);
buffers[ii] = bufptr;
newrequests[ii].delivery =
[bufptr,buflen](const void* data, std::int64_t len) {
[bufptr,buflen](ReadRequest::data_t data, std::int64_t len) {
std::cerr << "+";
// TODO-High: Verify: len can be more than requested due to speculative
// caching and less due to encountering EOF. The EOF ought to
......
......@@ -68,7 +68,7 @@ public:
//std::cout << "MyReceiver #" << seq << " was cloned" << std::endl;
}
void operator()(const void* data, std::int64_t size)
void operator()(ReadRequest::data_t data, std::int64_t size)
{
*callcount += 1;
*gotsize = size;
......
......@@ -95,7 +95,7 @@ run_helloworld(const std::string& fn, const std::function<std::shared_ptr<FileAD
char data[100]{0};
file->xx_read(data, 7, 5);
TEST_CHECK(std::string(data) == std::string("world"));
auto sink = [&data](const void *ptr, std::int64_t size) {
auto sink = [&data](ReadRequest::data_t ptr, std::int64_t size) {
memcpy(data, ptr, size);
};
ReadList requests{ ReadRequest(14, 9, sink) };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment