Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-26831

ActiveStreamCheckpointProcessorTask::run wakeUp logic could be simplified

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Won't Fix
    • Major
    • None
    • master
    • couchbase-bucket

    Description

      Abstractly shown are two function involved in the tasks run management.

      // The actual task run function - executes on a NONIO thread
      bool ActiveStreamCheckpointProcessorTask::run() {
          snooze(INT_MAX); // sets the task to appear asleep
          notified = false; // atomic_flag set to false
          ... task work - drain the inputQueue (up to some threshold of items ) ...
       
          // if notified == true, set it to false and return true 
          if (notified.cmpxchg(true, false) OR inputQueue.empty()) {
              A: request this task to be rescheduled at next available opportunity
          }
      }
       
      // The wake function - executes on another thread, this function requests that the task starts running
      void ActiveStreamCheckpointProcessorTask::schedule() {
          // if notified == false, set it to true and return true 
          if (notified.cmpxchg(false, true)) {
              B: request this task to be rescheduled at next available opportunity
          }
      }
      

      In the run() function, the final cmpxchg isn't needed, if we did find that notified was true we can be sure the other thread has done B, we only need to evaluate the inputQueue size to determine if the task should self-schedule.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              mohammad.zaeem Mohammad Zaeem
              jwalker Jim Walker
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty