7 #include<core/parallel/mutex.hpp> 8 #include<core/storage/sframe_data/sframe_constants.hpp> 46 template<
typename ValueType,
typename OutIterator>
50 size_t soft_limit = SFRAME_WRITER_BUFFER_SOFT_LIMIT,
52 out(out), out_lock(out_lock),
53 soft_limit(soft_limit),
54 hard_limit(hard_limit) {
55 ASSERT_GT(hard_limit, soft_limit);
63 void write(
const ValueType& val) {
64 buffer.push_back(val);
65 if (buffer.size() >= soft_limit) {
67 if (locked || buffer.size() >= hard_limit) {
73 void write(ValueType&& val) {
74 buffer.push_back(val);
75 if (buffer.size() >= soft_limit) {
77 if (locked || buffer.size() >= hard_limit) {
87 void flush(
bool is_locked =
false) {
91 std::lock_guard<turi::mutex> guard(out_lock, std::adopt_lock);
92 for (
auto& val : buffer) {
93 *out++ = std::move(val);
103 std::vector<ValueType> buffer;
void flush(bool is_locked=false)
void lock() const
Acquires a lock on the mutex.
const size_t SFRAME_WRITER_BUFFER_HARD_LIMIT
bool try_lock() const
Non-blocking attempt to acquire a lock on the mutex.
void write(const ValueType &val)