00001 /* 00002 // $Id: //open/dev/fennel/synch/LockHolderId.h#5 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2007-2009 The Eigenbase Project 00005 // Copyright (C) 2007-2009 SQLstream, Inc. 00006 // Copyright (C) 2007-2009 LucidEra, Inc. 00007 // 00008 // This program is free software; you can redistribute it and/or modify it 00009 // under the terms of the GNU General Public License as published by the Free 00010 // Software Foundation; either version 2 of the License, or (at your option) 00011 // any later version approved by The Eigenbase Project. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef Fennel_LockHolderId_Included 00024 #define Fennel_LockHolderId_Included 00025 00026 FENNEL_BEGIN_NAMESPACE 00027 00035 class FENNEL_SYNCH_EXPORT LockHolderId 00036 { 00037 enum HolderType { 00038 TYPE_NULL, 00039 TYPE_THREAD, 00040 TYPE_TXN 00041 }; 00042 00043 TxnId holderId; 00044 HolderType holderType; 00045 00046 public: 00050 explicit inline LockHolderId(); 00051 00058 explicit inline LockHolderId(TxnId txnId); 00059 00066 inline void assignFrom(TxnId txnId); 00067 00071 inline bool isNull() const; 00072 00076 inline void setNull(); 00077 00086 inline int operator == (LockHolderId const & other) const; 00087 }; 00088 00089 inline void LockHolderId::assignFrom(TxnId txnId) 00090 { 00091 if (txnId == IMPLICIT_TXN_ID) { 00092 // NOTE jvs 2-Jun-2007: Not exactly posixly correct, 00093 // but it will probably do for most environments. 00094 holderId = TxnId(uint(getCurrentThreadId())); 00095 holderType = TYPE_THREAD; 00096 } else { 00097 holderId = txnId; 00098 holderType = TYPE_TXN; 00099 } 00100 } 00101 00102 void LockHolderId::setNull() 00103 { 00104 holderId = NULL_TXN_ID; 00105 holderType = TYPE_NULL; 00106 } 00107 00108 inline LockHolderId::LockHolderId() 00109 { 00110 setNull(); 00111 } 00112 00113 inline LockHolderId::LockHolderId(TxnId txnId) 00114 { 00115 assignFrom(txnId); 00116 } 00117 00118 inline bool LockHolderId::isNull() const 00119 { 00120 return holderType == TYPE_NULL; 00121 } 00122 00123 inline int LockHolderId::operator == (LockHolderId const & other) const 00124 { 00125 return (holderId == other.holderId) 00126 && (holderType == other.holderType); 00127 } 00128 00129 FENNEL_END_NAMESPACE 00130 00131 #endif 00132 00133 // End LockHolderId.h