From 660e20397400a8242dd24da39e239dcaa2f9adbd Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 6 Aug 2013 15:00:47 +0000 Subject: NO-JIRA: HA remove use of boost_hash, failes to build on some compilers. Removed use of boost::hash entirely, build problems on RHEL5. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1510988 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/ha/AlternateExchangeSetter.h | 1 - qpid/cpp/src/qpid/ha/BrokerInfo.h | 5 +- qpid/cpp/src/qpid/ha/Primary.h | 6 +-- qpid/cpp/src/qpid/ha/PrimaryTxObserver.h | 3 +- qpid/cpp/src/qpid/ha/QueueGuard.h | 4 +- qpid/cpp/src/qpid/ha/QueueReplicator.h | 5 +- qpid/cpp/src/qpid/ha/QueueSnapshots.h | 10 ++-- qpid/cpp/src/qpid/ha/RemoteBackup.h | 8 +-- qpid/cpp/src/qpid/ha/hash.h | 71 ++++++++++++++++++++++++++ 9 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 qpid/cpp/src/qpid/ha/hash.h (limited to 'qpid/cpp/src') diff --git a/qpid/cpp/src/qpid/ha/AlternateExchangeSetter.h b/qpid/cpp/src/qpid/ha/AlternateExchangeSetter.h index 2386a01084..fbf4755e7d 100644 --- a/qpid/cpp/src/qpid/ha/AlternateExchangeSetter.h +++ b/qpid/cpp/src/qpid/ha/AlternateExchangeSetter.h @@ -25,7 +25,6 @@ #include "qpid/log/Statement.h" #include "qpid/broker/Exchange.h" #include "qpid/broker/ExchangeRegistry.h" -#include "boost/function.hpp" #include namespace qpid { diff --git a/qpid/cpp/src/qpid/ha/BrokerInfo.h b/qpid/cpp/src/qpid/ha/BrokerInfo.h index 8e62665088..87d51f5113 100644 --- a/qpid/cpp/src/qpid/ha/BrokerInfo.h +++ b/qpid/cpp/src/qpid/ha/BrokerInfo.h @@ -23,12 +23,12 @@ */ #include "types.h" +#include "hash.h" #include "qpid/Url.h" #include "qpid/framing/FieldTable.h" #include "qpid/types/Uuid.h" #include "qpid/types/Variant.h" #include "qpid/sys/unordered_map.h" -#include #include #include #include @@ -43,8 +43,7 @@ class BrokerInfo { public: typedef std::set Set; - typedef qpid::sys::unordered_map > Map; + typedef qpid::sys::unordered_map > Map; BrokerInfo(); BrokerInfo(const types::Uuid& id, BrokerStatus, const Address& = Address()); diff --git a/qpid/cpp/src/qpid/ha/Primary.h b/qpid/cpp/src/qpid/ha/Primary.h index c13d60991e..0affc49508 100644 --- a/qpid/cpp/src/qpid/ha/Primary.h +++ b/qpid/cpp/src/qpid/ha/Primary.h @@ -23,13 +23,13 @@ */ #include "types.h" +#include "hash.h" #include "BrokerInfo.h" #include "ReplicationTest.h" #include "Role.h" #include "qpid/sys/Mutex.h" #include "qpid/sys/unordered_map.h" #include -#include #include #include @@ -105,13 +105,13 @@ class Primary : public Role private: typedef sys::unordered_map< - types::Uuid, RemoteBackupPtr, boost::hash > BackupMap; + types::Uuid, RemoteBackupPtr, Hasher > BackupMap; typedef std::set BackupSet; typedef std::pair > UuidQueue; typedef sys::unordered_map > ReplicaMap; + Hasher > ReplicaMap; RemoteBackupPtr backupConnect(const BrokerInfo&, broker::Connection&, sys::Mutex::ScopedLock&); void backupDisconnect(RemoteBackupPtr, sys::Mutex::ScopedLock&); diff --git a/qpid/cpp/src/qpid/ha/PrimaryTxObserver.h b/qpid/cpp/src/qpid/ha/PrimaryTxObserver.h index 2c207c55fa..4efdf06c42 100644 --- a/qpid/cpp/src/qpid/ha/PrimaryTxObserver.h +++ b/qpid/cpp/src/qpid/ha/PrimaryTxObserver.h @@ -29,7 +29,6 @@ #include "qpid/types/Uuid.h" #include "qpid/sys/unordered_map.h" #include "qpid/sys/Monitor.h" -#include #include namespace qpid { @@ -79,7 +78,7 @@ class PrimaryTxObserver : public broker::TransactionObserver, private: class Exchange; typedef qpid::sys::unordered_map< - QueuePtr, ReplicationIdSet, boost::hash > QueueIdsMap; + QueuePtr, ReplicationIdSet, Hasher > QueueIdsMap; void membership(const BrokerInfo::Map&); void deduplicate(sys::Mutex::ScopedLock&); diff --git a/qpid/cpp/src/qpid/ha/QueueGuard.h b/qpid/cpp/src/qpid/ha/QueueGuard.h index 5a5f80996d..33967970eb 100644 --- a/qpid/cpp/src/qpid/ha/QueueGuard.h +++ b/qpid/cpp/src/qpid/ha/QueueGuard.h @@ -23,12 +23,12 @@ */ #include "types.h" +#include "hash.h" #include "qpid/types/Uuid.h" #include "qpid/sys/Mutex.h" #include "qpid/sys/unordered_map.h" #include #include -#include #include #include @@ -89,7 +89,7 @@ class QueueGuard { class QueueObserver; typedef qpid::sys::unordered_map, - boost::hash > Delayed; + Hasher > Delayed; bool complete(ReplicationId, sys::Mutex::ScopedLock &); void complete(Delayed::iterator, sys::Mutex::ScopedLock &); diff --git a/qpid/cpp/src/qpid/ha/QueueReplicator.h b/qpid/cpp/src/qpid/ha/QueueReplicator.h index 24baeb9a89..cc6c7ed2a7 100644 --- a/qpid/cpp/src/qpid/ha/QueueReplicator.h +++ b/qpid/cpp/src/qpid/ha/QueueReplicator.h @@ -23,10 +23,9 @@ */ #include "BrokerInfo.h" +#include "hash.h" #include "qpid/broker/Exchange.h" #include -#include -#include #include namespace qpid { @@ -106,7 +105,7 @@ class QueueReplicator : public broker::Exchange, private: typedef qpid::sys::unordered_map< - ReplicationId, QueuePosition, boost::hash > PositionMap; + ReplicationId, QueuePosition, Hasher > PositionMap; class ErrorListener; class QueueObserver; diff --git a/qpid/cpp/src/qpid/ha/QueueSnapshots.h b/qpid/cpp/src/qpid/ha/QueueSnapshots.h index c12ee743e8..d067b983d1 100644 --- a/qpid/cpp/src/qpid/ha/QueueSnapshots.h +++ b/qpid/cpp/src/qpid/ha/QueueSnapshots.h @@ -24,6 +24,7 @@ #include "QueueSnapshot.h" +#include "hash.h" #include "qpid/assert.h" #include "qpid/broker/BrokerObserver.h" @@ -31,7 +32,6 @@ #include "qpid/sys/Mutex.h" #include -#include namespace qpid { namespace ha { @@ -67,10 +67,10 @@ class QueueSnapshots : public broker::BrokerObserver } private: - typedef qpid::sys::unordered_map< - boost::shared_ptr, boost::shared_ptr, - boost::hash > > SnapshotMap; - + typedef qpid::sys::unordered_map, + boost::shared_ptr, + Hasher > + > SnapshotMap; SnapshotMap snapshots; mutable sys::Mutex lock; }; diff --git a/qpid/cpp/src/qpid/ha/RemoteBackup.h b/qpid/cpp/src/qpid/ha/RemoteBackup.h index d2533e8b5c..b9e2e1a496 100644 --- a/qpid/cpp/src/qpid/ha/RemoteBackup.h +++ b/qpid/cpp/src/qpid/ha/RemoteBackup.h @@ -25,8 +25,8 @@ #include "ReplicationTest.h" #include "BrokerInfo.h" #include "types.h" +#include "hash.h" #include "qpid/sys/unordered_map.h" -#include #include namespace qpid { @@ -96,8 +96,10 @@ class RemoteBackup void startCatchup() { started = true; } private: - typedef qpid::sys::unordered_map > GuardMap; + typedef qpid::sys::unordered_map< + QueuePtr, GuardPtr, Hasher > + > GuardMap; + typedef std::set QueueSet; std::string logPrefix; diff --git a/qpid/cpp/src/qpid/ha/hash.h b/qpid/cpp/src/qpid/ha/hash.h new file mode 100644 index 0000000000..8a7f3c00fe --- /dev/null +++ b/qpid/cpp/src/qpid/ha/hash.h @@ -0,0 +1,71 @@ +#ifndef QPID_HA_HASH_H +#define QPID_HA_HASH_H + +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +#include "qpid/types/Uuid.h" +#include +#include + +namespace qpid { +namespace ha { + +// TODO aconway 2013-08-06: would like to use boost::hash or std::hash here +// but not available/working on some older compilers. +// Add overloads as needed. + +inline std::size_t hashValue(bool v) { return static_cast(v); } +inline std::size_t hashValue(char v) { return static_cast(v); } +inline std::size_t hashValue(unsigned char v) { return static_cast(v); } +inline std::size_t hashValue(signed char v) { return static_cast(v); } +inline std::size_t hashValue(short v) { return static_cast(v); } +inline std::size_t hashValue(unsigned short v) { return static_cast(v); } +inline std::size_t hashValue(int v) { return static_cast(v); } +inline std::size_t hashValue(unsigned int v) { return static_cast(v); } +inline std::size_t hashValue(long v) { return static_cast(v); } +inline std::size_t hashValue(unsigned long v) { return static_cast(v); } + +inline std::size_t hashValue(const types::Uuid& v) { return v.hash(); } + +template inline std::size_t hashValue(T* v) { + std::size_t x = static_cast(reinterpret_cast(v)); + return x + (x >> 3); +} + +template inline void hashCombine(std::size_t& seed, const T& v) { + seed ^= hashValue(v) + 0x9e3779b9 + (seed<<6) + (seed>>2); +} + +template inline size_t hashValue(const std::pair& v) { + std::size_t seed = 0; + hashCombine(seed, v.first); + hashCombine(seed, v.second); + return seed; +} + +template struct Hasher { + size_t operator()(const T& v) const { return hashValue(v); } +}; + +}} // namespace qpid::ha + +#endif /*!QPID_HA_HASH_H*/ -- cgit v1.2.1