You.i Engine
CYIThreadManager Class Reference

Detailed Description

Allows the user to controls how many threads can be created for a specific use case or application. Each component or user can create its own manager and therefore minimize its impact on the overall system.

CYIThread manager does not hold CYIThread objects, but is more like a permission mechanism to create a new thread.

(Optional) It is possible to configure the maximum number of threads on the system. As more and more managers are added to the system, each manager will interact with the system configuration and adapt the number of available threads in the manager to accomodate all users in a reasaonable way by reducing the available buffers in each manager. Maximum system thread count could be a hard or a soft limit. There could be a parameter to specify the 'minimum' number of threads a manager can have and the system in that case will not allowed to steal threads from that manager and will have to relax its maximum thread requirement. This behaviour may be beneficial for badly configured system.

Ideal situation is not to change the performance of a component by reducing the number of threads available to it through the thread manager, but after some experimentation, set some hard/fixed limits on each component on the system

#include <thread/YiThreadManager.h>

Public Member Functions

 CYIThreadManager ()
 
 ~CYIThreadManager ()
 
uint32_t CreateManager (uint32_t count)
 
void DeleteManager (uint32_t managerId)
 
bool GetThread (uint32_t managerId, uint32_t timeout=0)
 
bool ReleaseThread (uint32_t managerId)
 
bool IsManagerExist (uint32_t managerId) const
 
bool IsManagerActive (uint32_t managerId) const
 
int32_t GetAvailableThreadCount (uint32_t managerId) const
 
int32_t GetCreatedManagerCount () const
 
int32_t GetActiveManagerCount () const
 

Constructor & Destructor Documentation

CYIThreadManager::CYIThreadManager ( )
inline
CYIThreadManager::~CYIThreadManager ( )
inline

Member Function Documentation

uint32_t CYIThreadManager::CreateManager ( uint32_t  count)

Creates a manager with 'count' number of threads in it.

Parameters
countnumber of threads in the manager
Returns
id of the manager created.
void CYIThreadManager::DeleteManager ( uint32_t  managerId)

Deletes a manager.

This marks the manager as deleted. As such, no further request from the manager will succeed. Deletion of the manager is delayed until the last thread user returns the thread to the manager.

This will also unblock all getThread() calls and cause them to return an error.

Parameters
managerIdid of the manager.
int32_t CYIThreadManager::GetActiveManagerCount ( ) const
int32_t CYIThreadManager::GetAvailableThreadCount ( uint32_t  managerId) const
int32_t CYIThreadManager::GetCreatedManagerCount ( ) const
bool CYIThreadManager::GetThread ( uint32_t  managerId,
uint32_t  timeout = 0 
)

Request a thread from a manager.

When successful, number of available thread is reduced by one. When no thread is available, it blocks the calling thread until timeout value is reached. If timeout value is 0, it does not block and simply returns error.

When a very long timeout is given and the caller is blocked, the only way to unblock the caller is to have other users return threads to the manager via CYIThreadManager::releaseThread() or delete the manager via CYIThread::deleteManager().

Parameters
managerIdid of the manager
timeouttimeout value in 'ms'
Returns
true when a thread is available, false otherwise
bool CYIThreadManager::IsManagerActive ( uint32_t  managerId) const
bool CYIThreadManager::IsManagerExist ( uint32_t  managerId) const
bool CYIThreadManager::ReleaseThread ( uint32_t  managerId)

Return a thread to a manager.

Increment the number of available threads by one. This will unblock the first getThread() request that was blocked. Unblocking therefore works in a FIFO fashion.

Parameters
managerIdid of the manager

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