00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00028
00029 #ifndef STATISTICS_HPP
00030 #define STATISTICS_HPP
00031
00032 #include "../my_config.h"
00033
00034 #include "infinint.hpp"
00035
00036 extern "C"
00037 {
00038 #if MUTEX_WORKS
00039 #if HAVE_PTHREAD_H
00040 #include <pthread.h>
00041 #endif
00042 #endif
00043 }
00044
00045 #if MUTEX_WORKS
00046 #define LOCK_IN pthread_mutex_lock(&lock_mutex)
00047 #define LOCK_OUT pthread_mutex_unlock(&lock_mutex)
00048 #define LOCK_IN_CONST pthread_mutex_lock(const_cast<pthread_mutex_t *>(&lock_mutex))
00049 #define LOCK_OUT_CONST pthread_mutex_unlock(const_cast<pthread_mutex_t *>(&lock_mutex))
00050 #else
00051 #define LOCK_IN //
00052 #define LOCK_OUT //
00053 #define LOCK_IN_CONST //
00054 #define LOCK_OUT_CONST //
00055 #endif
00056
00057 namespace libdar
00058 {
00059
00061
00065
00067 class statistics
00068 {
00069 public:
00071
00077 statistics(bool lock = true) { init(lock); clear(); };
00078 statistics(const statistics & ref) { copy_from(ref); };
00079 statistics & operator = (const statistics & ref) { detruit(); copy_from(ref); return *this; };
00080
00082 ~statistics() { detruit(); };
00083
00085 void clear();
00086
00088 infinint total() const;
00089
00090 void incr_treated() { (this->*increment)(&treated); };
00091 void incr_hard_links() { (this->*increment)(&hard_links); };
00092 void incr_skipped() { (this->*increment)(&skipped); };
00093 void incr_ignored() { (this->*increment)(&ignored); };
00094 void incr_tooold() { (this->*increment)(&tooold); };
00095 void incr_errored() { (this->*increment)(&errored); };
00096 void incr_deleted() { (this->*increment)(&deleted); };
00097 void incr_ea_treated() { (this->*increment)(&ea_treated); };
00098
00099 void add_to_ignored(const infinint & val) { (this->*add_to)(&ignored, val); };
00100 void add_to_errored(const infinint & val) { (this->*add_to)(&errored, val); };
00101 void add_to_deleted(const infinint & val) { (this->*add_to)(&deleted, val); };
00102
00103 infinint get_treated() const { return (this->*returned)(&treated); };
00104 infinint get_hard_links() const { return (this->*returned)(&hard_links); };
00105 infinint get_skipped() const { return (this->*returned)(&skipped); };
00106 infinint get_ignored() const { return (this->*returned)(&ignored); };
00107 infinint get_tooold() const { return (this->*returned)(&tooold); };
00108 infinint get_errored() const { return (this->*returned)(&errored); };
00109 infinint get_deleted() const { return (this->*returned)(&deleted); };
00110 infinint get_ea_treated() const { return (this->*returned)(&ea_treated); };
00111
00112 private:
00113 #if MUTEX_WORKS
00114 pthread_mutex_t lock_mutex;
00115 #endif
00116 bool locking;
00117
00118 infinint treated;
00119 infinint hard_links;
00120 infinint skipped;
00121 infinint ignored;
00122 infinint tooold;
00123 infinint errored;
00124 infinint deleted;
00125 infinint ea_treated;
00126
00127
00128 void (statistics::*increment)(infinint * var);
00129 void (statistics::*add_to)(infinint * var, const infinint & val);
00130 infinint (statistics::*returned)(const infinint * var) const;
00131
00132 void increment_locked(infinint * var)
00133 {
00134 LOCK_IN;
00135 (*var)++;
00136 LOCK_OUT;
00137 };
00138
00139 void increment_unlocked(infinint * var)
00140 {
00141 (*var)++;
00142 }
00143
00144 void add_to_locked(infinint * var, const infinint & val)
00145 {
00146 LOCK_IN;
00147 (*var) += val;
00148 LOCK_OUT;
00149 }
00150
00151 void add_to_unlocked(infinint *var, const infinint & val)
00152 {
00153 (*var) += val;
00154 }
00155
00156 infinint returned_locked(const infinint * var) const
00157 {
00158 infinint ret;
00159
00160 LOCK_IN_CONST;
00161 ret = *var;
00162 LOCK_OUT_CONST;
00163
00164 return ret;
00165 };
00166
00167 infinint returned_unlocked(const infinint * var) const
00168 {
00169 return *var;
00170 };
00171
00172 void init(bool lock);
00173 void detruit();
00174 void copy_from(const statistics & ref);
00175
00176 };
00177
00178 }
00179
00180 #endif