summaryrefslogtreecommitdiff
path: root/src/threads
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2009-03-31 18:46:23 +0200
committerAndreas Baumann <abaumann@yahoo.com>2009-03-31 18:46:23 +0200
commit80fabedc72b56664a4f6d77c253f9b3fe3939707 (patch)
tree35edd37dfb4bf34507826c78cf354bdc314d7fe2 /src/threads
parentd2b0696d8fa0ce47e0bc525581b6b9254637984b (diff)
downloadwolfbones-80fabedc72b56664a4f6d77c253f9b3fe3939707.tar.gz
wolfbones-80fabedc72b56664a4f6d77c253f9b3fe3939707.tar.bz2
started to add thread support (POSIX)
Diffstat (limited to 'src/threads')
-rw-r--r--src/threads/mutex.c1
-rw-r--r--src/threads/threads.c69
2 files changed, 69 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>.
*/
-#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 <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 "threads/threads.h"
+
+#if defined HAVE_PTHREADS
+
+#include <errno.h> /* for EXXX values */
+#include <assert.h> /* 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 */