12 #ifndef __NET_THREADEDIO_H__
13 #define __NET_THREADEDIO_H__
35 virtual ~
Task() =
default;
38 virtual void invoke() = 0;
39 virtual exint memoryEstimate()
const = 0;
47 myClb(std::move(callable)),
68 myStrand(hboost::asio::make_strand(ctx.get_executor())),
77 exint cost = task->memoryEstimate();
84 if (cost && myMaxCost >= 0 && (myCurrentCost > 0)
85 && (myCurrentCost + cost > myMaxCost))
88 myCond.waitForTrigger(myLock);
96 myCurrentCost += cost;
98 hboost::asio::post(myStrand, [
this, work_task = std::move(task), cost]() {
101 myCurrentCost -= cost;
115 postTask(UTmakeUnique<CallableTask>(std::move(
func), cost));
126 hboost::asio::strand<hboost::asio::io_context::executor_type> myStrand;
132 #endif // __NET_THREADEDIO_H__
NET_API NET_ThreadedIO * NETgetThreadedIO()
NET_ThreadedIO(ASIO_IOContext &ctx, exint max_cost=0)
Base Class to perform IO thread tasks.
void postTask(UT_Function< void()> func, exint cost=0)
Condition synchronization primitive.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
virtual exint memoryEstimate() const =0
void postTask(UT_UniquePtr< Task > task)
hboost::asio::io_context ASIO_IOContext
std::function< T > UT_Function