00001 #ifndef SAFE_ROLLER_IMPLEMENTATION_FILE 00002 #define SAFE_ROLLER_IMPLEMENTATION_FILE 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : safe_roller * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 1998-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "roller.cpp" 00019 #include "safe_roller.h" 00020 00021 #include <basis/function.h> 00022 #include <basis/mutex.h> 00023 #include <data_struct/static_memory_gremlin.h> 00024 00025 SAFE_STATIC(mutex, __roller_synch, ) 00026 00027 void safe_add(int &to_change, int addition) 00028 { 00029 auto_synchronizer l(__roller_synch()); 00030 to_change += addition; 00031 } 00032 00034 00035 safe_roller::safe_roller(int start_of_range, int end_of_range) 00036 : _rolling(new int_roller(start_of_range, end_of_range)), 00037 _lock(new mutex) 00038 { 00039 } 00040 00041 safe_roller::~safe_roller() 00042 { 00043 WHACK(_rolling); 00044 WHACK(_lock); 00045 } 00046 00047 int safe_roller::next_id() 00048 { 00049 _lock->lock(); 00050 int to_return = _rolling->next_id(); 00051 _lock->unlock(); 00052 return to_return; 00053 } 00054 00055 int safe_roller::current() const 00056 { 00057 _lock->lock(); 00058 int to_return = _rolling->current(); 00059 _lock->unlock(); 00060 return to_return; 00061 } 00062 00063 void safe_roller::set_current(int new_current) 00064 { 00065 _lock->lock(); 00066 _rolling->set_current(new_current); 00067 _lock->unlock(); 00068 } 00069 00070 00071 #endif //SAFE_ROLLER_IMPLEMENTATION_FILE 00072
1.5.1