-
Notifications
You must be signed in to change notification settings - Fork 7
/
schedulerbase.hpp
67 lines (50 loc) · 1.88 KB
/
schedulerbase.hpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// solid/frame/schedulerbase.hpp
//
// Copyright (c) 2007, 2008 Valentin Palade (vipalade @ gmail . com)
//
// This file is part of SolidFrame framework.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.
//
#pragma once
#include "solid/frame/common.hpp"
#include "solid/system/error.hpp"
#include "solid/system/pimpl.hpp"
#include "solid/utility/function.hpp"
#include <thread>
namespace solid {
namespace frame {
class Service;
class ReactorBase;
class ActorBase;
// typedef FunctorReference<bool, ReactorBase&> ScheduleFunctorT;
typedef solid_function_t(bool(ReactorBase&)) ScheduleFunctionT;
//! A base class for all schedulers
class SchedulerBase : NonCopyable {
struct Data;
Pimpl<Data, 304> pimpl_;
protected:
typedef bool (*CreateWorkerF)(SchedulerBase& _rsch, const size_t, std::thread& _rthr, const size_t _wake_capacity);
typedef solid_function_t(bool()) ThreadEnterFunctionT;
typedef solid_function_t(void()) ThreadExitFunctionT;
void doStart(
CreateWorkerF _pf,
ThreadEnterFunctionT& _renf,
ThreadExitFunctionT& _rexf,
size_t _reactorcnt, const size_t _wake_capacity);
void doStop(const bool _wait = true);
ActorIdT doStartActor(ActorBase& _ract, Service& _rsvc, ScheduleFunctionT& _rfct, ErrorConditionT& _rerr);
ActorIdT doStartActor(ActorBase& _ract, Service& _rsvc, const size_t _workerIndex, ScheduleFunctionT& _rfct, ErrorConditionT& _rerr);
size_t workerCount() const;
protected:
SchedulerBase();
~SchedulerBase();
private:
friend class ReactorBase;
bool prepareThread(const size_t _idx, ReactorBase& _rsel, const bool _success);
void unprepareThread(const size_t _idx, ReactorBase& _rsel);
size_t doComputeScheduleReactorIndex();
};
} // namespace frame
} // namespace solid