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

9  

10  
#ifndef BOOST_COROSIO_DETAIL_SCHEDULER_HPP
10  
#ifndef BOOST_COROSIO_DETAIL_SCHEDULER_HPP
11  
#define BOOST_COROSIO_DETAIL_SCHEDULER_HPP
11  
#define BOOST_COROSIO_DETAIL_SCHEDULER_HPP
12  

12  

13  
#include <boost/corosio/detail/config.hpp>
13  
#include <boost/corosio/detail/config.hpp>
14  
#include <boost/capy/coro.hpp>
14  
#include <boost/capy/coro.hpp>
15  

15  

16  
#include <cstddef>
16  
#include <cstddef>
17  

17  

18  
namespace boost::corosio::detail {
18  
namespace boost::corosio::detail {
19  

19  

20  
class scheduler_op;
20  
class scheduler_op;
21  

21  

22  
struct scheduler
22  
struct scheduler
23  
{
23  
{
24  
    virtual ~scheduler() = default;
24  
    virtual ~scheduler() = default;
25  
    virtual void post(capy::coro) const = 0;
25  
    virtual void post(capy::coro) const = 0;
26  
    virtual void post(scheduler_op*) const = 0;
26  
    virtual void post(scheduler_op*) const = 0;
27  

27  

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

33  

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

40  

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

51  

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

53  

54  
#endif
54  
#endif