Program Listing for File executor.h

Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/canonical-mir-documentation/checkouts/stable/include/common/mir/executor.h)

/*
 * Copyright © Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 or 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MIR_EXECUTOR_H_
#define MIR_EXECUTOR_H_

#include <functional>

namespace mir
{

class Executor
{
public:
    virtual void spawn(std::function<void()>&& work) = 0;

protected:
    virtual ~Executor() = default;
};

class NonBlockingExecutor: public Executor
{
};

class ThreadPoolExecutor : public NonBlockingExecutor
{
public:
    void spawn(std::function<void()>&& work) override;

    static void set_unhandled_exception_handler(void (*handler)());

    static void quiesce();
protected:
    ThreadPoolExecutor() = default;
};

extern NonBlockingExecutor& thread_pool_executor;

extern NonBlockingExecutor& linearising_executor;

extern Executor& immediate_executor;
}

#endif // MIR_EXECUTOR_H_