TPIE

2362a60
tpie::resource_manager Class Referenceabstract

Resource management object used to track resource usage. More...

#include <tpie/resource_manager.h>

Inherited by tpie::file_manager, and tpie::memory_manager.

Public Types

enum  enforce_t { ENFORCE_IGNORE, ENFORCE_DEBUG, ENFORCE_WARN, ENFORCE_THROW }
 Memory limit enforcement policies. More...
 

Public Member Functions

size_t used () const noexcept
 Return the current amount of the resource used. More...
 
size_t available () const noexcept
 Return the amount of the resource still available to be assigned. More...
 
size_t limit () const noexcept
 Return the resource limit. More...
 
void set_limit (size_t new_limit)
 Update the resource limit. More...
 
void set_enforcement (enforce_t e)
 Set the resource limit enforcement policy. More...
 
enforce_t enforcement () const noexcept
 Return the current resource limit enforcement policy. More...
 
void register_increased_usage (size_t amount)
 
void register_decreased_usage (size_t amount)
 
virtual std::string amount_with_unit (size_t amount) const
 
 resource_manager (resource_type type)
 

Protected Member Functions

virtual void throw_out_of_resource_error (const std::string &s)=0
 

Protected Attributes

std::atomic< size_t > m_used
 
size_t m_limit
 
size_t m_maxExceeded
 
size_t m_nextWarning
 
enforce_t m_enforce
 
resource_type resource_managed
 

Detailed Description

Resource management object used to track resource usage.

Definition at line 46 of file resource_manager.h.

Member Enumeration Documentation

Memory limit enforcement policies.

Enumerator
ENFORCE_IGNORE 

Ignore when running out of the resource.

ENFORCE_DEBUG 

Log to debug log when the resource limit is exceeded.

Note that not all violations will be logged.

ENFORCE_WARN 

Log a warning when the resource limit is exceeded.

Note that not all violations will be logged.

ENFORCE_THROW 

Throw an out_of_resource_error when the resource limit is exceeded.

Definition at line 51 of file resource_manager.h.

51  {
62  };
Log a warning when the resource limit is exceeded.
Throw an out_of_resource_error when the resource limit is exceeded.
Log to debug log when the resource limit is exceeded.
Ignore when running out of the resource.

Constructor & Destructor Documentation

tpie::resource_manager::resource_manager ( resource_type  type)

Construct the resource manager object.

Member Function Documentation

size_t tpie::resource_manager::available ( ) const
noexcept

Return the amount of the resource still available to be assigned.

Referenced by tpie::ami::stream_old< T >::available_streams().

enforce_t tpie::resource_manager::enforcement ( ) const
inlinenoexcept

Return the current resource limit enforcement policy.

Definition at line 96 of file resource_manager.h.

96 {return m_enforce;}
size_t tpie::resource_manager::limit ( ) const
inlinenoexcept

Return the resource limit.

Definition at line 77 of file resource_manager.h.

77 {return m_limit;}
void tpie::resource_manager::set_enforcement ( enforce_t  e)

Set the resource limit enforcement policy.

Parameters
eThe new enforcement policy.
void tpie::resource_manager::set_limit ( size_t  new_limit)

Update the resource limit.

If the resource limit is exceeded by decreasing the limit, no exception will be thrown.

Parameters
new_limitThe new resource limit.
size_t tpie::resource_manager::used ( ) const
noexcept

Return the current amount of the resource used.


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