SchedInst.h 2.9 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.

18 19
#pragma once

S
starlord 已提交
20
#include "JobMgr.h"
21 22
#include "ResourceMgr.h"
#include "Scheduler.h"
23 24
#include "optimizer/HybridPass.h"
#include "optimizer/Optimizer.h"
25 26

#include <memory>
S
starlord 已提交
27
#include <mutex>
28
#include <vector>
29 30

namespace milvus {
W
wxyu 已提交
31
namespace scheduler {
32 33

class ResMgrInst {
S
starlord 已提交
34
 public:
35 36 37 38 39 40 41 42 43 44 45
    static ResourceMgrPtr
    GetInstance() {
        if (instance == nullptr) {
            std::lock_guard<std::mutex> lock(mutex_);
            if (instance == nullptr) {
                instance = std::make_shared<ResourceMgr>();
            }
        }
        return instance;
    }

S
starlord 已提交
46
 private:
47 48 49 50 51
    static ResourceMgrPtr instance;
    static std::mutex mutex_;
};

class SchedInst {
S
starlord 已提交
52
 public:
53 54 55 56 57 58 59 60 61 62 63
    static SchedulerPtr
    GetInstance() {
        if (instance == nullptr) {
            std::lock_guard<std::mutex> lock(mutex_);
            if (instance == nullptr) {
                instance = std::make_shared<Scheduler>(ResMgrInst::GetInstance());
            }
        }
        return instance;
    }

S
starlord 已提交
64
 private:
65 66 67 68
    static SchedulerPtr instance;
    static std::mutex mutex_;
};

W
wxyu 已提交
69
class JobMgrInst {
S
starlord 已提交
70
 public:
W
wxyu 已提交
71 72 73 74 75 76 77 78 79 80 81
    static scheduler::JobMgrPtr
    GetInstance() {
        if (instance == nullptr) {
            std::lock_guard<std::mutex> lock(mutex_);
            if (instance == nullptr) {
                instance = std::make_shared<scheduler::JobMgr>(ResMgrInst::GetInstance());
            }
        }
        return instance;
    }

S
starlord 已提交
82
 private:
W
wxyu 已提交
83 84 85 86
    static scheduler::JobMgrPtr instance;
    static std::mutex mutex_;
};

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
class OptimizerInst {
 public:
    static OptimizerPtr
    GetInstance() {
        if (instance == nullptr) {
            std::lock_guard<std::mutex> lock(mutex_);
            if (instance == nullptr) {
                HybridPassPtr pass_ptr = std::make_shared<HybridPass>();
                std::vector<PassPtr> pass_list;
                pass_list.push_back(pass_ptr);
                instance = std::make_shared<Optimizer>(pass_list);
            }
        }
        return instance;
    }

 private:
    static scheduler::OptimizerPtr instance;
    static std::mutex mutex_;
};

W
wxyu 已提交
108
void
S
starlord 已提交
109 110 111 112
StartSchedulerService();

void
StopSchedulerService();
W
wxyu 已提交
113

S
starlord 已提交
114 115
}  // namespace scheduler
}  // namespace milvus