#include <safe_roller.h>
Collaboration diagram for safe_roller:

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. | |
Integers can be generated by this object without concern for corruption by multiple threads.
Definition at line 29 of file safe_roller.h.
| 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 | ( | ) |
| 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().
1.5.1