feisty meow concerns codebase  2.140
processes::safe_roller Class Reference

Implements a thread-safe roller object. More...

#include <safe_roller.h>

Public Member Functions

 safe_roller (int start_of_range=0, int end_of_range=MAXINT32)
 Provides numbers between the start and end in a thread-safe way. More...
 
 ~safe_roller ()
 
int next_id ()
 returns a unique (per instance of this type) id. More...
 
int current () const
 returns the current id to be used; be careful! More...
 
void set_current (int new_current)
 allows the current id to be manipulated. More...
 

Detailed Description

Implements a thread-safe roller object.

Integers can be generated by this object without concern for corruption by multiple threads.

Definition at line 29 of file safe_roller.h.

Constructor & Destructor Documentation

◆ safe_roller()

processes::safe_roller::safe_roller ( int  start_of_range = 0,
int  end_of_range = MAXINT32 
)

Provides numbers between the start and end in a thread-safe way.

constructs a roller that runs from the value "start_of_range" and will stay smaller than "end_of_range" (unless the initial parameters are screwed up; this class doesn't validate the start and end of range). when the roller hits the end of range, then its value is reset to the "start_of_range" again.

Definition at line 37 of file safe_roller.cpp.

◆ ~safe_roller()

processes::safe_roller::~safe_roller ( )

Definition at line 43 of file safe_roller.cpp.

References basis::WHACK().

Member Function Documentation

◆ current()

int processes::safe_roller::current ( ) const

returns the current id to be used; be careful!

this value will be the next one returned, so only look at the current id and don't use it unwisely. this function is useful if you want to assign an id provisionally but might not want to complete the issuance of it.

Definition at line 57 of file safe_roller.cpp.

References structures::roller< contents >::current(), basis::mutex::lock(), and basis::mutex::unlock().

◆ next_id()

int processes::safe_roller::next_id ( )

returns a unique (per instance of this type) id.

Definition at line 49 of file safe_roller.cpp.

References basis::mutex::lock(), structures::roller< contents >::next_id(), and basis::mutex::unlock().

Referenced by octopi::octopus::issue_identity().

◆ set_current()

void processes::safe_roller::set_current ( int  new_current)

allows the current id to be manipulated.

this must be done with care lest existing ids be re-used.

Definition at line 65 of file safe_roller.cpp.

References basis::mutex::lock(), structures::roller< contents >::set_current(), and basis::mutex::unlock().


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