Skip to content
Snippets Groups Projects
Verified Commit 944af311 authored by Adam Edward Barton's avatar Adam Edward Barton :speech_balloon:
Browse files

Add UnlikelyMacros to sanity checks

parent e7404913
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@
#include "GaudiKernel/DataObject.h"
#include "EventContainers/IdentifiableContainerBase.h"
#include "EventContainers/IDC_WriteHandleBase.h"
#include "CxxUtils/AthUnlikelyMacros.h"
//const_iterator and indexFind are provided for backwards compatability. they are not optimal
/*
IT is faster to iterate over the container with this method:
......@@ -65,14 +65,14 @@ public:
Swap(*this, other);
}
StatusCode addOrDelete(std::unique_ptr<T> ptr, bool &deleted){
if(m_IDC_ptr==nullptr) return StatusCode::FAILURE;
if(ATH_UNLIKELY(m_IDC_ptr==nullptr)) return StatusCode::FAILURE;
StatusCode sc = m_IDC_ptr->addOrDelete(std::move(ptr), m_hashId, deleted);
IDC_WriteHandleBase::ReleaseLock();
m_alreadyPresent = true;
return sc;
}
StatusCode addOrDelete(std::unique_ptr<T> ptr){
if(m_IDC_ptr==nullptr) return StatusCode::FAILURE;
if(ATH_UNLIKELY(m_IDC_ptr==nullptr)) return StatusCode::FAILURE;
StatusCode sc = m_IDC_ptr->addOrDelete(std::move(ptr), m_hashId);
IDC_WriteHandleBase::ReleaseLock();
m_alreadyPresent = true;
......@@ -373,7 +373,7 @@ StatusCode
IdentifiableContainerMT<T>::addCollection(const T* coll, IdentifierHash hashId)
{
// update m_hashids
if (! castCache()->add(hashId, coll)) return StatusCode::FAILURE;
if (ATH_UNLIKELY(! castCache()->add(hashId, coll))) return StatusCode::FAILURE;
m_mask[hashId] = true;
return StatusCode::SUCCESS;
......@@ -415,7 +415,7 @@ template < class T >
StatusCode
IdentifiableContainerMT<T>::naughtyRetrieve(IdentifierHash hashId, T* &collToRetrieve) const
{
if(m_OnlineMode) return StatusCode::FAILURE;//NEVER ALLOW FOR EXTERNAL CACHE
if(ATH_UNLIKELY(m_OnlineMode)) return StatusCode::FAILURE;//NEVER ALLOW FOR EXTERNAL CACHE
else {
collToRetrieve = const_cast< T* > (castCache()->find(hashId));//collToRetrieve can be null on success
return StatusCode::SUCCESS;
......@@ -426,7 +426,7 @@ template < class T>
StatusCode
IdentifiableContainerMT<T>::addOrDelete(std::unique_ptr<T> ptr, IdentifierHash hashId)
{
if(hashId >= m_mask.size()) return StatusCode::FAILURE;
if(ATH_UNLIKELY(hashId >= m_mask.size())) return StatusCode::FAILURE;
bool added = castCache()->add(hashId, std::move(ptr));
m_mask[hashId] = true;
if(added) {
......@@ -440,7 +440,7 @@ template < class T>
StatusCode
IdentifiableContainerMT<T>::addOrDelete(std::unique_ptr<T> ptr, IdentifierHash hashId, bool &deleted)
{
if(hashId >= m_mask.size()) return StatusCode::FAILURE;
if(ATH_UNLIKELY(hashId >= m_mask.size())) return StatusCode::FAILURE;
bool added = castCache()->add(hashId, std::move(ptr));
m_mask[hashId] = true;
deleted = !added;
......
......@@ -16,7 +16,7 @@
// INVALID --- Conversion in progress or intention to add soon.
#include "EventContainers/IdentifiableCacheBase.h"
#include "CxxUtils/AthUnlikelyMacros.h"
namespace EventContainers {
......@@ -123,7 +123,7 @@ int IdentifiableCacheBase::itemInProgress (IdentifierHash hash){
const void* IdentifiableCacheBase::find (IdentifierHash hash)
{
if (hash >= m_vec.size()) return nullptr;
if (ATH_UNLIKELY(hash >= m_vec.size())) return nullptr;
const void* p = m_vec[hash].load();
if (p >= ABORTED)
return nullptr;
......@@ -153,7 +153,7 @@ void IdentifiableCacheBase::cancelWait(IdentifierHash hash){
#endif
const void* IdentifiableCacheBase::findWait (IdentifierHash hash)
{
if (hash >= m_vec.size()) return nullptr;
if (ATH_UNLIKELY(hash >= m_vec.size())) return nullptr;
const void* p = waitFor(hash);
if(p>=ABORTED) return nullptr;
return p;
......@@ -171,7 +171,7 @@ const void* IdentifiableCacheBase::get (IdentifierHash hash)
{
// If it's there already, return directly without locking.
const void* ptr = nullptr;
if (hash >= m_vec.size()) return ptr;
if (ATH_UNLIKELY(hash >= m_vec.size())) return ptr;
if(m_vec[hash].compare_exchange_strong(ptr, INVALID) ) {//Exchanges ptr with current value!!
// Make the payload.
......@@ -248,7 +248,7 @@ std::vector<IdentifierHash> IdentifiableCacheBase::ids()
bool IdentifiableCacheBase::add (IdentifierHash hash, const void* p)
{
if (hash >= m_vec.size()) return false;
if (ATH_UNLIKELY(hash >= m_vec.size())) return false;
if(p==nullptr) return false;
const void* nul=nullptr;
if(m_vec[hash].compare_exchange_strong(nul, p)){
......
......@@ -4,6 +4,7 @@
#include "EventContainers/IdentifiableContainerBase.h"
#include <algorithm>
#include "EventContainers/IDC_WriteHandleBase.h"
#include "CxxUtils/AthUnlikelyMacros.h"
IdentifiableContainerBase::IdentifiableContainerBase(EventContainers::IdentifiableCacheBase *cache, bool online)
{
......@@ -95,14 +96,14 @@
}
StatusCode IdentifiableContainerBase::fetchOrCreate(IdentifierHash hashId){
if(!m_cacheLink->IMakerPresent()) return StatusCode::FAILURE;
if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
auto ptr = m_cacheLink->get(hashId);
m_mask[hashId] = ptr !=nullptr;
return StatusCode::SUCCESS;
}
StatusCode IdentifiableContainerBase::fetchOrCreate(const std::vector<IdentifierHash> &hashIds){
if(!m_cacheLink->IMakerPresent()) return StatusCode::FAILURE;
if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
m_cacheLink->createSet(hashIds, m_mask);
return StatusCode::SUCCESS;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment