summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-30 18:11:19 +0200
committerAndreas Baumann <abaumann@yahoo.com>2009-03-30 18:11:19 +0200
commit181c176bc16d57a3dcb42b3657290ce1dbf7695f (patch)
tree226594c69e8a7d3035f9a2475bb512cb05168b0d /src
parent8c0d332229b887595d01e77a501cb6a986b70be6 (diff)
downloadwolfbones-181c176bc16d57a3dcb42b3657290ce1dbf7695f.tar.gz
wolfbones-181c176bc16d57a3dcb42b3657290ce1dbf7695f.tar.bz2
started to add thread stuff, mutexes first
Diffstat (limited to 'src')
-rw-r--r--src/GNUmakefile6
-rw-r--r--src/mutex.c78
-rw-r--r--src/port/string.c3
3 files changed, 86 insertions, 1 deletions
diff --git a/src/GNUmakefile b/src/GNUmakefile
index ea2e754..8fc202f 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -26,10 +26,14 @@ DAEMON_OBJS = \
SERVICE_OBJS = \
service/service.o
+THREADING_OBJS = \
+ mutex.o
+
OBJS = \
$(PORT_OBJS) \
$(LOG_OBJS) \
- $(DAEMON_OBJS)
+ $(DAEMON_OBJS) \
+ $(THREADING_OBJS)
CATALOG_NAME = libwolf
diff --git a/src/mutex.c b/src/mutex.c
new file mode 100644
index 0000000..2e06318
--- /dev/null
+++ b/src/mutex.c
@@ -0,0 +1,78 @@
+/*
+ Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>
+
+ This program 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.
+
+ This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "errors.h"
+#include "mutex.h"
+
+#if defined HAVE_PTHREADS
+
+#include <errno.h> /* for EXXX values */
+#include <assert.h> /* for assertions */
+
+wolf_error_t wolf_mutex_init( wolf_mutex_t *mutex ) {
+ pthread_mutexattr_t attr;
+ int res;
+
+ /* intialize mutex attribute object */
+ res = pthread_mutexattr_init( &attr );
+ if( res == ENOMEM ) {
+ return WOLF_ERR_OUT_OF_MEMORY;
+ } else if( res == EINVAL ) {
+ return WOLF_ERR_INVALID_VALUE;
+ } else {
+ return WOLF_ERR_INTERNAL;
+ }
+
+ /* set default values */
+ res = pthread_mutexattr_settype( &attr, WOLF_MUTEX_DEFAULT_ATTR );
+ if( res != 0 ) {
+ res = pthread_mutexattr_destroy( &attr );
+ assert( res == 0 );
+ return WOLF_ERR_INTERNAL;
+ }
+
+ /* initialize the mutex */
+ res = pthread_mutex_init( mutex, &attr );
+ if( res == ENOMEM ) {
+ return WOLF_ERR_OUT_OF_MEMORY;
+ } else if( res == EINVAL ) {
+ return WOLF_ERR_INVALID_VALUE;
+ } else {
+ return WOLF_ERR_INTERNAL;
+ }
+
+ /* destroy mutex attributes */
+ res = pthread_mutexattr_destroy( &attr );
+ assert( res == 0 );
+
+ return WOLF_OK;
+}
+
+wolf_error_t wolf_mutex_destroy( wolf_mutex_t *mutex ) {
+ int res;
+
+ res = pthread_mutex_destroy( mutex );
+ if( res == EINVAL ) {
+ return WOLF_ERR_INVALID_VALUE;
+ } else {
+ return WOLF_ERR_INTERNAL;
+ }
+
+ return WOLF_OK;
+}
+
+#endif /* defined HAVE_PTHREADS */
diff --git a/src/port/string.c b/src/port/string.c
index e05dfbd..da0dfce 100644
--- a/src/port/string.c
+++ b/src/port/string.c
@@ -47,6 +47,9 @@ char *wolf_port_strdup( const char *s ) {
#include <sys/types.h> /* for size_t */
#include <errno.h> /* for errno */
+/* FIXME: this version is NOT thread and signal safe! But we have to port
+ * mutexes first
+ */
int wolf_port_strerror_r( int num, char *buf, size_t buflen ) {
int safe_errno = errno;
const char *msg;