Skip to content

Commit e9f28cc

Browse files
committed
remove task batches
1 parent 15a1a53 commit e9f28cc

File tree

7 files changed

+59
-400
lines changed

7 files changed

+59
-400
lines changed

include/scl/coro/batch.h

Lines changed: 0 additions & 246 deletions
This file was deleted.

include/scl/coro/runtime.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,6 @@ std::coroutine_handle<> FutureAwaiter<FUTURE>::await_suspend(
175175
return m_runtime->next();
176176
}
177177

178-
template <typename RESULT>
179-
std::coroutine_handle<> Batch<RESULT>::await_suspend(
180-
std::coroutine_handle<> coroutine) {
181-
for (auto& task : m_tasks) {
182-
task.setRuntime(m_runtime);
183-
m_runtime->schedule(task.m_handle);
184-
}
185-
186-
m_runtime->schedule(coroutine, [this]() { return await_ready(); });
187-
188-
return m_runtime->next();
189-
}
190-
191-
template <typename RESULT>
192-
std::coroutine_handle<> PartialBatch<RESULT>::await_suspend(
193-
std::coroutine_handle<> coroutine) {
194-
for (auto& task : m_tasks) {
195-
task.setRuntime(m_runtime);
196-
m_runtime->schedule(task.m_handle);
197-
}
198-
199-
m_runtime->schedule(coroutine, [this]() { return await_ready(); });
200-
201-
return m_runtime->next();
202-
}
203-
204178
inline std::coroutine_handle<> SleepAwaiter::await_suspend(
205179
std::coroutine_handle<> handle) {
206180
m_runtime->schedule(handle, m_duration);

include/scl/net/network.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -131,39 +131,6 @@ class Network {
131131
}
132132
}
133133

134-
/**
135-
* @brief Receive data from a subset of parties.
136-
* @param t the minimum number of parties to receive data from.
137-
* @return list of received packets.
138-
*
139-
* Attempts to receive data from all parties, but stops when a Packet has been
140-
* received from at least t parties. The return value is a std::vector of
141-
* size() std::optional elements. Positions with no values correspond to
142-
* parties that did not send anything. Thus, the return value will have at
143-
* least \p t positions with values.
144-
*/
145-
Task<std::vector<std::optional<Packet>>> recv(std::size_t t) {
146-
std::vector<Task<Packet>> recvs;
147-
recvs.reserve(size());
148-
for (std::size_t i = 0; i < size(); i++) {
149-
recvs.emplace_back(party(i)->recv());
150-
}
151-
co_return co_await batch(std::move(recvs), t);
152-
}
153-
154-
/**
155-
* @brief Receive data from all parties on the network.
156-
* @return list of received packets.
157-
*/
158-
Task<std::vector<Packet>> recv() {
159-
std::vector<Task<Packet>> recvs;
160-
recvs.reserve(size());
161-
for (std::size_t i = 0; i < size(); i++) {
162-
recvs.emplace_back(party(i)->recv());
163-
}
164-
co_return co_await batch(std::move(recvs));
165-
}
166-
167134
/**
168135
* @brief The number of parties in this network.
169136
*/

src/scl/net/tcp/network.cc

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include "scl/net/tcp/network.h"
1919

20+
#include <algorithm>
21+
#include <coroutine>
2022
#include <cstdint>
2123
#include <memory>
2224

@@ -100,6 +102,44 @@ scl::Task<SocketAndId> establishConnection(scl::ConnectionInfo party,
100102
throw std::runtime_error("could not establish connection to party");
101103
}
102104

105+
class BatchTask final {
106+
public:
107+
BatchTask(std::vector<scl::Task<SocketAndId>>&& tasks)
108+
: m_tasks(std::move(tasks)), m_runtime(nullptr) {}
109+
110+
bool await_ready() const noexcept {
111+
return std::all_of(m_tasks.begin(), m_tasks.end(), [](const auto& task) {
112+
return task.ready();
113+
});
114+
}
115+
116+
std::coroutine_handle<> await_suspend(std::coroutine_handle<> handle) {
117+
for (auto& task : m_tasks) {
118+
task.setRuntime(m_runtime);
119+
m_runtime->schedule(task.m_handle);
120+
}
121+
m_runtime->schedule(handle, [this]() { return this->await_ready(); });
122+
123+
return m_runtime->next();
124+
}
125+
126+
std::vector<SocketAndId> await_resume() {
127+
std::vector<SocketAndId> results;
128+
for (const auto& task : m_tasks) {
129+
results.emplace_back(task.result());
130+
}
131+
return results;
132+
}
133+
134+
void setRuntime(scl::Runtime* runtime) {
135+
m_runtime = runtime;
136+
}
137+
138+
private:
139+
std::vector<scl::Task<SocketAndId>> m_tasks;
140+
scl::Runtime* m_runtime;
141+
};
142+
103143
} // namespace
104144

105145
scl::Task<scl::Network> scl::createTcpNetwork(const NetworkConfig& config) {
@@ -123,7 +163,7 @@ scl::Task<scl::Network> scl::createTcpNetwork(const NetworkConfig& config) {
123163
}
124164
}
125165

126-
std::vector<SocketAndId> sais = co_await batch(std::move(tasks));
166+
std::vector<SocketAndId> sais = co_await BatchTask(std::move(tasks));
127167

128168
details::sys_call::close(server_socket);
129169

test/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SCL --- Secure Computation Library
2-
# Copyright (C) 2024 Anders Dalskov
2+
# Copyright (C) 2025 Anders Dalskov
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU Affero General Public License as published by
@@ -47,7 +47,6 @@ set(SCL_SOURCE_FILES_TEST
4747
scl/ss/test_pedersen.cc
4848

4949
scl/coro/test_task.cc
50-
scl/coro/test_batch.cc
5150

5251
scl/net/util.cc
5352
scl/net/test_config.cc

0 commit comments

Comments
 (0)