| 1 |
/* |
| 2 |
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2025 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 27 янв. 2016 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_IPC_NATIVEEXECUTOR_H_ |
| 23 |
#define LSP_PLUG_IN_IPC_NATIVEEXECUTOR_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/common/atomic.h> |
| 27 |
#include <lsp-plug.in/ipc/Thread.h> |
| 28 |
#include <lsp-plug.in/ipc/IExecutor.h> |
| 29 |
#include <lsp-plug.in/ipc/ITask.h> |
| 30 |
|
| 31 |
namespace lsp |
| 32 |
{ |
| 33 |
namespace ipc |
| 34 |
{ |
| 35 |
/** |
| 36 |
* Native executor class |
| 37 |
*/ |
| 38 |
class NativeExecutor: public IExecutor |
| 39 |
{ |
| 40 |
private: |
| 41 |
Thread hThread; |
| 42 |
ITask *pHead; |
| 43 |
ITask *pTail; |
| 44 |
atomic_t nLock; |
| 45 |
|
| 46 |
private: |
| 47 |
static status_t execute(void *params); |
| 48 |
|
| 49 |
private: |
| 50 |
void run(); |
| 51 |
|
| 52 |
public: |
| 53 |
explicit NativeExecutor(); |
| 54 |
NativeExecutor(const NativeExecutor &) = delete; |
| 55 |
NativeExecutor(NativeExecutor &&) = delete; |
| 56 |
virtual ~NativeExecutor() override; |
| 57 |
|
| 58 |
NativeExecutor &operator = (const NativeExecutor & src) = delete; |
| 59 |
NativeExecutor &operator = (NativeExecutor && src) = delete; |
| 60 |
|
| 61 |
public: |
| 62 |
/** |
| 63 |
* Start the execution thread |
| 64 |
* @return status of operation |
| 65 |
*/ |
| 66 |
status_t start(); |
| 67 |
|
| 68 |
public: |
| 69 |
/** |
| 70 |
* Submit some task for execution |
| 71 |
* @param task task to submit |
| 72 |
* @return true on success |
| 73 |
*/ |
| 74 |
virtual bool submit(ITask *task) override; |
| 75 |
|
| 76 |
/** |
| 77 |
* Shutdown the executor |
| 78 |
*/ |
| 79 |
virtual void shutdown() override; |
| 80 |
}; |
| 81 |
} /* namespace ipc */ |
| 82 |
} /* namespace lsp */ |
| 83 |
|
| 84 |
#endif /* LSP_PLUG_IN_IPC_NATIVEEXECUTOR_H_ */ |