IndexLoaderQueue.h 1.4 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*******************************************************************************
 * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 ******************************************************************************/
#pragma once

#include "SearchContext.h"

#include <condition_variable>
#include <iostream>
#include <queue>
#include <list>


namespace zilliz {
J
jinhai 已提交
17
namespace milvus {
G
groot 已提交
18 19 20 21 22 23 24 25 26 27 28
namespace engine {


class IndexLoaderContext {
public:
    TableFileSchemaPtr file_;
    std::vector<SearchContextPtr> search_contexts_;
};
using IndexLoaderContextPtr = std::shared_ptr<IndexLoaderContext>;

class IndexLoaderQueue {
G
groot 已提交
29
public:
G
groot 已提交
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
    IndexLoaderQueue() : mtx(), full_(), empty_() {}

    IndexLoaderQueue(const IndexLoaderQueue &rhs) = delete;

    IndexLoaderQueue &operator=(const IndexLoaderQueue &rhs) = delete;

    using LoaderQueue = std::list<IndexLoaderContextPtr>;

    void Put(const SearchContextPtr &search_context);

    IndexLoaderContextPtr Take();

    IndexLoaderContextPtr Front();

    IndexLoaderContextPtr Back();

    size_t Size();

    bool Empty();

    void SetCapacity(const size_t capacity);

private:
    mutable std::mutex mtx;
    std::condition_variable full_;
    std::condition_variable empty_;

    LoaderQueue queue_;
    size_t capacity_ = 1000000;
};

}
}
}