PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/elements/standard/rrsched.cc

https://github.com/bhesmans/click
C++ | 64 lines | 41 code | 6 blank | 17 comment | 5 complexity | 961a1cce08b3848d61c2791d65154a6f MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. // -*- c-basic-offset: 4 -*-
  2. /*
  3. * rrsched.{cc,hh} -- round robin scheduler element
  4. * Robert Morris, Eddie Kohler
  5. *
  6. * Copyright (c) 1999-2000 Massachusetts Institute of Technology
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, subject to the conditions
  11. * listed in the Click LICENSE file. These conditions include: you must
  12. * preserve this copyright notice, and you cannot mention the copyright
  13. * holders in advertising related to the Software without their permission.
  14. * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
  15. * notice is a summary of the Click LICENSE file; the license in that file is
  16. * legally binding.
  17. */
  18. #include <click/config.h>
  19. #include <click/error.hh>
  20. #include "rrsched.hh"
  21. CLICK_DECLS
  22. RRSched::RRSched()
  23. : _next(0), _signals(0)
  24. {
  25. }
  26. int
  27. RRSched::initialize(ErrorHandler *errh)
  28. {
  29. if (!(_signals = new NotifierSignal[ninputs()]))
  30. return errh->error("out of memory!");
  31. for (int i = 0; i < ninputs(); i++)
  32. _signals[i] = Notifier::upstream_empty_signal(this, i);
  33. return 0;
  34. }
  35. void
  36. RRSched::cleanup(CleanupStage)
  37. {
  38. delete[] _signals;
  39. }
  40. Packet *
  41. RRSched::pull(int)
  42. {
  43. int n = ninputs();
  44. int i = _next;
  45. for (int j = 0; j < n; j++) {
  46. Packet *p = (_signals[i] ? input(i).pull() : 0);
  47. i++;
  48. if (i >= n)
  49. i = 0;
  50. if (p) {
  51. _next = i;
  52. return p;
  53. }
  54. }
  55. return 0;
  56. }
  57. CLICK_ENDDECLS
  58. EXPORT_ELEMENT(RRSched)