1  
//
1  
//
2  
// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3  
// Copyright (c) 2026 Steve Gerbino
3  
// Copyright (c) 2026 Steve Gerbino
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/cppalliance/corosio
8  
// Official repository: https://github.com/cppalliance/corosio
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_COROSIO_DETAIL_SCHEDULER_HPP
11  
#ifndef BOOST_COROSIO_DETAIL_SCHEDULER_HPP
12  
#define BOOST_COROSIO_DETAIL_SCHEDULER_HPP
12  
#define BOOST_COROSIO_DETAIL_SCHEDULER_HPP
13  

13  

14  
#include <boost/corosio/detail/config.hpp>
14  
#include <boost/corosio/detail/config.hpp>
15  
#include <coroutine>
15  
#include <coroutine>
16  

16  

17  
#include <cstddef>
17  
#include <cstddef>
18  

18  

19  
namespace boost::corosio::detail {
19  
namespace boost::corosio::detail {
20  

20  

21  
class scheduler_op;
21  
class scheduler_op;
22  

22  

23  
struct scheduler
23  
struct scheduler
24  
{
24  
{
25  
    virtual ~scheduler() = default;
25  
    virtual ~scheduler() = default;
26  
    virtual void post(std::coroutine_handle<>) const = 0;
26  
    virtual void post(std::coroutine_handle<>) const = 0;
27  
    virtual void post(scheduler_op*) const = 0;
27  
    virtual void post(scheduler_op*) const = 0;
28  

28  

29  
    /** Notify scheduler of pending work (for executor use).
29  
    /** Notify scheduler of pending work (for executor use).
30  
        When the count reaches zero, the scheduler stops.
30  
        When the count reaches zero, the scheduler stops.
31  
    */
31  
    */
32  
    virtual void on_work_started() noexcept = 0;
32  
    virtual void on_work_started() noexcept = 0;
33  
    virtual void on_work_finished() noexcept = 0;
33  
    virtual void on_work_finished() noexcept = 0;
34  

34  

35  
    /** Notify scheduler of pending I/O work (for services use).
35  
    /** Notify scheduler of pending I/O work (for services use).
36  
        Unlike on_work_finished, work_finished does not stop the scheduler
36  
        Unlike on_work_finished, work_finished does not stop the scheduler
37  
        when the count reaches zero - it only wakes blocked threads.
37  
        when the count reaches zero - it only wakes blocked threads.
38  
    */
38  
    */
39  
    virtual void work_started() const noexcept = 0;
39  
    virtual void work_started() const noexcept = 0;
40  
    virtual void work_finished() const noexcept = 0;
40  
    virtual void work_finished() const noexcept = 0;
41  

41  

42  
    virtual bool running_in_this_thread() const noexcept = 0;
42  
    virtual bool running_in_this_thread() const noexcept = 0;
43  
    virtual void stop() = 0;
43  
    virtual void stop() = 0;
44  
    virtual bool stopped() const noexcept = 0;
44  
    virtual bool stopped() const noexcept = 0;
45  
    virtual void restart() = 0;
45  
    virtual void restart() = 0;
46  
    virtual std::size_t run() = 0;
46  
    virtual std::size_t run() = 0;
47  
    virtual std::size_t run_one() = 0;
47  
    virtual std::size_t run_one() = 0;
48  
    virtual std::size_t wait_one(long usec) = 0;
48  
    virtual std::size_t wait_one(long usec) = 0;
49  
    virtual std::size_t poll() = 0;
49  
    virtual std::size_t poll() = 0;
50  
    virtual std::size_t poll_one() = 0;
50  
    virtual std::size_t poll_one() = 0;
51  
};
51  
};
52  

52  

53  
} // namespace boost::corosio::detail
53  
} // namespace boost::corosio::detail
54  

54  

55  
#endif
55  
#endif