37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
// Copyright (2019-2024) Paul Scherrer Institute
|
|
|
|
#include "SendBufferControl.h"
|
|
|
|
SendBufferControl::SendBufferControl(const DiffractionExperiment &experiment,
|
|
SendBuffer &in_buffer)
|
|
: buffer(in_buffer) {
|
|
buffer.SetBufferLocationSize(experiment.GetSendBufferLocationSize());
|
|
for (int i = 0; i < buffer.GetNumOfLocations(); i++) {
|
|
send_buffer_avail.Put(i);
|
|
send_buffer_zero_copy_ret_val.push_back(ZeroCopyReturnValue(buffer.GetBufferLocation(i),
|
|
send_buffer_avail,
|
|
i));
|
|
}
|
|
}
|
|
|
|
bool SendBufferControl::CheckIfBufferReturned(std::chrono::microseconds timeout) {
|
|
uint32_t val;
|
|
for (int i = 0; i < buffer.GetNumOfLocations(); i++) {
|
|
if (!send_buffer_avail.GetTimeout(val, timeout))
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
ZeroCopyReturnValue *SendBufferControl::GetBufLocation() {
|
|
uint32_t location;
|
|
if (send_buffer_avail.Get(location))
|
|
return &send_buffer_zero_copy_ret_val[location];
|
|
else
|
|
return nullptr;
|
|
}
|
|
|
|
size_t SendBufferControl::GetAvailBufLocations() {
|
|
return send_buffer_avail.Size();
|
|
}
|