feisty meow concerns codebase  2.140
safe_roller.h
Go to the documentation of this file.
1 #ifndef SAFE_ROLLER_CLASS
2 #define SAFE_ROLLER_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : safe_roller *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1998-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/mutex.h>
19 #include <structures/roller.h>
20 
21 namespace processes {
22 
24 
30 {
31 public:
32  safe_roller(int start_of_range = 0, int end_of_range = MAXINT32);
34 
40  ~safe_roller();
41 
42  int next_id();
44 
45  int current() const;
47 
52  void set_current(int new_current);
54 
56 private:
57  structures::int_roller *_rolling;
58  basis::mutex *_lock;
59 
60  // forbidden...
61  safe_roller(const safe_roller &);
62  safe_roller &operator =(const safe_roller &);
63 };
64 
66 
67 void safe_add(int &to_change, int addition);
69 
73 } //namespace.
74 
75 #endif
76 
Implements a thread-safe roller object.
Definition: safe_roller.h:30
int next_id()
returns a unique (per instance of this type) id.
Definition: safe_roller.cpp:49
void set_current(int new_current)
allows the current id to be manipulated.
Definition: safe_roller.cpp:65
safe_roller(int start_of_range=0, int end_of_range=MAXINT32)
Provides numbers between the start and end in a thread-safe way.
Definition: safe_roller.cpp:37
int current() const
returns the current id to be used; be careful!
Definition: safe_roller.cpp:57
A roller that's based on integers. This is the most common type so far.
Definition: roller.h:79
#define MAXINT32
Maximum 32-bit integer value.
Definition: definitions.h:75
void safe_add(int &to_change, int addition)
thread-safe integer addition.
Definition: safe_roller.cpp:29