MCPcopy Create free account
hub / github.com/apache/trafficserver / enqueue

Method enqueue

plugins/experimental/wasm/lib/src/shared_queue.cc:122–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122WasmResult SharedQueue::enqueue(uint32_t token, std::string_view value) {
123 std::string vm_key;
124 uint32_t context_id;
125 CallOnThreadFunction call_on_thread;
126
127 {
128 std::lock_guard<std::mutex> lock(mutex_);
129 auto it = queues_.find(token);
130 if (it == queues_.end()) {
131 return WasmResult::NotFound;
132 }
133 Queue *target_queue = &(it->second);
134 vm_key = target_queue->vm_key;
135 context_id = target_queue->context_id;
136 call_on_thread = target_queue->call_on_thread;
137 target_queue->queue.emplace_back(value);
138 }
139
140 call_on_thread([vm_key, context_id, token] {
141 // This code may or may not execute in another thread.
142 // Make sure that the lock is no longer held here.
143 auto wasm = getThreadLocalWasm(vm_key);
144 if (wasm) {
145 auto *context = wasm->wasm()->getContext(context_id);
146 if (context != nullptr) {
147 context->onQueueReady(token);
148 }
149 }
150 });
151 return WasmResult::Ok;
152}
153
154} // namespace proxy_wasm

Callers 1

enqueueSharedQueueMethod · 0.45

Calls 7

getThreadLocalWasmFunction · 0.85
emplace_backMethod · 0.80
findMethod · 0.45
endMethod · 0.45
getContextMethod · 0.45
wasmMethod · 0.45
onQueueReadyMethod · 0.45

Tested by

no test coverage detected