summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2005-10-08 15:56:24 +0000
committerdeva <deva>2005-10-08 15:56:24 +0000
commitb6a85d646c94f8b1efc51c4a50a644fc902c9521 (patch)
tree8206479fc2eff08586badcd2ca8b1b766717c3a5
parent3338a985ce001f4d73aaefa450e008b10496273b (diff)
*** empty log message ***
-rw-r--r--src/Makefile.am4
-rw-r--r--src/mutex.cc48
-rw-r--r--src/mutex.h45
-rw-r--r--src/semaphore.cc48
-rw-r--r--src/semaphore.h2
-rw-r--r--src/threadsafe_queue.h20
-rw-r--r--src/threadsafe_queue_fifo.h26
-rw-r--r--src/threadsafe_queue_priority.cc24
8 files changed, 190 insertions, 27 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b0ed05f..effa384 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,10 +36,12 @@ miav_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \
mov_encoder_writer.cc \
multicast.cc \
multiplexer.cc \
+ mutex.cc \
network.cc \
player.cc \
server.cc \
server_status.cc \
+ semaphore.cc \
socket.cc \
thread.cc \
threadsafe_queue.cc \
@@ -87,12 +89,14 @@ EXTRA_DIST = \
mov_encoder_writer.h \
multicast.h \
multiplexer.h \
+ mutex.h \
network.h \
package.h \
player.h \
queue.h \
server.h \
server_status.h \
+ semaphore.h \
socket.h \
thread.h \
threadsafe_queue.h \
diff --git a/src/mutex.cc b/src/mutex.cc
new file mode 100644
index 0000000..483d71a
--- /dev/null
+++ b/src/mutex.cc
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * mutex.cc
+ *
+ * Sat Oct 8 17:44:09 CEST 2005
+ * Copyright 2005 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MIaV is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+#include "mutex.h"
+
+Mutex::Mutex()
+{
+ pthread_mutex_init (&mutex, NULL);
+}
+
+Mutex::~Mutex()
+{
+ pthread_mutex_destroy(&mutex);
+}
+
+void Mutex::lock()
+{
+ pthread_mutex_lock( &mutex );
+}
+
+void Mutex::unlock()
+{
+ pthread_mutex_unlock( &mutex );
+}
diff --git a/src/mutex.h b/src/mutex.h
new file mode 100644
index 0000000..0b1f4e7
--- /dev/null
+++ b/src/mutex.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * mutex.h
+ *
+ * Sat Oct 8 17:44:09 CEST 2005
+ * Copyright 2005 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MIaV is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+#ifndef __MIAV_MUTEX_H__
+#define __MIAV_MUTEX_H__
+
+#include <pthread.h>
+
+class Mutex {
+public:
+ Mutex();
+ ~Mutex();
+
+ void lock();
+ void unlock();
+
+private:
+ pthread_mutex_t mutex;
+};
+
+#endif/*__MIAV_MUTEX_H__*/
diff --git a/src/semaphore.cc b/src/semaphore.cc
new file mode 100644
index 0000000..147bd24
--- /dev/null
+++ b/src/semaphore.cc
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * semaphore.cc
+ *
+ * Sat Oct 8 17:44:13 CEST 2005
+ * Copyright 2005 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MIaV is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+#include "semaphore.h"
+
+Semaphore::Semaphore()
+{
+ sem_init(&semaphore, 0, 0);
+}
+
+Semaphore::~Semaphore()
+{
+ sem_destroy(&semaphore);
+}
+
+void Semaphore::post()
+{
+ sem_post(&semaphore);
+}
+
+void Semaphore::wait()
+{
+ sem_wait(&semaphore);
+}
diff --git a/src/semaphore.h b/src/semaphore.h
index adf9bc7..85f4c09 100644
--- a/src/semaphore.h
+++ b/src/semaphore.h
@@ -28,7 +28,7 @@
#ifndef __MIAV_SEMAPHORE_H__
#define __MIAV_SEMAPHORE_H__
-#include <semaphore.h>
+#include </usr/include/semaphore.h>
class Semaphore {
public:
diff --git a/src/threadsafe_queue.h b/src/threadsafe_queue.h
index 616e81e..b6d5725 100644
--- a/src/threadsafe_queue.h
+++ b/src/threadsafe_queue.h
@@ -28,29 +28,31 @@
#ifndef __MIAV_THREADSAFE_QUEUE_H__
#define __MIAV_THREADSAFE_QUEUE_H__
-#include <pthread.h>
-#include <semaphore.h>
+#include "mutex.h"
+#include "semaphore.h"
template <typename T>
class ThreadSafeQueue {
public:
ThreadSafeQueue() {
- pthread_mutex_init (&mutex, NULL);
- sem_init(&semaphore, 0, 0);
+ // pthread_mutex_init (&mutex, NULL);
+ // sem_init(&semaphore, 0, 0);
}
virtual ~ThreadSafeQueue() {
- pthread_mutex_destroy(&mutex);
- sem_destroy(&semaphore);
+ // pthread_mutex_destroy(&mutex);
+ //sem_destroy(&semaphore);
}
virtual void push(T t) = 0;
virtual T pop() = 0;
virtual int size() = 0;
- //protected:
- pthread_mutex_t mutex;
- sem_t semaphore;
+protected:
+ // pthread_mutex_t mutex;
+ Mutex mutex;
+ //sem_t semaphore;
+ Semaphore semaphore;
};
#endif/*__MIAV_THREADSAFE_QUEUE_H__*/
diff --git a/src/threadsafe_queue_fifo.h b/src/threadsafe_queue_fifo.h
index 30f6645..404e2f9 100644
--- a/src/threadsafe_queue_fifo.h
+++ b/src/threadsafe_queue_fifo.h
@@ -32,30 +32,36 @@
#include <queue>
template <typename T>
-class ThreadSafeQueueFIFO: public ThreadSafeQueue<T> {
+class ThreadSafeQueueFIFO: ThreadSafeQueue<T> {
public:
ThreadSafeQueueFIFO() {}
~ThreadSafeQueueFIFO() {}
void push(T t) {
// Lock mutex
- pthread_mutex_lock( &mutex );
+ // pthread_mutex_lock( &mutex );
+ mutex.lock();
queue.push(t);
- pthread_mutex_unlock( &mutex );
+ // pthread_mutex_unlock( &mutex );
+ mutex.unlock();
// Unlock mutex
- sem_post(&semaphore);
+ semaphore.post();
+ //sem_post(&semaphore);
}
T pop() {
- sem_wait(&semaphore);
+ semaphore.wait();
+ // sem_wait(&semaphore);
T t;
// Lock mutex
- pthread_mutex_lock( &mutex );
+ // pthread_mutex_lock( &mutex );
+ mutex.lock();
t = queue.front();
queue.pop();
- pthread_mutex_unlock( &mutex );
+ // pthread_mutex_unlock( &mutex );
+ mutex.unlock();
// Unlock mutex
return t;
@@ -65,9 +71,11 @@ public:
int sz;
// Lock mutex
- pthread_mutex_lock( &mutex );
+ // pthread_mutex_lock( &mutex );
+ mutex.lock();
sz = queue.size();
- pthread_mutex_unlock( &mutex );
+ // pthread_mutex_unlock( &mutex );
+ mutex.unlock();
// Unlock mutex
return sz;
diff --git a/src/threadsafe_queue_priority.cc b/src/threadsafe_queue_priority.cc
index 130b0f5..df7ae8c 100644
--- a/src/threadsafe_queue_priority.cc
+++ b/src/threadsafe_queue_priority.cc
@@ -43,24 +43,29 @@ ThreadSafeQueuePriority::~ThreadSafeQueuePriority()
void ThreadSafeQueuePriority::push(Frame *frame)
{
// Lock mutex
- pthread_mutex_lock( &mutex );
+ // pthread_mutex_lock( &mutex );
+ mutex.lock();
queue.push(frame);
- pthread_mutex_unlock( &mutex );
+ // pthread_mutex_unlock( &mutex );
+ mutex.unlock();
// Unlock mutex
- sem_post(&semaphore);
+ // sem_post(&semaphore);
+ semaphore.post();
}
Frame *ThreadSafeQueuePriority::pop()
{
- sem_wait(&semaphore);
+ semaphore.wait();
+ // sem_wait(&semaphore);
Frame *tmpframe = NULL;
Frame *frame = NULL;
while( frame == NULL ) {
// Lock mutex
- pthread_mutex_lock( &mutex );
+ // pthread_mutex_lock( &mutex );
+ mutex.lock();
tmpframe = queue.top();
@@ -70,7 +75,8 @@ Frame *ThreadSafeQueuePriority::pop()
framenumber++;
}
- pthread_mutex_unlock( &mutex );
+ // pthread_mutex_unlock( &mutex );
+ mutex.unlock();
// Unlock mutex
if(frame == NULL) sleep_0_2_frame();
@@ -84,9 +90,11 @@ int ThreadSafeQueuePriority::size()
int sz;
// Lock mutex
- pthread_mutex_lock( &mutex );
+ // pthread_mutex_lock( &mutex );
+ mutex.lock();
sz = queue.size();
- pthread_mutex_unlock( &mutex );
+ // pthread_mutex_unlock( &mutex );
+ mutex.unlock();
// Unlock mutex
return sz;