@@ -335,36 +335,44 @@ void Consumer::execute()
335335 auto entries = std::make_shared<std::deque<KeyOpFieldsValuesTuple>>();
336336 getConsumerTable ()->pops (*entries);
337337
338- pushRingBuffer ([=](){
339- addToSync (entries);
340- });
341-
342- pushRingBuffer ([=](){
343- drain ();
344- });
338+ processAnyTask (
339+ // bundle tasks into a lambda function which takes no argument and returns void
340+ // this lambda captures variables by value from the surrounding scope
341+ [=](){
342+ addToSync (entries);
343+ drain ();
344+ }
345+ );
345346}
346347
347- void Executor::pushRingBuffer (AnyTask&& task)
348+ void Executor::processAnyTask (AnyTask&& task)
348349{
350+ // if either gRingBuffer isn't initialized or the ring thread isn't created
349351 if (!gRingBuffer || !gRingBuffer ->thread_created )
350352 {
351- // execute the task right now in this thread if gRingBuffer is not initialized
352- // or the ring thread is not created, or this executor is not served by gRingBuffer
353+ // execute the input task immediately
353354 task ();
354355 }
355- else if (!gRingBuffer ->serves (getName ())) // not served by ring thread
356+
357+ // Ring Buffer Logic
358+
359+ // if this executor isn't served by ring buffer
360+ else if (!gRingBuffer ->serves (getName ()))
356361 {
362+ // this executor should execute the input task in the main thread
363+ // but to avoid thread issue, it should wait when the ring buffer is actively working
357364 while (!gRingBuffer ->IsEmpty () || !gRingBuffer ->IsIdle ()) {
358365 gRingBuffer ->notify ();
359366 std::this_thread::sleep_for (std::chrono::milliseconds (SLEEP_MSECONDS));
360367 }
361- // if ring thread is enabled, make sure to execute task after the ring finishes its work
368+ // execute task()
362369 task ();
363370 }
364371 else
365372 {
366- // if this executor is served by gRingBuffer, push the task to gRingBuffer
367- // and notify the ring thread to flush gRingBuffer
373+ // if this executor is served by ring buffer,
374+ // push the task to gRingBuffer
375+ // this task would be executed in the ring thread, not here
368376 while (!gRingBuffer ->push (task)) {
369377 gRingBuffer ->notify ();
370378 SWSS_LOG_WARN (" ring is full...push again" );
0 commit comments