From 80fabedc72b56664a4f6d77c253f9b3fe3939707 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Tue, 31 Mar 2009 18:46:23 +0200 Subject: started to add thread support (POSIX) --- src/GNUmakefile | 11 ++++---- src/Makefile.W32 | 11 ++++---- src/threads/mutex.c | 1 - src/threads/threads.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 src/threads/threads.c (limited to 'src') diff --git a/src/GNUmakefile b/src/GNUmakefile index 64e2394..f8a4707 100644 --- a/src/GNUmakefile +++ b/src/GNUmakefile @@ -6,6 +6,10 @@ INCLUDE_DIRS = -I$(TOPDIR)/include/wolf -I. BINS = +THREADING_OBJS = \ + threads/mutex.o \ + threads/threads.o + PORT_OBJS = \ port/string.o \ port/unistd.o \ @@ -26,14 +30,11 @@ DAEMON_OBJS = \ SERVICE_OBJS = \ service/service.o -THREADING_OBJS = \ - threads/mutex.o - OBJS = \ + $(THREADING_OBJS) \ $(PORT_OBJS) \ $(LOG_OBJS) \ - $(DAEMON_OBJS) \ - $(THREADING_OBJS) + $(DAEMON_OBJS) CATALOG_NAME = libwolf diff --git a/src/Makefile.W32 b/src/Makefile.W32 index 10d9295..b321eeb 100644 --- a/src/Makefile.W32 +++ b/src/Makefile.W32 @@ -12,6 +12,10 @@ LIBRARIES = \ wolf.lib \ log\wolfmsg.dll +THREADING_OBJS = \ + threads\mutex.obj \ + threads\threads.obj + PORT_OBJS = \ port\string.obj \ port\stdio.obj \ @@ -24,14 +28,11 @@ LOG_OBJS = \ SERVICE_OBJS = \ service\service.obj -THREADING_OBJS = \ - threads\mutex.obj - OBJS = \ + $(THREADING_OBJS) \ $(PORT_OBJS) \ $(LOG_OBJS) \ - $(SERVICE_OBJS) \ - $(THREADING_OBJS) + $(SERVICE_OBJS) local_all: $(LIBRARIES) diff --git a/src/threads/mutex.c b/src/threads/mutex.c index 509eb51..e710981 100644 --- a/src/threads/mutex.c +++ b/src/threads/mutex.c @@ -15,7 +15,6 @@ along with this program. If not, see . */ -#include "errors.h" #include "threads/mutex.h" #if defined HAVE_PTHREADS diff --git a/src/threads/threads.c b/src/threads/threads.c new file mode 100644 index 0000000..79cf4ba --- /dev/null +++ b/src/threads/threads.c @@ -0,0 +1,69 @@ +/* + Copyright (C) 2008 Andreas Baumann + + 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 . +*/ + +#include "threads/threads.h" + +#if defined HAVE_PTHREADS + +#include /* for EXXX values */ +#include /* for assertions */ +#include "port/unused.h" + +wolf_error_t wolf_thread_create( wolf_thread_t *thread, wolf_thread_func_t func ) { + pthread_attr_t attr; + int res; + + /* intialize thread attributes with defaults */ + res = pthread_attr_init( &attr ); + if( res == ENOMEM ) { + return WOLF_ERR_OUT_OF_MEMORY; + } else if( res != 0 ) { + return WOLF_ERR_INTERNAL; + } + + /* create the thread */ + res = pthread_create( thread, &attr, func, NULL ); + if( res == EINVAL ) { + return WOLF_ERR_INVALID_VALUE; + } else if( res != 0 ) { + return WOLF_ERR_INTERNAL; + } + + /* destroy the thread attributes */ + res = pthread_attr_destroy( &attr ); + assert( res == 0 ); + + return WOLF_OK; +} + +wolf_error_t wolf_thread_join( wolf_thread_t *thread ) { + int res; + void *result; + + res = pthread_join( *thread, &result ); + if( res != 0 ) { + return WOLF_ERR_INTERNAL; + } + + return WOLF_OK; +} + +#endif /* defined HAVE_PTHREADS */ + +#if defined _WIN32 + +#endif /* defined _WIN32 */ -- cgit v1.2.3-54-g00ecf