Skip to content

Commit

Permalink
renamed WorkReturnStatus -> work::Status & WorkReturn -> work::Result
Browse files Browse the repository at this point in the history
... hope this makes it a bit easier in terms of naming.
  • Loading branch information
RalphSteinhagen authored and wirew0rm committed Oct 11, 2023
1 parent 3e7f5cd commit 87ff686
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 177 deletions.
10 changes: 5 additions & 5 deletions blocks/basic/include/gnuradio-4.0/basic/clock_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ClockSource Documentation -- add here
while (this->ioThreadShallRun.load()) {
std::this_thread::sleep_until(nextTimePoint);
// invoke and execute work function from user-provided thread
if (this->invokeWork() == WorkReturnStatus::DONE) {
if (this->invokeWork() == work::Status::DONE) {
break;
} else {
retry = 2;
Expand Down Expand Up @@ -89,11 +89,11 @@ ClockSource Documentation -- add here
nextTimePoint = ClockSourceType::now();
}

WorkReturnStatus
work::Status
processBulk(PublishableSpan auto &output) noexcept {
if (n_samples_max > 0 && n_samples_produced >= n_samples_max) {
output.publish(0_UZ);
return WorkReturnStatus::DONE;
return work::Status::DONE;
}

if constexpr (useIoThread) { // using scheduler-graph provided user thread
Expand All @@ -103,7 +103,7 @@ ClockSource Documentation -- add here
const auto writableSamples = static_cast<std::uint32_t>(output.size());
if (writableSamples < chunk_size) {
output.publish(0_UZ);
return WorkReturnStatus::INSUFFICIENT_OUTPUT_ITEMS;
return work::Status::INSUFFICIENT_OUTPUT_ITEMS;
}

const std::uint32_t remaining_samples = n_samples_max - n_samples_produced;
Expand Down Expand Up @@ -139,7 +139,7 @@ ClockSource Documentation -- add here
nextTimePoint += std::chrono::microseconds(static_cast<long>(static_cast<float>(updatePeriod.count()) * ratio));
}

return WorkReturnStatus::OK;
return work::Status::OK;
}
};

Expand Down
6 changes: 3 additions & 3 deletions blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class multi_adder : public gr::BlockModel {
}

// TODO: integrate with Block::work
gr::WorkReturn
gr::work::Result
work(std::size_t requested_work) override {
// TODO: Rewrite with ranges once we can use them
std::size_t available_samples = -1_UZ;
Expand All @@ -153,7 +153,7 @@ class multi_adder : public gr::BlockModel {
}

if (available_samples == 0) {
return { requested_work, 0_UZ, gr::WorkReturnStatus::OK };
return { requested_work, 0_UZ, gr::work::Status::OK };
}

std::vector<std::span<const double>> readers;
Expand All @@ -174,7 +174,7 @@ class multi_adder : public gr::BlockModel {
for (auto &input_port [[maybe_unused]] : _input_ports) {
assert(available_samples == input_port.streamReader().consume(available_samples));
}
return { requested_work, available_samples, gr::WorkReturnStatus::OK };
return { requested_work, available_samples, gr::work::Status::OK };
}

void *
Expand Down
4 changes: 2 additions & 2 deletions blocks/basic/include/gnuradio-4.0/basic/data_sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class data_sink : public Block<data_sink<T>> {
}
}

[[nodiscard]] WorkReturnStatus
[[nodiscard]] work::Status
processBulk(std::span<const T> in_data) noexcept {
std::optional<property_map> tagData;
if (this->input_tags_present()) {
Expand All @@ -500,7 +500,7 @@ class data_sink : public Block<data_sink<T>> {
}
}

return WorkReturnStatus::OK;
return work::Status::OK;
}

private:
Expand Down
6 changes: 3 additions & 3 deletions blocks/basic/include/gnuradio-4.0/basic/selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct Selector : Block<Selector<T>, SelectorDoc> {
using input_reader_t = typename PortIn<T, Async>::ReaderType;
using output_writer_t = typename PortOut<T, Async>::WriterType;

gr::WorkReturnStatus
gr::work::Status
processBulk(select_reader_t *select, //
const std::vector<input_reader_t *> &ins,
monitor_writer_t *monOut, //
Expand All @@ -120,7 +120,7 @@ struct Selector : Block<Selector<T>, SelectorDoc> {
// make the implicit consume all available behaviour explicit
std::for_each(ins.begin(), ins.end(), [](auto *input) { std::ignore = input->consume(input->available()); });
}
return WorkReturnStatus::OK;
return work::Status::OK;
}

std::set<std::size_t> used_inputs;
Expand Down Expand Up @@ -199,7 +199,7 @@ struct Selector : Block<Selector<T>, SelectorDoc> {
}
}

return WorkReturnStatus::OK;
return work::Status::OK;
}
};
} // namespace gr::basic
Expand Down
6 changes: 3 additions & 3 deletions blocks/basic/test/qa_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct repeated_source : public gr::Block<repeated_source<T>> {
}
}

