libfilezilla
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
bucket_base Class Referenceabstract

Base class for buckets. More...

#include <rate_limiter.hpp>

Inheritance diagram for bucket_base:
Inheritance graph
[legend]
Collaboration diagram for bucket_base:
Collaboration graph
[legend]

Public Member Functions

void remove_bucket ()
 

Protected Member Functions

virtual void lock_tree ()
 Recursively locks the mutexes of self and all children. More...
 
virtual void update_stats (bool &active)=0
 Updates weight and usage statistics. More...
 
virtual size_t weight () const
 Returns the weight of the tree. More...
 
virtual size_t unsaturated (direction::type const) const
 Returns the number of buckets not yet full. More...
 
virtual void set_mgr_recursive (rate_limit_manager *mgr)
 Recursively sets the manager. More...
 
virtual rate::type add_tokens (direction::type const, rate::type, rate::type)=0
 Recursively adds tokens. More...
 
virtual rate::type distribute_overflow (direction::type const, rate::type)
 Recursively distributes overflow. More...
 
virtual void unlock_tree ()
 Recursively unlocks the mutexes of self and all childen.
 
virtual std::array< rate::type, 2 > gather_unspent_for_removal ()=0
 Gather unspent tokens during removal to repay debt. More...
 

Protected Attributes

mutex mtx_ {false}
 
rate_limit_managermgr_ {}
 
void * parent_ {}
 
size_t idx_ {static_cast<size_t>(-1)}
 

Friends

class rate_limiter
 

Detailed Description

Base class for buckets.

Member Function Documentation

◆ add_tokens()

virtual rate::type add_tokens ( direction::type  const,
rate::type  ,
rate::type   
)
protectedpure virtual

Recursively adds tokens.

Arguments are normalized for a single bucket. For total added, multiply by weight.

Must only be called with a locked tree

Returns
the overflow, the tokens that could not be distributed.

◆ distribute_overflow()

virtual rate::type distribute_overflow ( direction::type  const,
rate::type   
)
inlineprotectedvirtual

Recursively distributes overflow.

Arguments are normalized for a single bucket. For total added, multiply by weight.

Must only be called with a locked tree

Returns
the overflow, the tokens that could not be distributed.

◆ gather_unspent_for_removal()

virtual std::array<rate::type, 2> gather_unspent_for_removal ( )
protectedpure virtual

Gather unspent tokens during removal to repay debt.

When called, this is locked, children are not.

◆ lock_tree()

virtual void lock_tree ( )
inlineprotectedvirtual

Recursively locks the mutexes of self and all children.

Aggregate buckets need to implement the child traversal.

◆ remove_bucket()

void remove_bucket ( )

Removes the bucket from its parent

///

Warning
You MUST call this function in the destructor of the most derived class

◆ set_mgr_recursive()

virtual void set_mgr_recursive ( rate_limit_manager mgr)
protectedvirtual

Recursively sets the manager.

Must only be called with a locked tree

◆ unsaturated()

virtual size_t unsaturated ( direction::type  const) const
inlineprotectedvirtual

Returns the number of buckets not yet full.

Must only be called with a locked mutex

◆ update_stats()

virtual void update_stats ( bool &  active)
protectedpure virtual

Updates weight and usage statistics.

Must only be called with a locked tree

◆ weight()

virtual size_t weight ( ) const
inlineprotectedvirtual

Returns the weight of the tree.

Must only be called with a locked mutex


The documentation for this class was generated from the following file: