src/concurrent/dotnet/Scheduler.cs
/// <summary>
/// Add the work item into the linked list so that the list
/// is always sorted by earliest deadline to oldest deadline.
/// Return true if we have a new head which changes our
/// next earliest deadline.
/// </summary>
Add the work item into the linked list so that the list
is always sorted by earliest deadline to oldest deadline.
Return true if we have a new head which changes our
next earliest deadline.
Add the work item into the linked list so that the list is always sorted by earliest deadline to oldest deadline . Return true if we have a new head which changes our next earliest deadline .
private bool add(long ns, Work work)
    {
      Node node = new Node();
      node.deadline = Fan.Sys.Sys.nanoTime() + ns;
      node.work = work;
      if (head == null)
      {
        head = node;
        return true;
      }
      if (node.deadline < head.deadline)
      {
        node.next = head;
        head = node;
        return true;
      }
      Node last = head, cur = head.next;
      while (cur != null)
      {
        if (node.deadline < cur.deadline)
        {
          node.next = cur;
          last.next = node;
          return false;
        }
        last = cur;
        cur = cur.next;
      }
      last.next = node;
      return false;
    }
private bool add ( long ns , Work work ) { Node node = new Node ( ) ; node . deadline = Fan . Sys . Sys . nanoTime ( ) + ns ; node . work = work ; if ( head == null ) { head = node ; return true ; } if ( node . deadline < head . deadline ) { node . next = head ; head = node ; return true ; } Node last = head , cur = head . next ; while ( cur != null ) { if ( node . deadline < cur . deadline ) { node . next = cur ; last . next = node ; return false ; } last = cur ; cur = cur . next ; } last . next = node ; return false ; }
Add the work item into the linked list so that the list
is always sorted by earliest deadline to oldest deadline.
Add the work item into the linked list so that the list is always sorted by earliest deadline to oldest deadline .
// create new node for our linked list // if no items, this is easy // if new item has earliest deadline it becomes new head // find insertion point in linked list // this node has the oldest deadline, append to linked list
ns
long
work
Work