milvus/cpp/src/utils/BlockingQueue.h
jinhai 94612238e5 MS-82 & MS-83 Update vecwise to Milvus
Former-commit-id: 69d1f1b661e6fc7779b4ae3abae60eeb28fa2b04
2019-06-13 16:02:25 +08:00

55 lines
1.1 KiB
C++

/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#pragma once
#include <assert.h>
#include <condition_variable>
#include <iostream>
#include <queue>
#include <vector>
namespace zilliz {
namespace milvus {
namespace server {
template<typename T>
class BlockingQueue {
public:
BlockingQueue() : mtx(), full_(), empty_() {}
BlockingQueue(const BlockingQueue &rhs) = delete;
BlockingQueue &operator=(const BlockingQueue &rhs) = delete;
void Put(const T &task);
T Take();
T Front();
T 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_;
std::queue<T> queue_;
size_t capacity_ = 32;
};
}
}
}
#include "./BlockingQueue.inl"