aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yt/core/concurrency/suspendable_action_queue.h
blob: 4c8f4173fe3187014b233ef06b5f61448f230a2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "public.h"

#include <yt/yt/core/actions/public.h>

namespace NYT::NConcurrency {

////////////////////////////////////////////////////////////////////////////////

struct ISuspendableActionQueue
    : public TRefCounted
{
    virtual const IInvokerPtr& GetInvoker() = 0;

    //! Returns a future that becomes set when action queue is suspended
    //! and thread is blocked.
    //! If #immediately is true, queue is suspended just after completion
    //! of current fiber.
    //! If #immediately is false, queue is suspended when underlying queue
    //! becomes empty.
    virtual TFuture<void> Suspend(bool immediately) = 0;

    //! Resumes queue. Queue should be suspended prior to this call.
    virtual void Resume() = 0;

    virtual void Shutdown(bool graceful) = 0;
};

DEFINE_REFCOUNTED_TYPE(ISuspendableActionQueue)

////////////////////////////////////////////////////////////////////////////////

struct TSuspendableActionQueueOptions
{
    std::function<void()> ThreadInitializer;
};

ISuspendableActionQueuePtr CreateSuspendableActionQueue(
    TString threadName,
    TSuspendableActionQueueOptions options = {});

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NConcurrency