| 1 | /* -*- C++ -*- |
| 2 | Wrap functors in jobs in ThreadWeaver. |
| 3 | |
| 4 | SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef LAMBDA_H |
| 10 | #define LAMBDA_H |
| 11 | |
| 12 | #include "job.h" |
| 13 | #include "threadweaver_export.h" |
| 14 | |
| 15 | namespace ThreadWeaver |
| 16 | { |
| 17 | template<typename T> |
| 18 | /* |
| 19 | * Lambda is a template that takes any type on which operator() is available, and executes it in run() |
| 20 | */ |
| 21 | class Lambda : public Job |
| 22 | { |
| 23 | public: |
| 24 | /*! |
| 25 | */ |
| 26 | explicit Lambda(T t_) |
| 27 | : t(t_) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | protected: |
| 32 | void run(JobPointer, Thread *) override |
| 33 | { |
| 34 | t(); |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | T t; |
| 39 | }; |
| 40 | |
| 41 | } |
| 42 | |
| 43 | #endif // LAMBDA_H |
| 44 | |