Mercurial > foo_out_sdl
diff foosdk/sdk/pfc/cmd_thread.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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/foosdk/sdk/pfc/cmd_thread.h Mon Jan 05 02:15:46 2026 -0500 @@ -0,0 +1,46 @@ +#pragma once + +#include "wait_queue.h" +#include <functional> +#include <mutex> +#include <memory> + +namespace pfc { + + class cmdThread { + public: + typedef std::function<void()> cmd_t; + typedef pfc::waitQueue<cmd_t> queue_t; + + void add(cmd_t c) { + std::call_once(m_once, [this] { + auto q = std::make_shared<queue_t>(); + pfc::splitThread([q] { + cmd_t cmd; + while (q->get(cmd)) { + cmd(); + } + }); + m_queue = q; + }); + m_queue->put(c); + } + + void shutdown() { + if (m_queue) { + m_queue->set_eof(); + m_queue.reset(); + } + } + ~cmdThread() { + shutdown(); + } + private: + + std::shared_ptr< queue_t > m_queue; + + + std::once_flag m_once; + }; + +} \ No newline at end of file
