tid_t.h

00001 /* -*- mode:C++; c-basic-offset:4 -*-
00002      Shore-MT -- Multi-threaded port of the SHORE storage manager
00003    
00004                        Copyright (c) 2007-2009
00005       Data Intensive Applications and Systems Labaratory (DIAS)
00006                Ecole Polytechnique Federale de Lausanne
00007    
00008                          All Rights Reserved.
00009    
00010    Permission to use, copy, modify and distribute this software and
00011    its documentation is hereby granted, provided that both the
00012    copyright notice and this permission notice appear in all copies of
00013    the software, derivative works or modified versions, and any
00014    portions thereof, and that both notices appear in supporting
00015    documentation.
00016    
00017    This code is distributed in the hope that it will be useful, but
00018    WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
00020    DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
00021    RESULTING FROM THE USE OF THIS SOFTWARE.
00022 */
00023 
00024 // -*- mode:c++; c-basic-offset:4 -*-
00025 /*<std-header orig-src='shore' incl-file-exclusion='TID_T_H'>
00026 
00027  $Id: tid_t.h,v 1.68 2010/06/15 17:28:29 nhall Exp $
00028 
00029 SHORE -- Scalable Heterogeneous Object REpository
00030 
00031 Copyright (c) 1994-99 Computer Sciences Department, University of
00032                       Wisconsin -- Madison
00033 All Rights Reserved.
00034 
00035 Permission to use, copy, modify and distribute this software and its
00036 documentation is hereby granted, provided that both the copyright
00037 notice and this permission notice appear in all copies of the
00038 software, derivative works or modified versions, and any portions
00039 thereof, and that both notices appear in supporting documentation.
00040 
00041 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00042 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00043 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00044 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00045 
00046 This software was developed with support by the Advanced Research
00047 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00048 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00049 Further funding for this work was provided by DARPA through
00050 Rome Research Laboratory Contract No. F30602-97-2-0247.
00051 
00052 */
00053 
00054 #ifndef TID_T_H
00055 #define TID_T_H
00056 
00057 #include "w_defines.h"
00058 
00059 /*  -- do not edit anything above this line --   </std-header>*/
00060 
00061 #include "atomic_templates.h"
00062 
00063 #ifdef __GNUG__
00064 #pragma interface
00065 #endif
00066 
00067 /**\brief Transaction ID
00068  *
00069  * \ingroup IDS
00070  * \details
00071  * Transaction IDs are 64-bit quantities.
00072  * They can be constructed of and used as a pair
00073  * of two 32-bit value, the high and low parts,
00074  * or they can be constructed from a single 64-bit value.
00075  *
00076  * \note The two-part nature comes from the days before 64-bit architectures,
00077  * and it's retained for the purpose of printing transaction ids.
00078  * They are output in the form "hi.low", which is more readable than
00079  * printing as a 64-bit value.  
00080  * In no other way need we maintain high and low parts.
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 /* XXX yes, this is disgusting, but at least it allows it to
00150    be a shore.def option.  In reality, this specification should
00151    be revisited.    These fixed length objects have caused a 
00152    fair amount of problems, and it might be time to rethink the
00153    issue a bit. */
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 /**\typedef opaque_quantity<max_gtid_len> gtid_t
00187  * \brief Global transaction Identifier used for Two-Phase Commit
00188  */
00189 typedef opaque_quantity<max_gtid_len> gtid_t;
00190 /**\typedef opaque_quantity<max_server_handle_len> server_handle_t; 
00191  * \brief Coordinator Handle used for Two-Phase Commit
00192  * */
00193 typedef opaque_quantity<max_server_handle_len> server_handle_t;
00194 
00195 /*<std-footer incl-file-exclusion='TID_T_H'>  -- do not edit anything below this line -- */
00196 
00197 #endif          /*</std-footer>*/

Generated on Thu Dec 9 08:42:26 2010 for Shore Storage Manager by  doxygen 1.4.7