MCPcopy Create free account
hub / github.com/ml-explore/mlx-data / background_buffer_fetch_

Method background_buffer_fetch_

mlx/data/stream/Buffered.cpp:23–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 buffer_(nullptr) {}
22
23std::future<std::shared_ptr<buffer::Buffer>>
24Buffered::background_buffer_fetch_() const {
25 return pool_->enqueue([this]() -> std::shared_ptr<buffer::Buffer> {
26 std::vector<std::future<Sample>> future_buffer;
27 {
28 std::unique_lock lock(pool_mutex_);
29 if (pool_is_alive_) {
30 for (int i = 0; i < buffer_size_; i++) {
31 future_buffer.push_back(
32 pool_->enqueue([this] { return stream_->next(); }));
33 }
34 }
35 }
36
37 std::vector<Sample> buffer;
38 for (auto& fsample : future_buffer) {
39 Sample sample = fsample.get();
40 if (!sample.empty()) {
41 buffer.push_back(sample);
42 }
43 }
44
45 {
46 std::unique_lock lock(pool_mutex_);
47 if (pool_is_alive_) {
48 return on_refill(std::make_shared<FromVector>(buffer));
49 }
50 }
51
52 return nullptr;
53 });
54}
55
56Sample Buffered::next() const {
57 std::unique_lock lock(mutex_);

Callers

nothing calls this directly

Calls 3

enqueueMethod · 0.80
nextMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected