processor.h 1.8 KB
Newer Older
1
/******************************************************************************
G
gruminions 已提交
2
 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *****************************************************************************/

G
GoLancer 已提交
17 18
#ifndef CYBER_SCHEDULER_PROCESSOR_H_
#define CYBER_SCHEDULER_PROCESSOR_H_
19

20
#include <atomic>
21 22 23
#include <condition_variable>
#include <memory>
#include <mutex>
24
#include <string>
25
#include <thread>
26
#include <vector>
27

G
GoLancer 已提交
28 29
#include "cyber/croutine/croutine.h"
#include "cyber/proto/scheduler_conf.pb.h"
30
#include "cyber/scheduler/processor_context.h"
31 32

namespace apollo {
G
GoLancer 已提交
33
namespace cyber {
34 35 36 37 38 39
namespace scheduler {

using croutine::CRoutine;

class Processor {
 public:
G
GoLancer 已提交
40
  Processor();
41
  virtual ~Processor();
42

Z
zaxon 已提交
43
  void Run();
44 45
  void Stop();
  void BindContext(const std::shared_ptr<ProcessorContext>& context);
46
  void SetAffinity(const std::vector<int>&, const std::string&, int);
47
  void SetSchedPolicy(std::string spolicy, int sched_priority);
48

49
 private:
50
  std::shared_ptr<ProcessorContext> context_;
Z
zaxon 已提交
51

52
  std::condition_variable cv_ctx_;
53
  std::once_flag thread_flag_;
Z
zaxon 已提交
54 55 56
  std::mutex mtx_ctx_;
  std::thread thread_;

57
  std::atomic<pid_t> tid_{-1};
58
  std::atomic<bool> running_{false};
59 60 61
};

}  // namespace scheduler
G
GoLancer 已提交
62
}  // namespace cyber
63 64
}  // namespace apollo

G
GoLancer 已提交
65
#endif  // CYBER_SCHEDULER_PROCESSOR_H_