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

Use smart pointers up to and including _deliver(). Still dumb pointers in the functor and above.

parent cc526ece
...@@ -154,9 +154,14 @@ FileADT::_validate_readv(const ReadList& requests, std::int64_t eof, OpenMode mo ...@@ -154,9 +154,14 @@ FileADT::_validate_readv(const ReadList& requests, std::int64_t eof, OpenMode mo
* *
* If the functor states that it needs to retain a pointer then make * If the functor states that it needs to retain a pointer then make
* sure it gets a smart pointer that is aliased to the entire buffer. * sure it gets a smart pointer that is aliased to the entire buffer.
*
* Transition aid, TO BE REMOVED.
* In some places the caller of _deliver() only has an unsafe pointer.
* Typically because it got that pointer from another delivery, and
* the delivery functor itself still just provides a dumb pointer.
*/ */
void void
FileADT::_deliver( FileADT::_deliver_old(
const ReadRequest::delivery_t& fn, const ReadRequest::delivery_t& fn,
ReadRequest::data_t data, ReadRequest::data_t data,
std::int64_t offset, std::int64_t offset,
...@@ -176,6 +181,17 @@ FileADT::_deliver( ...@@ -176,6 +181,17 @@ FileADT::_deliver(
} }
} }
void
FileADT::_deliver(
const ReadRequest::delivery_t& fn,
const std::shared_ptr<const void>& data,
std::int64_t offset,
std::int64_t size,
bool transient)
{
_deliver_old(fn, data.get(), offset, size, transient);
}
std::shared_ptr<FileADT> std::shared_ptr<FileADT>
FileADT::factory(const std::string& filename, OpenMode mode, const IOContext *iocontext) FileADT::factory(const std::string& filename, OpenMode mode, const IOContext *iocontext)
{ {
......
...@@ -234,7 +234,8 @@ protected: ...@@ -234,7 +234,8 @@ protected:
static void _validate_write(const void *data, std::int64_t offset, std::int64_t size, OpenMode mode); 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); static void _validate_readv(const ReadList& requests, std::int64_t eof, OpenMode mode);
public: // Actually internal. Used by ConsolidateRequests. public: // Actually internal. Used by ConsolidateRequests.
static void _deliver(const ReadRequest::delivery_t& fn, ReadRequest::data_t data, std::int64_t offset, std::int64_t size, bool transient); static void _deliver_old(const ReadRequest::delivery_t& fn, ReadRequest::data_t data, std::int64_t offset, std::int64_t size, bool transient);
static void _deliver(const ReadRequest::delivery_t& fn, const std::shared_ptr<const void>& data, std::int64_t offset, std::int64_t size, bool transient);
public: public:
static std::shared_ptr<FileADT> factory(const std::string& filename, OpenMode mode, const OpenZGY::IOContext *iocontext); static std::shared_ptr<FileADT> factory(const std::string& filename, OpenMode mode, const OpenZGY::IOContext *iocontext);
......
...@@ -33,7 +33,7 @@ namespace InternalZGY { ...@@ -33,7 +33,7 @@ namespace InternalZGY {
* *
* COMPLEX TYPES: * COMPLEX TYPES:
* *
* class ReadRequest {offset, size, delivery_functor(buffer*, size)} * class ReadRequest {offset, size, delivery_functor(buffer, size)}
* class RawRequest {seg_number, offset_in_seg, size_in_seg, outpos} * class RawRequest {seg_number, offset_in_seg, size_in_seg, outpos}
* *
* FUNCTION CALL HIERARCHY: * FUNCTION CALL HIERARCHY:
...@@ -363,7 +363,7 @@ ConsolidateRequests::_consolidated_delivery( ...@@ -363,7 +363,7 @@ ConsolidateRequests::_consolidated_delivery(
std::int64_t end = std::min(rr.offset + rr.size - begin, size); std::int64_t end = std::min(rr.offset + rr.size - begin, size);
std::int64_t beg = std::min(rr.offset - begin, end); std::int64_t beg = std::min(rr.offset - begin, end);
// Caller will check the transient_ok flag. we won't. // Caller will check the transient_ok flag. we won't.
FileADT::_deliver(rr.delivery, data, beg, end - beg, false); FileADT::_deliver_old(rr.delivery, data, beg, end - beg, false);
} }
} }
}; };
......
...@@ -258,7 +258,7 @@ LocalFileLinux::xx_readv(const ReadList& requests, bool parallel_ok, bool immuta ...@@ -258,7 +258,7 @@ LocalFileLinux::xx_readv(const ReadList& requests, bool parallel_ok, bool immuta
for (const ReadRequest& r : requests) { for (const ReadRequest& r : requests) {
std::shared_ptr<char> data(new char[r.size]); std::shared_ptr<char> data(new char[r.size]);
this->LocalFileLinux::xx_read(data.get(), r.offset, r.size, usagehint); this->LocalFileLinux::xx_read(data.get(), r.offset, r.size, usagehint);
_deliver(r.delivery, data.get(), 0, r.size, transient_ok); _deliver(r.delivery, data, 0, r.size, transient_ok);
} }
} }
else { else {
...@@ -298,7 +298,7 @@ LocalFileLinux::xx_readv(const ReadList& requests, bool parallel_ok, bool immuta ...@@ -298,7 +298,7 @@ LocalFileLinux::xx_readv(const ReadList& requests, bool parallel_ok, bool immuta
const ReadRequest& r = requests[ii]; const ReadRequest& r = requests[ii];
guard.run([&](){ guard.run([&](){
this->LocalFileLinux::xx_read(data.get(), r.offset, r.size, usagehint); this->LocalFileLinux::xx_read(data.get(), r.offset, r.size, usagehint);
_deliver(r.delivery, data.get(), 0, r.size, transient_ok); _deliver(r.delivery, data, 0, r.size, transient_ok);
}); });
} }
} }
......
...@@ -132,7 +132,7 @@ FileParallelizer::xx_readv( ...@@ -132,7 +132,7 @@ FileParallelizer::xx_readv(
for (std::int64_t ii = 0; ii < requestcount; ++ii) { for (std::int64_t ii = 0; ii < requestcount; ++ii) {
guard.run([&](){ guard.run([&](){
std::cerr << "0123456789"[omp_get_thread_num() % 10]; std::cerr << "0123456789"[omp_get_thread_num() % 10];
_deliver(requests[ii].delivery, buffers[ii].get(), 0, requests[ii].size, transient_ok); _deliver(requests[ii].delivery, buffers[ii], 0, requests[ii].size, transient_ok);
}); });
} }
guard.finished(); guard.finished();
......
...@@ -1155,7 +1155,7 @@ SeismicStoreFile::xx_readv(const ReadList& requests, bool parallel_ok, bool immu ...@@ -1155,7 +1155,7 @@ SeismicStoreFile::xx_readv(const ReadList& requests, bool parallel_ok, bool immu
for (const ReadRequest& r : requests) { for (const ReadRequest& r : requests) {
std::shared_ptr<char> data(new char[r.size]); std::shared_ptr<char> data(new char[r.size]);
this->SeismicStoreFile::xx_read(data.get(), r.offset, r.size, usagehint); this->SeismicStoreFile::xx_read(data.get(), r.offset, r.size, usagehint);
_deliver(r.delivery, data.get(), 0, r.size, transient_ok); _deliver(r.delivery, data, 0, r.size, transient_ok);
} }
return; return;
#endif #endif
...@@ -1296,7 +1296,7 @@ SeismicStoreFile::xx_readv(const ReadList& requests, bool parallel_ok, bool immu ...@@ -1296,7 +1296,7 @@ SeismicStoreFile::xx_readv(const ReadList& requests, bool parallel_ok, bool immu
// TODO-Worry: If this_size != rr.size, can this ever happen? // TODO-Worry: If this_size != rr.size, can this ever happen?
// If yes then we might have lost track of where in the buffer // If yes then we might have lost track of where in the buffer
// we should copy out from. This wory also applies to the Python code. // we should copy out from. This wory also applies to the Python code.
_deliver(rr.delivery, data.get(), pos, this_size, transient_ok); _deliver(rr.delivery, data, pos, this_size, transient_ok);
pos += this_size; pos += this_size;
} }
} }
...@@ -1809,7 +1809,7 @@ SeismicStoreFileDelayedWrite::xx_readv(const ReadList& requests, bool parallel_o ...@@ -1809,7 +1809,7 @@ SeismicStoreFileDelayedWrite::xx_readv(const ReadList& requests, bool parallel_o
for (const ReadRequest& r : requests) { for (const ReadRequest& r : requests) {
std::shared_ptr<char> data(new char[r.size]); std::shared_ptr<char> data(new char[r.size]);
this->SeismicStoreFileDelayedWrite::xx_read(data.get(), r.offset, r.size, usagehint); this->SeismicStoreFileDelayedWrite::xx_read(data.get(), r.offset, r.size, usagehint);
_deliver(r.delivery, data.get(), 0, r.size, transient_ok); _deliver(r.delivery, data, 0, r.size, transient_ok);
} }
} }
} }
......
...@@ -237,7 +237,7 @@ LocalFileWindows::xx_readv(const ReadList& requests, bool parallel_ok, bool immu ...@@ -237,7 +237,7 @@ LocalFileWindows::xx_readv(const ReadList& requests, bool parallel_ok, bool immu
for (const ReadRequest& r : requests) { for (const ReadRequest& r : requests) {
std::unique_ptr<char> data(new char[r.size]); std::unique_ptr<char> data(new char[r.size]);
this->LocalFileWindows::xx_read(data.get(), r.offset, r.size, usagehint); this->LocalFileWindows::xx_read(data.get(), r.offset, r.size, usagehint);
_deliver(r.delivery, data.get(), 0, r.size, transient_ok); _deliver(r.delivery, data, 0, r.size, transient_ok);
} }
} }
......
...@@ -169,13 +169,13 @@ run_test(const ReadList& list_in, ...@@ -169,13 +169,13 @@ run_test(const ReadList& list_in,
// Pretend we read this data file a file. The raw data contains the // Pretend we read this data file a file. The raw data contains the
// offset from the start of the buffer so we can check what was sent. // offset from the start of the buffer so we can check what was sent.
std::vector<int> data(filesize/sizeof(int), 0); std::shared_ptr<int> data(new int[filesize/sizeof(int)]);
for (std::size_t ii=0; ii<data.size(); ++ii) for (std::size_t ii=0; ii<filesize/sizeof(int); ++ii)
data[ii] = sizeof(int)*static_cast<int>(ii); data.get()[ii] = sizeof(int)*static_cast<int>(ii);
// Deliver my data according to the consolidated list. // Deliver my data according to the consolidated list.
for (const ReadRequest& rr : result) for (const ReadRequest& rr : result)
FileADT::_deliver(rr.delivery, data.data(), rr.offset, rr.size, false); FileADT::_deliver(rr.delivery, data, rr.offset, rr.size, false);
// Check that all the data that was originally requested // Check that all the data that was originally requested
// was delivered to the correct place in a timely manner. // was delivered to the correct place in a timely manner.
......
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