summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-01 00:06:31 -0700
committerPixel <pixel@nobis-crew.org>2012-04-01 00:06:31 -0700
commita09746544b188f7908389e0e4818bba90b0f0029 (patch)
treefee65271447810b7b9cb3673ac147eed4515db0d /includes
parent01e69854c5445ea1ae73cfc0f386d1a7c7b687f3 (diff)
More code cleanup.
Diffstat (limited to 'includes')
-rw-r--r--includes/Threads.h32
1 files changed, 23 insertions, 9 deletions
diff --git a/includes/Threads.h b/includes/Threads.h
index 23d664f..46ea365 100644
--- a/includes/Threads.h
+++ b/includes/Threads.h
@@ -15,7 +15,8 @@ class Lock {
void enter() { pthread_mutex_lock(&m_lock); }
void leave() { pthread_mutex_unlock(&m_lock); }
private:
- Lock(const Lock &);
+ Lock(const Lock &) = delete;
+ Lock & operator=(const Lock &) = delete;
pthread_mutex_t m_lock;
template<class T>
friend class Queue;
@@ -26,7 +27,8 @@ class ScopeLock {
ScopeLock(Lock & lock) : m_lock(lock) { m_lock.enter(); }
~ScopeLock() { m_lock.leave(); }
private:
- ScopeLock(const ScopeLock &);
+ ScopeLock(const ScopeLock &) = delete;
+ ScopeLock & operator=(const ScopeLock &) = delete;
Lock & m_lock;
};
@@ -38,7 +40,8 @@ class RWLock {
void enterW() { pthread_rwlock_wrlock(&m_lock); }
void leave() { pthread_rwlock_unlock(&m_lock); }
private:
- RWLock(const RWLock &);
+ RWLock(const RWLock &) = delete;
+ RWLock & operator=(const ScopeLock &) = delete;
pthread_rwlock_t m_lock;
};
@@ -47,7 +50,8 @@ class ScopeLockR {
ScopeLockR(RWLock & lock) : m_lock(lock) { m_lock.enterR(); }
~ScopeLockR() { m_lock.leave(); }
private:
- ScopeLockR(const ScopeLockR &);
+ ScopeLockR(const ScopeLockR &) = delete;
+ ScopeLockR & operator=(const ScopeLockR &) = delete;
RWLock & m_lock;
};
@@ -56,7 +60,8 @@ class ScopeLockW {
ScopeLockW(RWLock & lock) : m_lock(lock) { m_lock.enterW(); }
~ScopeLockW() { m_lock.leave(); }
private:
- ScopeLockW(const ScopeLockW &);
+ ScopeLockW(const ScopeLockW &) = delete;
+ ScopeLockW & operator=(const ScopeLockW &) = delete;
RWLock & m_lock;
};
@@ -72,6 +77,8 @@ class Thread {
virtual void * proc() = 0;
virtual void threadExit() { };
private:
+ Thread(const Thread &) = delete;
+ Thread & operator=(const Thread &) = delete;
pthread_t m_thread;
volatile bool m_joined;
@@ -82,6 +89,8 @@ class GlobalThread : public Thread, public AtStart, public AtExit {
protected:
GlobalThread(int startOrder = 10) : AtStart(startOrder), AtExit(1) { }
private:
+ GlobalThread(const GlobalThread &) = delete;
+ GlobalThread & operator=(const GlobalThread &) = delete;
virtual void doStart() { threadStart(); }
virtual void doExit() { join(); }
};
@@ -102,11 +111,13 @@ class Queue {
m_back = c;
pthread_cond_signal(&m_cond);
}
- T * pop() {
+ T * pop(bool wait = true) {
ScopeLock sl(m_lock);
- while (!m_front)
+ while (!m_front && wait)
pthread_cond_wait(&m_cond, &m_lock.m_lock);
Cell * c = m_front;
+ if (!c)
+ return NULL;
m_front = c->m_next;
if (m_front)
m_front->m_prev = NULL;
@@ -121,10 +132,13 @@ class Queue {
return !m_front;
}
private:
+ Queue(const Queue &) = delete;
+ Queue & operator=(const Queue &) = delete;
Lock m_lock;
- class Cell {
- public:
+ struct Cell {
Cell(T * elem) : m_next(NULL), m_prev(NULL), m_elem(elem) { }
+ Cell(const Cell &) = delete;
+ Cell & operator=(const Cell &) = delete;
Cell * m_next, * m_prev;
T * m_elem;
};