12 #ifndef __NET_THREADEDIO_H__
13 #define __NET_THREADEDIO_H__
35 virtual ~
Task() =
default;
39 virtual exint memoryEstimate()
const = 0;
47 myClb(std::move(callable)),
68 : myStrand(hboost::asio::make_strand(exc))
78 exint cost = task->memoryEstimate();
85 if (cost && myMaxCost >= 0 && (myCurrentCost > 0)
86 && (myCurrentCost + cost > myMaxCost))
89 myCond.waitForTrigger(myLock);
97 myCurrentCost += cost;
99 hboost::asio::post(myStrand, [
this, work_task = std::move(task), cost]() {
102 myCurrentCost -= cost;
116 postTask(UTmakeUnique<CallableTask>(std::move(
func), cost));
127 hboost::asio::strand<hboost::asio::io_context::executor_type> myStrand;
133 #endif // __NET_THREADEDIO_H__
NET_API NET_ThreadedIO * NETgetThreadedIO()
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.
NET_ThreadedIO(const ASIO_IOContext::executor_type &exc, exint max_cost=0)
#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)
std::function< T > UT_Function
int invoke(const Func &taskFunc1, Rest...taskFuncN)