worked on thread safety with tasks
This commit is contained in:
@@ -26,6 +26,8 @@ set(OLIVE_SOURCES
|
||||
common/qobjectlistcast.h
|
||||
common/qtversionabstraction.h
|
||||
common/qtversionabstraction.cpp
|
||||
common/threadedobject.h
|
||||
common/threadedobject.cpp
|
||||
common/timecodefunctions.h
|
||||
common/timecodefunctions.cpp
|
||||
PARENT_SCOPE
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "threadedobject.h"
|
||||
|
||||
ThreadedObject::ThreadedObject()
|
||||
{
|
||||
}
|
||||
|
||||
void ThreadedObject::LockDeletes()
|
||||
{
|
||||
threadobj_delete_lock_++;
|
||||
}
|
||||
|
||||
void ThreadedObject::UnlockDeletes()
|
||||
{
|
||||
Q_ASSERT(AreDeletesLocked());
|
||||
|
||||
threadobj_delete_lock_--;
|
||||
}
|
||||
|
||||
bool ThreadedObject::AreDeletesLocked()
|
||||
{
|
||||
return (threadobj_delete_lock_ > 0);
|
||||
}
|
||||
|
||||
void ThreadedObject::LockMutex()
|
||||
{
|
||||
threadobj_main_lock_.lock();
|
||||
}
|
||||
|
||||
void ThreadedObject::UnlockMutex()
|
||||
{
|
||||
threadobj_main_lock_.unlock();
|
||||
}
|
||||
|
||||
bool ThreadedObject::TryLockMutex(int timeout)
|
||||
{
|
||||
return threadobj_main_lock_.tryLock(timeout);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef THREADEDOBJECT_H
|
||||
#define THREADEDOBJECT_H
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
class ThreadedObject
|
||||
{
|
||||
public:
|
||||
ThreadedObject();
|
||||
|
||||
void LockMutex();
|
||||
void UnlockMutex();
|
||||
bool TryLockMutex(int timeout = 0);
|
||||
|
||||
void LockDeletes();
|
||||
void UnlockDeletes();
|
||||
bool AreDeletesLocked();
|
||||
|
||||
private:
|
||||
QMutex threadobj_main_lock_;
|
||||
|
||||
QAtomicInt threadobj_delete_lock_;
|
||||
};
|
||||
|
||||
#endif // THREADEDOBJECT_H
|
||||
Reference in New Issue
Block a user