Click tasks and timers

Eddie Kohler kohler at aciri.org
Mon Feb 26 08:52:04 EST 2001


Hi all,

This mail is about recent changes in the Click anonymous CVS repository.
We've changed both Timers and the way Click tasks are scheduled.

First, Timers. The change is simple: TimerHook callback functions used to
take an unsigned long argument; now they take (Timer *, void *).

     typedef void (*TimerHook)(Timer *, void *);

More significantly, tasks. Click tasks were previously synonymous with
elements -- an element could be placed on a router's task list, or not.
This had several problems: Every task had to be an element; each element
could correspond to only one task; every element had task-related space
overhead. This annoyed. So now, tasks are encapsulated in a separate class,
called Task. Elements that want to run as tasks must explicitly contain a
Task member. All scheduling-related functions, such as scheduled_next(),
scheduled(), set_max_tickets(), and so on, are now Task functions.

For example:

  class Unqueue : public Element { public:
    // ...
   private:
    // ...
    Task _task;
  };

  Unqueue::Unqueue()
    // must initialize the Task object to call this element as its callback
    : Element(1, 1), _task(this)
  { /* ... */ }

  int
  Unqueue::initialize(ErrorHandler *errh)
  {
    // must pass the Task to ScheduleInfo::join_scheduler
    ScheduleInfo::join_scheduler(this, &_task, errh);
    // ...
  }

  void
  Unqueue::uninitialize()
  {
    _task.unschedule();
  }

  void
  Unqueue::run_scheduled()
  {
    // ...  
    _task.reschedule();
  }

We've updated all the elements checked in to the MIT repository, but you
will need to update any elements you run yourselves. Hope this pleases. As
always, comments appreciated.

love,
ed



More information about the click mailing list