PageRenderTime 45ms CodeModel.GetById 32ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llthrottle.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 101 lines | 57 code | 18 blank | 26 comment | 0 complexity | f93ce5d81bc70a2021ee5300da1ce818 MD5 | raw file
  1/** 
  2 * @file llthrottle.h
  3 * @brief LLThrottle class used for network bandwidth control
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLTHROTTLE_H
 28#define LL_LLTHROTTLE_H
 29
 30#include "lltimer.h"
 31
 32const S32 MAX_THROTTLE_SIZE = 32;
 33
 34class LLDataPacker;
 35
 36// Single instance of a generic throttle
 37class LLThrottle
 38{
 39public:
 40	LLThrottle(const F32 throttle = 1.f);
 41	~LLThrottle() { }
 42
 43	void setRate(const F32 rate);
 44	BOOL checkOverflow(const F32 amount); // I'm about to add an amount, TRUE if would overflow throttle
 45	BOOL throttleOverflow(const F32 amount); // I just sent amount, TRUE if that overflowed the throttle
 46
 47	F32 getAvailable();	// Return the available bits
 48	F32 getRate() const				{ return mRate; }
 49private:
 50	F32 mLookaheadSecs;	// Seconds to look ahead, maximum
 51	F32	mRate;	// BPS available, dynamically adjusted
 52	F32	mAvailable;	// Bits available to send right now on each channel
 53	F64	mLastSendTime;		// Time since last send on this channel
 54};
 55
 56typedef enum e_throttle_categories
 57{
 58	TC_RESEND,
 59	TC_LAND,
 60	TC_WIND,
 61	TC_CLOUD,
 62	TC_TASK,
 63	TC_TEXTURE,
 64	TC_ASSET,
 65	TC_EOF
 66} EThrottleCats;
 67
 68
 69class LLThrottleGroup
 70{
 71public:
 72	LLThrottleGroup();
 73	~LLThrottleGroup() { }
 74
 75	void	resetDynamicAdjust();
 76	BOOL	checkOverflow(S32 throttle_cat, F32 bits);		// I'm about to send bits, TRUE if would overflow channel
 77	BOOL	throttleOverflow(S32 throttle_cat, F32 bits);	// I just sent bits, TRUE if that overflowed the channel
 78	BOOL	dynamicAdjust();		// Shift bandwidth from idle channels to busy channels, TRUE if adjustment occurred
 79	BOOL	setNominalBPS(F32* throttle_vec);				// TRUE if any value was different, resets adjustment system if was different
 80
 81	S32		getAvailable(S32 throttle_cat);					// Return bits available in the channel
 82
 83	void packThrottle(LLDataPacker &dp) const;
 84	void unpackThrottle(LLDataPacker &dp);
 85public:
 86	F32		mThrottleTotal[TC_EOF];	// BPS available, sent by viewer, sum for all simulators
 87
 88protected:
 89	F32		mNominalBPS[TC_EOF];	// BPS available, adjusted to be just this simulator
 90	F32		mCurrentBPS[TC_EOF];	// BPS available, dynamically adjusted
 91
 92	F32		mBitsAvailable[TC_EOF];	// Bits available to send right now on each channel
 93	F32		mBitsSentThisPeriod[TC_EOF];	// Sent in this dynamic allocation period
 94	F32		mBitsSentHistory[TC_EOF];		// Sent before this dynamic allocation period, adjusted to one period length
 95
 96	F64		mLastSendTime[TC_EOF];		// Time since last send on this channel
 97	F64		mDynamicAdjustTime;	// Only dynamic adjust every 2 seconds or so.
 98
 99};
100
101#endif