xorp

round_robin.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2006-2009 XORP, Inc.
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License, Version
00008 // 2.1, June 1999 as published by the Free Software Foundation.
00009 // Redistribution and/or modification of this program under the terms of
00010 // any other version of the GNU Lesser General Public License is not
00011 // permitted.
00012 // 
00013 // This program is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00016 // see the GNU Lesser General Public License, Version 2.1, a copy of
00017 // which can be found in the XORP LICENSE.lgpl file.
00018 // 
00019 // XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00020 // http://xorp.net
00021 
00022 // $XORP: xorp/libxorp/round_robin.hh,v 1.8 2008/10/02 21:57:33 bms Exp $
00023 
00024 #ifndef __LIBXORP_ROUND_ROBIN_HH__
00025 #define __LIBXORP_ROUND_ROBIN_HH__
00026 
00027 class RoundRobin;
00028 
00032 class RoundRobinObjBase {
00033 public:
00034     RoundRobinObjBase();
00035 
00036     int weight() const { return _weight; }
00037     void set_weight(int v) { _weight = v; }
00038     RoundRobinObjBase* next() const { return _next; }
00039     RoundRobinObjBase* prev() const { return _prev; }
00040     void set_next(RoundRobinObjBase* next) { _next = next; }
00041     void set_prev(RoundRobinObjBase* prev) { _prev = prev; }
00042     bool scheduled() const;
00043 
00044 private:
00045     int _weight;
00046 
00047     // Links to build a circular list
00048     RoundRobinObjBase* _next;
00049     RoundRobinObjBase* _prev;
00050 };
00051 
00055 class RoundRobinQueue {
00056 public:
00057     RoundRobinQueue();
00058     void push(RoundRobinObjBase* obj, int weight);
00059     void pop_obj(RoundRobinObjBase* obj);
00060     void pop();
00061 
00062     RoundRobinObjBase* get_next_entry();
00063 
00069     size_t size() const { return _elements; }
00070 
00071 private:
00072     void link_object(RoundRobinObjBase* obj, int weight);
00073     void unlink_object(RoundRobinObjBase* obj);
00074 
00075     RoundRobinObjBase* _next_to_run;
00076     int _run_count; // How many times we've run the current task in a row
00077     int _elements;
00078 };
00079 
00080 #endif // __LIBXORP_ROUND_ROBIN_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations