mirror of https://github.com/Icinga/icinga2.git
parent
c6a015e317
commit
d2cd4b6667
|
@ -91,4 +91,13 @@
|
|||
# define I2_BASE_API I2_IMPORT
|
||||
#endif /* I2_BASE_BUILD */
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# define likely(x) __builtin_expect(!!(x), 1)
|
||||
# define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* I2BASE_H */
|
||||
|
|
|
@ -191,7 +191,7 @@ inline void intrusive_ptr_release(Object *object)
|
|||
refs = __sync_sub_and_fetch(&object->m_References, 1);
|
||||
#endif /* _WIN32 */
|
||||
|
||||
if (refs == 0) {
|
||||
if (unlikely(refs == 0)) {
|
||||
#ifdef I2_LEAK_DEBUG
|
||||
TypeRemoveObject(object);
|
||||
#endif /* I2_LEAK_DEBUG */
|
||||
|
|
|
@ -62,14 +62,14 @@ public:
|
|||
|
||||
#ifdef _WIN32
|
||||
# ifdef _WIN64
|
||||
while (InterlockedCompareExchange64((LONGLONG *)&object->m_Mutex, I2MUTEX_LOCKED, I2MUTEX_UNLOCKED) != I2MUTEX_UNLOCKED) {
|
||||
while (likely(InterlockedCompareExchange64((LONGLONG *)&object->m_Mutex, I2MUTEX_LOCKED, I2MUTEX_UNLOCKED) != I2MUTEX_UNLOCKED)) {
|
||||
# else /* _WIN64 */
|
||||
while (InterlockedCompareExchange(&object->m_Mutex, I2MUTEX_LOCKED, I2MUTEX_UNLOCKED) != I2MUTEX_UNLOCKED) {
|
||||
while (likely(InterlockedCompareExchange(&object->m_Mutex, I2MUTEX_LOCKED, I2MUTEX_UNLOCKED) != I2MUTEX_UNLOCKED)) {
|
||||
# endif /* _WIN64 */
|
||||
#else /* _WIN32 */
|
||||
while (!__sync_bool_compare_and_swap(&object->m_Mutex, I2MUTEX_UNLOCKED, I2MUTEX_LOCKED)) {
|
||||
while (likely(!__sync_bool_compare_and_swap(&object->m_Mutex, I2MUTEX_UNLOCKED, I2MUTEX_LOCKED))) {
|
||||
#endif /* _WIN32 */
|
||||
if (object->m_Mutex > I2MUTEX_LOCKED) {
|
||||
if (likely(object->m_Mutex > I2MUTEX_LOCKED)) {
|
||||
boost::recursive_mutex *mtx = reinterpret_cast<boost::recursive_mutex *>(object->m_Mutex);
|
||||
mtx->lock();
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ public:
|
|||
if (!IsObject())
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error("Cannot convert value of type '" + GetTypeName() + "' to an object."));
|
||||
|
||||
Object::Ptr object = boost::get<Object::Ptr>(m_Value);
|
||||
const Object::Ptr& object = boost::get<Object::Ptr>(m_Value);
|
||||
|
||||
ASSERT(object);
|
||||
|
||||
|
|
|
@ -193,10 +193,10 @@ public:
|
|||
|
||||
static inline Value GetField(const Value& context, const String& field, bool sandboxed = false, const DebugInfo& debugInfo = DebugInfo())
|
||||
{
|
||||
if (context.IsEmpty() && !context.IsString())
|
||||
if (unlikely(context.IsEmpty() && !context.IsString()))
|
||||
return Empty;
|
||||
|
||||
if (!context.IsObject())
|
||||
if (unlikely(!context.IsObject()))
|
||||
return GetPrototypeField(context, field, true, debugInfo);
|
||||
|
||||
Object::Ptr object = context;
|
||||
|
|
Loading…
Reference in New Issue