API  4.3
For MATLAB, Python, Java, and C++ users
OpenSim::ThreadsafeJar< T > Class Template Reference

This class lets you store objects of a single type for reuse by multiple threads, ensuring threadsafe access to each of those objects. More...

Public Member Functions

std::unique_ptr< T > take ()
 Request an object for your exclusive use on your thread. More...
 
void leave (std::unique_ptr< T > entry)
 Add or return an object so that another thread can use it. More...
 
int size () const
 Obtain the number of entries that can be taken. More...
 

Detailed Description

template<typename T>
class OpenSim::ThreadsafeJar< T >

This class lets you store objects of a single type for reuse by multiple threads, ensuring threadsafe access to each of those objects.

Member Function Documentation

◆ leave()

template<typename T >
void OpenSim::ThreadsafeJar< T >::leave ( std::unique_ptr< T >  entry)
inline

Add or return an object so that another thread can use it.

You will need to std::move() the entry, ensuring that you will no longer have access to the entry in your code (the pointer will now be null).

◆ size()

template<typename T >
int OpenSim::ThreadsafeJar< T >::size ( ) const
inline

Obtain the number of entries that can be taken.

◆ take()

template<typename T >
std::unique_ptr<T> OpenSim::ThreadsafeJar< T >::take ( )
inline

Request an object for your exclusive use on your thread.

This function blocks the thread until an object is available. Make sure to return (leave()) the object when you're done!


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