struct QSlotObjectBaseDeleter { // for use with QScopedPointer<QSlotObjectBase,...>
static void cleanup(QtPrivate::QSlotObjectBase *slot) {
- if (slot && !slot->ref.deref() ) slot->destroy();
+ if (slot) slot->destroyIfLastRef();
}
};
static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
callFunction_(0), method_offset_(0), method_relative_(ushort(-1))
{
if (slotObj_)
- slotObj_->ref.ref();
+ slotObj_->ref();
}
/*!
if (semaphore_)
semaphore_->release();
#endif
- if (slotObj_ && !slotObj_->ref.deref())
- slotObj_->destroy();
+ if (slotObj_)
+ slotObj_->destroyIfLastRef();
}
/*!
if (v != &DIRECT_CONNECTION_ONLY)
delete [] v;
}
- if (isSlotObject && !slotObj->ref.deref())
- slotObj->destroy();
+ if (isSlotObject)
+ slotObj->destroyIfLastRef();
}
const QObjectPrivate::StaticMetaCallFunction callFunction = c->callFunction;
const int method_relative = c->method_relative;
if (c->isSlotObject) {
- c->slotObj->ref.ref();
+ c->slotObj->ref();
const QScopedPointer<QtPrivate::QSlotObjectBase, QSlotObjectBaseDeleter> obj(c->slotObj);
locker.unlock();
obj->call(receiver, argv ? argv : empty_argv);
{
if (!sender || !signal || !slotObj || !senderMetaObject) {
qWarning("QObject::connect: invalid null parametter");
- if (slotObj && !slotObj->ref.deref())
- slotObj->destroy();
+ if (slotObj)
+ slotObj->destroyIfLastRef();
return QMetaObject::Connection();
}
int signal_index = -1;
senderMetaObject->static_metacall(QMetaObject::IndexOfMethod, 0, args);
if (signal_index < 0 || signal_index >= QMetaObjectPrivate::get(senderMetaObject)->signalCount) {
qWarning("QObject::connect: signal not found in %s", senderMetaObject->className());
- if (!slotObj->ref.deref())
- slotObj->destroy();
+ slotObj->destroyIfLastRef();
return QMetaObject::Connection(0);
}
signal_index += QMetaObjectPrivate::signalOffset(senderMetaObject);
while (c2) {
if (c2->receiver == receiver && c2->isSlotObject && c2->slotObj->compare(slot)) {
- if (!slotObj->ref.deref())
- slotObj->destroy();
+ slotObj->destroyIfLastRef();
return QMetaObject::Connection();
}
c2 = c2->nextConnectionList;
#endif
// internal base class (interface) containing functions required to call a slot managed by a pointer to function.
- struct QSlotObjectBase {
- QAtomicInt ref;
+ class QSlotObjectBase {
+ QAtomicInt m_ref;
// don't use virtual functions here; we don't want the
// compiler to create tons of per-polymorphic-class stuff that
// we'll never need. We just use one function pointer.
typedef void (*ImplFn)(int which, QSlotObjectBase* this_, QObject *receiver, void **args, bool *ret);
- const ImplFn impl;
+ const ImplFn m_impl;
protected:
enum Operation {
Destroy,
NumOperations
};
public:
- explicit QSlotObjectBase(ImplFn fn) : ref(1), impl(fn) {}
+ explicit QSlotObjectBase(ImplFn fn) : m_ref(1), m_impl(fn) {}
- inline void destroy() { impl(Destroy, this, 0, 0, 0); }
- inline bool compare(void **a) { bool ret; impl(Compare, this, 0, a, &ret); return ret; }
- inline void call(QObject *r, void **a) { impl(Call, this, r, a, 0); }
+ inline int ref() Q_DECL_NOTHROW { return m_ref.ref(); }
+ inline void destroyIfLastRef() Q_DECL_NOTHROW
+ { if (!m_ref.deref()) m_impl(Destroy, this, 0, 0, 0); }
+
+ inline bool compare(void **a) { bool ret; m_impl(Compare, this, 0, a, &ret); return ret; }
+ inline void call(QObject *r, void **a) { m_impl(Call, this, r, a, 0); }
protected:
~QSlotObjectBase() {}
};