gr::WorkReturn
gr::work::Result
work(std::size_t requested_work) {
if (values_next == values.cend()) {
values_next = values.cbegin();
Expand All @@ -50,10 +50,10 @@ struct repeated_source : public gr::Block<repeated_source<T>> {

values_next++;

return { requested_work, 1UL, gr::WorkReturnStatus::OK };
return { requested_work, 1UL, gr::work::Status::OK };
} else {
// TODO: Investigate what schedulers do when there is an event written, but we return DONE
return { requested_work, 1UL, gr::WorkReturnStatus::DONE };
return { requested_work, 1UL, gr::work::Status::DONE };
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions blocks/fourier/include/gnuradio-4.0/fourier/fft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ On the choice of window (mathematically aka. apodisation) functions
_phaseSpectrum.resize(computeHalfSpectrum ? newSize : (newSize / 2), 0);
}

[[nodiscard]] constexpr WorkReturnStatus
[[nodiscard]] constexpr work::Status
processBulk(std::span<const T> input, std::span<U> output) {
if constexpr (std::is_same_v<T, InDataType>) {
std::copy_n(input.begin(), fftSize, _inData.begin());
Expand Down Expand Up @@ -158,7 +158,7 @@ On the choice of window (mathematically aka. apodisation) functions
static_assert(!std::is_same_v<U, DataSet<float>> && "FFT output type not (yet) implemented");
}

return WorkReturnStatus::OK;
return work::Status::OK;
}

constexpr U
Expand Down
8 changes: 4 additions & 4 deletions blocks/fourier/test/qa_fourier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] {
std::ignore = fftBlock.settings().apply_staged_parameters();
const auto signal{ generateSinSample<InType>(t.N, t.sample_rate, t.frequency, t.amplitude) };
std::vector<OutType> resultingDataSets(1);
expect(gr::WorkReturnStatus::OK == fftBlock.processBulk(signal, resultingDataSets));
expect(gr::work::Status::OK == fftBlock.processBulk(signal, resultingDataSets));

const auto peakIndex{
static_cast<std::size_t>(std::distance(fftBlock._magnitudeSpectrum.begin(),
Expand Down Expand Up @@ -224,7 +224,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] {
expectedPeakAmplitude = 1.;
}
std::vector<OutType> resultingDataSets(1);
expect(gr::WorkReturnStatus::OK == fftBlock.processBulk(signal, resultingDataSets));
expect(gr::work::Status::OK == fftBlock.processBulk(signal, resultingDataSets));

const auto peakIndex{ static_cast<std::size_t>(std::distance(fftBlock._magnitudeSpectrum.begin(), std::ranges::max_element(fftBlock._magnitudeSpectrum))) };
const auto peakAmplitude{ fftBlock._magnitudeSpectrum[peakIndex] };
Expand Down Expand Up @@ -252,7 +252,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] {
std::vector<OutType> v{ OutType() };
std::span<OutType> outSpan(v);

expect(gr::WorkReturnStatus::OK == fftBlock.processBulk(signal, outSpan));
expect(gr::work::Status::OK == fftBlock.processBulk(signal, outSpan));
equalDataset(fftBlock, v[0], sample_rate);
} | typesWithAlgoToTest;

Expand Down Expand Up @@ -338,7 +338,7 @@ const boost::ut::suite<"Fourier Transforms"> fftTests = [] {
std::iota(signal.begin(), signal.end(), 1.);
}
std::vector<OutType> resultingDataSets(1);
expect(gr::WorkReturnStatus::OK == fftBlock.processBulk(signal, resultingDataSets));
expect(gr::work::Status::OK == fftBlock.processBulk(signal, resultingDataSets));

expect(eq(fftBlock.fftSize, N)) << fmt::format("<{}> equal fft size", type_name<T>());
expect(eq(fftBlock._window.size(), N)) << fmt::format("<{}> equal window vector size", type_name<T>());
Expand Down
10 changes: 5 additions & 5 deletions blocks/testing/include/gnuradio-4.0/testing/bm_test_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class source : public gr::Block<source<T, min, count>> {
return x;
}

gr::WorkReturn
gr::work::Result
work(std::size_t requested_work) {
const std::size_t n_to_publish = _n_samples_max - n_samples_produced;
if (n_to_publish > 0) {
Expand All @@ -62,7 +62,7 @@ class source : public gr::Block<source<T, min, count>> {
if constexpr (use_bulk_operation) {
std::size_t n_write = std::clamp(n_to_publish, 0UL, std::min(writer.available(), port.max_buffer_size()));
if (n_write == 0_UZ) {
return { requested_work, 0_UZ, gr::WorkReturnStatus::INSUFFICIENT_INPUT_ITEMS };
return { requested_work, 0_UZ, gr::work::Status::INSUFFICIENT_INPUT_ITEMS };
}

writer.publish( //
Expand All @@ -75,14 +75,14 @@ class source : public gr::Block<source<T, min, count>> {
} else {
auto [data, token] = writer.get(1);
if (data.size() == 0_UZ) {
return { requested_work, 0_UZ, gr::WorkReturnStatus::ERROR };
return { requested_work, 0_UZ, gr::work::Status::ERROR };
}
data[0] = processOne();
writer.publish(token, 1);
}
return { requested_work, 1_UZ, gr::WorkReturnStatus::OK };
return { requested_work, 1_UZ, gr::work::Status::OK };
} else {
return { requested_work, 0_UZ, gr::WorkReturnStatus::DONE };
return { requested_work, 0_UZ, gr::work::Status::DONE };
}
}
};
Expand Down
12 changes: 6 additions & 6 deletions blocks/testing/include/gnuradio-4.0/testing/tag_monitors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct TagSource : public Block<TagSource<T, UseProcessOne>> {
return static_cast<T>(0);
}

WorkReturnStatus
work::Status
processBulk(std::span<T> output) noexcept
requires(UseProcessOne == ProcessFunction::USE_PROCESS_BULK)
{
Expand All @@ -133,7 +133,7 @@ struct TagSource : public Block<TagSource<T, UseProcessOne>> {
}

n_samples_produced += static_cast<std::int64_t>(output.size());
return n_samples_produced < n_samples_max ? WorkReturnStatus::OK : WorkReturnStatus::DONE;
return n_samples_produced < n_samples_max ? work::Status::OK : work::Status::DONE;
}
};

Expand All @@ -158,7 +158,7 @@ struct TagMonitor : public Block<TagMonitor<T, UseProcessOne>> {
return input;
}

constexpr WorkReturnStatus
constexpr work::Status
processBulk(std::span<const T> input, std::span<T> output) noexcept
requires(UseProcessOne == ProcessFunction::USE_PROCESS_BULK)
{
Expand All @@ -172,7 +172,7 @@ struct TagMonitor : public Block<TagMonitor<T, UseProcessOne>> {
n_samples_produced += static_cast<std::int64_t>(input.size());
std::memcpy(output.data(), input.data(), input.size() * sizeof(T));

return WorkReturnStatus::OK;
return work::Status::OK;
}
};

Expand Down Expand Up @@ -204,7 +204,7 @@ struct TagSink : public Block<TagSink<T, UseProcessOne>> {
}

// template<gr::meta::t_or_simd<T> V>
constexpr WorkReturnStatus
constexpr work::Status
processBulk(std::span<const T> input) noexcept
requires(UseProcessOne == ProcessFunction::USE_PROCESS_BULK)
{
Expand All @@ -220,7 +220,7 @@ struct TagSink : public Block<TagSink<T, UseProcessOne>> {

n_samples_produced += static_cast<std::int64_t>(input.size());
timeLastSample = ClockSourceType::now();
return WorkReturnStatus::OK;
return work::Status::OK;
}

float
Expand Down
4 changes: 2 additions & 2 deletions core/benchmarks/bm_fft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ testFFT() {

std::vector<DataSet<PrecisionType>> resultingDataSets(1);
::benchmark::benchmark<nRepetitions>(fmt::format("{} - fftw", type_name<T>())) = [&fft1, &signal, &resultingDataSets] {
expect(gr::WorkReturnStatus::OK == fft1.processBulk(signal, resultingDataSets));
expect(gr::work::Status::OK == fft1.processBulk(signal, resultingDataSets));
};
}
{
Expand All @@ -92,7 +92,7 @@ testFFT() {

std::vector<DataSet<PrecisionType>> resultingDataSets(1);
::benchmark::benchmark<nRepetitions>(fmt::format("{} - fft", type_name<T>())) = [&fft1, &signal, &resultingDataSets] {
expect(gr::WorkReturnStatus::OK == fft1.processBulk(signal, resultingDataSets));
expect(gr::work::Status::OK == fft1.processBulk(signal, resultingDataSets));
};
}

Expand Down
Loading

0 comments on commit 87ff686

Please sign in to comment.