safe_roller Class Reference

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

#include <safe_roller.h>

Collaboration diagram for safe_roller:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

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::safe_roller ( int  start_of_range = 0,
int  end_of_range = MAXINT 
)

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 35 of file safe_roller.cpp.

safe_roller::~safe_roller (  ) 

Definition at line 41 of file safe_roller.cpp.

References WHACK().


Member Function Documentation

int safe_roller::next_id (  ) 

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

Definition at line 47 of file safe_roller.cpp.

References mutex_base::lock(), roller< contents >::next_id(), and mutex_base::unlock().

Referenced by octopus::issue_identity().

int 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 55 of file safe_roller.cpp.

References roller< contents >::current(), mutex_base::lock(), and mutex_base::unlock().

void 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 63 of file safe_roller.cpp.

References mutex_base::lock(), roller< contents >::set_current(), and mutex_base::unlock().


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 04:30:57 2008 for HOOPLE Libraries by  doxygen 1.5.1