SchedInst.h 2.3 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 20 21
#pragma once

#include "ResourceMgr.h"
#include "Scheduler.h"
W
wxyu 已提交
22
#include "JobMgr.h"
23 24 25 26 27 28

#include <mutex>
#include <memory>

namespace zilliz {
namespace milvus {
W
wxyu 已提交
29
namespace scheduler {
30 31

class ResMgrInst {
S
starlord 已提交
32
 public:
33 34 35 36 37 38 39 40 41 42 43
    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 已提交
44
 private:
45 46 47 48 49
    static ResourceMgrPtr instance;
    static std::mutex mutex_;
};

class SchedInst {
S
starlord 已提交
50
 public:
51 52 53 54 55 56 57 58 59 60 61
    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 已提交
62
 private:
63 64 65 66
    static SchedulerPtr instance;
    static std::mutex mutex_;
};

W
wxyu 已提交
67
class JobMgrInst {
S
starlord 已提交
68
 public:
W
wxyu 已提交
69 70 71 72 73 74 75 76 77 78 79
    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 已提交
80
 private:
W
wxyu 已提交
81 82 83 84
    static scheduler::JobMgrPtr instance;
    static std::mutex mutex_;
};

W
wxyu 已提交
85
void
S
starlord 已提交
86 87 88 89
StartSchedulerService();

void
StopSchedulerService();
W
wxyu 已提交
90

S
starlord 已提交
91 92 93
} // namespace scheduler
} // namespace milvus
} // namespace zilliz