NDEVR
API Documentation
ThreadQueue.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: ThreadQueue
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Thread.h>
34#include <NDEVR/Resource.h>
35#include "DLLInfo.h"
36namespace NDEVR
37{
38#if NDEVR_SUPPORTS_THREADING
44 class NDEVR_BASE_API ThreadQueue : public Thread
45 {
46 public:
48 public:
53 explicit ThreadQueue(const String& name);
54
58 void run() override;
59
64 void add(const std::function<void()>& callback)
65 {
66 m_functions.add(callback);
67 start();
68 }
69 protected:
70 Buffer<std::function<void()>> m_functions;
71 std::function<void(const char* const)> m_error_callback;
72 };
73#endif
74}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
The core String class for the NDEVR API.
Definition String.h:95
Buffer< std::function< void()> > m_functions
The queue of functions awaiting execution.
Definition ThreadQueue.h:70
void run() override
Executes all queued functions sequentially in the thread.
Resource< bool > sv_is_running
Indicates whether the thread queue is currently running.
Definition ThreadQueue.h:47
void add(const std::function< void()> &callback)
Adds a callback function to the queue and starts the thread if not already running.
Definition ThreadQueue.h:64
std::function< void(const char *const)> m_error_callback
Optional callback invoked when an error occurs during execution.
Definition ThreadQueue.h:71
ThreadQueue(const String &name)
Constructs a ThreadQueue with the given name.
Thread()
Constructs a Thread with a default name.
void start()
Starts the thread execution.
The primary namespace for the NDEVR SDK.