documentation for class WQueue and Notify added.
This commit is contained in:
@@ -4,18 +4,20 @@ AM_CXXFLAGS = -fpic \
|
|||||||
|
|
||||||
noinst_LIBRARIES = libutils.a
|
noinst_LIBRARIES = libutils.a
|
||||||
|
|
||||||
libutils_a_SOURCES = wqueue.h \
|
libutils_a_SOURCES = appl.cpp \
|
||||||
notify.h \
|
|
||||||
appl.cpp \
|
|
||||||
appl.h \
|
appl.h \
|
||||||
daemon.cpp \
|
daemon.cpp \
|
||||||
daemon.h \
|
daemon.h \
|
||||||
logger.cpp \
|
logger.cpp \
|
||||||
logger.h \
|
logger.h \
|
||||||
|
notify.cpp \
|
||||||
|
notify.h \
|
||||||
|
tcpsocket.cpp \
|
||||||
|
tcpsocket.h \
|
||||||
thread.cpp \
|
thread.cpp \
|
||||||
thread.h \
|
thread.h \
|
||||||
tcpsocket.cpp \
|
wqueue.h
|
||||||
tcpsocket.h
|
|
||||||
|
|
||||||
distclean-local:
|
distclean-local:
|
||||||
-rm -f Makefile.in
|
-rm -f Makefile.in
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) Roland Jax 2012-2014 <ebusd@liwest.at>
|
||||||
|
*
|
||||||
|
* This file is part of ebusd.
|
||||||
|
*
|
||||||
|
* ebusd 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* ebusd 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 ebusd. If not, see http://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "notify.h"
|
||||||
|
|
||||||
|
Notify::Notify()
|
||||||
|
{
|
||||||
|
int pipefd[2];
|
||||||
|
int ret = pipe(pipefd);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
m_recvfd = pipefd[0];
|
||||||
|
m_sendfd = pipefd[1];
|
||||||
|
|
||||||
|
fcntl(m_sendfd, F_SETFL, O_NONBLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Notify::~Notify()
|
||||||
|
{
|
||||||
|
close(m_sendfd);
|
||||||
|
close(m_recvfd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+22
-13
@@ -23,30 +23,39 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief class to notify other thread per pipe.
|
||||||
|
*/
|
||||||
class Notify
|
class Notify
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Notify()
|
/**
|
||||||
{
|
* @brief constructs a new instance and do notifying.
|
||||||
int pipefd[2];
|
*/
|
||||||
int ret = pipe(pipefd);
|
Notify();
|
||||||
|
|
||||||
if (ret == 0) {
|
/**
|
||||||
m_recvfd = pipefd[0];
|
* @brief destructor.
|
||||||
m_sendfd = pipefd[1];
|
*/
|
||||||
|
~Notify();
|
||||||
|
|
||||||
fcntl(m_sendfd, F_SETFL, O_NONBLOCK);
|
/**
|
||||||
}
|
* @brief file descriptor to watch for notify event.
|
||||||
|
* @return the notification value
|
||||||
|
*/
|
||||||
|
int notifyFD() { return m_recvfd; }
|
||||||
|
|
||||||
}
|
/**
|
||||||
virtual ~Notify() { close(m_sendfd); close(m_recvfd); }
|
* @brief write notify event to file descriptor.
|
||||||
|
* @return result of writing notification
|
||||||
int notifyFD() const { return m_recvfd; }
|
*/
|
||||||
int notify() const { return write(m_sendfd,"1",1); }
|
int notify() const { return write(m_sendfd,"1",1); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** file descriptor to watch */
|
||||||
int m_recvfd;
|
int m_recvfd;
|
||||||
|
/** file descriptor to notify */
|
||||||
int m_sendfd;
|
int m_sendfd;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+30
-1
@@ -23,22 +23,36 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
template <typename T> class WQueue
|
/**
|
||||||
|
* @brief queue class template for all kinds data types with exclusiv lock.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
class WQueue
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief constructs a new instance.
|
||||||
|
*/
|
||||||
WQueue()
|
WQueue()
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&m_mutex, NULL);
|
pthread_mutex_init(&m_mutex, NULL);
|
||||||
pthread_cond_init(&m_cond, NULL);
|
pthread_cond_init(&m_cond, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief destructor.
|
||||||
|
*/
|
||||||
~WQueue()
|
~WQueue()
|
||||||
{
|
{
|
||||||
pthread_mutex_destroy(&m_mutex);
|
pthread_mutex_destroy(&m_mutex);
|
||||||
pthread_cond_destroy(&m_cond);
|
pthread_cond_destroy(&m_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief add a new item to the end of queue.
|
||||||
|
* @param item
|
||||||
|
*/
|
||||||
void add(T item)
|
void add(T item)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
@@ -49,6 +63,10 @@ public:
|
|||||||
pthread_mutex_unlock(&m_mutex);
|
pthread_mutex_unlock(&m_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief remove the first item from queue.
|
||||||
|
* @return the item
|
||||||
|
*/
|
||||||
T remove()
|
T remove()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
@@ -64,6 +82,10 @@ public:
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief return the first item from queue without remove.
|
||||||
|
* @return the item
|
||||||
|
*/
|
||||||
T next()
|
T next()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
@@ -78,6 +100,10 @@ public:
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief the number of entries inside queue.
|
||||||
|
* @return the size
|
||||||
|
*/
|
||||||
int size()
|
int size()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&m_mutex);
|
pthread_mutex_lock(&m_mutex);
|
||||||
@@ -90,8 +116,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** the queue itself */
|
||||||
std::list<T> m_queue;
|
std::list<T> m_queue;
|
||||||
|
/** mutex variable for exclusive lock */
|
||||||
pthread_mutex_t m_mutex;
|
pthread_mutex_t m_mutex;
|
||||||
|
/** condition variable for exclusive lock */
|
||||||
pthread_cond_t m_cond;
|
pthread_cond_t m_cond;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user