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 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 #ifndef TID_T_H
00055 #define TID_T_H
00056 
00057 #include "w_defines.h"
00058 
00059 
00060 
00061 #include "atomic_templates.h"
00062 
00063 #ifdef __GNUG__
00064 #pragma interface
00065 #endif
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 class tid_t {
00083 public:
00084     typedef w_base_t::uint8_t datum_t;
00085     enum { hwm = max_uint4 };
00086 
00087     tid_t() : _data(0) { }
00088     tid_t(uint4_t l, uint4_t h) : _data( (((datum_t) h) << 32) | l ) { }
00089     tid_t(datum_t x) : _data(x) { }
00090 
00091     uint4_t get_hi() const { return (uint4_t) (_data >> 32); }
00092     uint4_t get_lo() const { return (uint4_t) _data; }
00093 
00094     tid_t& operator=(const tid_t& t)    {
00095         _data = t._data;
00096         return *this;
00097     }
00098 
00099     bool invalid() const { return _data == 0; }
00100 
00101     datum_t atomic_incr() {
00102         return atomic_inc_nv(_data);
00103     }
00104     tid_t &atomic_assign_max(const tid_t &tid) {
00105         datum_t old_value = _data;
00106         while(tid._data > old_value) {
00107             datum_t cur_value = atomic_cas_64(&_data, old_value, tid._data);
00108             old_value = cur_value;
00109         }
00110         return *this;
00111     }
00112     tid_t &atomic_assign_min(const tid_t &tid) {
00113         datum_t old_value = _data;
00114         while(tid._data < old_value) {
00115             datum_t cur_value = atomic_cas_64(&_data, old_value, tid._data);
00116             old_value = cur_value;
00117         }
00118         return *this;
00119     }
00120 
00121     inline bool operator==(const tid_t& tid) const  {
00122         return _data == tid._data;
00123     }
00124     inline bool operator!=(const tid_t& tid) const  {
00125         return !(*this == tid);
00126     }
00127     inline bool operator<(const tid_t& tid) const  {
00128         return _data < tid._data;
00129     }
00130     inline bool operator<=(const tid_t& tid) const  {
00131         return !(tid < *this);
00132     }
00133     inline bool operator>(const tid_t& tid) const  {
00134         return (tid < *this);
00135     }
00136     inline bool operator>=(const tid_t& tid) const  {
00137         return !(*this < tid);
00138     }
00139 
00140     static const tid_t Max;
00141     static const tid_t null;
00142 
00143 private:
00144 
00145     datum_t        _data;
00146 };
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 #ifdef COMMON_GTID_LENGTH
00155 #define max_gtid_len        COMMON_GTID_LENGTH
00156 #else
00157 #define max_gtid_len  96
00158 #endif
00159 
00160 #ifdef COMMON_SERVER_HANDLE_LENGTH
00161 #define max_server_handle_len  COMMON_SERVER_HANDLE_LENGTH
00162 #else
00163 #define max_server_handle_len  96
00164 #endif
00165 
00166 
00167 #include <w_stream.h>
00168 
00169 inline ostream& operator<<(ostream& o, const tid_t& t)
00170 {
00171     return o << t.get_hi() << '.' << t.get_lo();
00172 }
00173 
00174 inline istream& operator>>(istream& i, tid_t& t)
00175 {
00176     char ch;
00177     uint4_t h, l;
00178     i >> h >> ch >> l;
00179     t = tid_t(l,h);
00180     return i;
00181 }
00182 
00183 
00184 #include "w_opaque.h"
00185 
00186 
00187 
00188 
00189 typedef opaque_quantity<max_gtid_len> gtid_t;
00190 
00191 
00192 
00193 typedef opaque_quantity<max_server_handle_len> server_handle_t;
00194 
00195 
00196 
00197 #endif