Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/SDK/threadPool.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 | |
| 3 #include <functional> | |
| 4 namespace fb2k { | |
| 5 void inWorkerThread(std::function<void()> f); | |
| 6 void inCpuWorkerThread(std::function<void()> f); | |
| 7 | |
| 8 //! \since 2.0 | |
| 9 class threadEntry : public service_base { | |
| 10 FB2K_MAKE_SERVICE_INTERFACE(threadEntry, service_base); | |
| 11 public: | |
| 12 virtual void run() = 0; | |
| 13 | |
| 14 static threadEntry::ptr make(std::function<void()> f); | |
| 15 }; | |
| 16 | |
| 17 //! \since 2.0 | |
| 18 //! A class interfacing with shared pool of threads intended for use with CPU bound tasks. \n | |
| 19 //! Use this instead of creating threads directly to avoid making the system unresponsive by creating too many CPU bound threads. | |
| 20 class cpuThreadPool : public service_base { | |
| 21 FB2K_MAKE_SERVICE_COREAPI(cpuThreadPool); | |
| 22 public: | |
| 23 //! Run one time task on a thread pool. Returns immediately. | |
| 24 virtual void runSingle(threadEntry::ptr trd) = 0; | |
| 25 //! Run the task multiple times concurrently. Optionally block until all done. \n | |
| 26 //! Exceptions: if nonblocking, they're discarded; if blocking; rethrown to caller. If multiple are thrown, one of them is rethrown, precedence undefined. | |
| 27 virtual void runMulti(threadEntry::ptr trd, size_t numRuns, bool blocking) = 0; | |
| 28 | |
| 29 virtual size_t numRunsSanity(size_t suggested) = 0; | |
| 30 | |
| 31 //! Helper around blocking runMulti(), with fallback for pre-v2.0 | |
| 32 static void runMultiHelper(std::function<void()>, size_t numRuns); | |
| 33 void runMulti_(std::function<void()>, size_t numRuns); | |
| 34 }; | |
| 35 } | |
| 36 |
