TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cpid::priority_mutex Class Reference

This class implements a mutex that offers some control over the priority of the waiting threads. More...

#include <prioritymutex.h>

Public Member Functions

 priority_mutex (int maxPrio)
 Constructs a mutex. More...
 
 priority_mutex (const priority_mutex &)=delete
 
priority_mutexoperator= (const priority_mutex &)=delete
 
 priority_mutex (priority_mutex &&)=delete
 
void lock (int prio=0)
 
bool try_lock (int prio=0)
 
void unlock ()
 

Protected Member Functions

bool canGo (int prio)
 

Protected Attributes

std::mutex queueMutex_
 
std::mutex dataMutex_
 
std::condition_variable_any queueCV_
 
std::vector< int > queueCount_
 
int maxPrio_
 

Detailed Description

This class implements a mutex that offers some control over the priority of the waiting threads.

If several threads are waiting to obtain the lock, it is guaranteed that the one with the highest priority will get it first. If there are several threads with the same priority level, then the outcome is up to the pthread implementation. Note that if there are always high priority threads in the queue, it will create starvation on the lower priority ones. If used inside a lock from the standard library, this will default to locking with the lowest priority

Constructor & Destructor Documentation

cpid::priority_mutex::priority_mutex ( int  maxPrio)
inline

Constructs a mutex.

Parameters
maxPriois the maximal priority level accepted
cpid::priority_mutex::priority_mutex ( const priority_mutex )
delete
cpid::priority_mutex::priority_mutex ( priority_mutex &&  )
delete

Member Function Documentation

bool cpid::priority_mutex::canGo ( int  prio)
inlineprotected
void cpid::priority_mutex::lock ( int  prio = 0)
inline
priority_mutex& cpid::priority_mutex::operator= ( const priority_mutex )
delete
bool cpid::priority_mutex::try_lock ( int  prio = 0)
inline
void cpid::priority_mutex::unlock ( )
inline

Member Data Documentation

std::mutex cpid::priority_mutex::dataMutex_
protected
int cpid::priority_mutex::maxPrio_
protected
std::vector<int> cpid::priority_mutex::queueCount_
protected
std::condition_variable_any cpid::priority_mutex::queueCV_
protected
std::mutex cpid::priority_mutex::queueMutex_
protected

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