diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2009-07-28 09:59:01 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2009-07-28 09:59:01 +0200 |
commit | 721d733e935a930fc8dde75f5705db701169b46c (patch) | |
tree | 1975af730dbe4a9b85584e0b2c7dafec2ea75bbf | |
parent | b2feb59cdfd2cb612ac8b1bfd16d454c17598707 (diff) |
initial pthread support (buggy!)
-rw-r--r-- | Jamfile | 2 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | threading_pthread.c | 61 |
3 files changed, 63 insertions, 1 deletions
@@ -20,7 +20,7 @@ HDRS += $(ROOT)/sidplay-libs-2.1.0/libsidplay/include ; HDRS += $(ROOT)/sidplay-libs-2.1.0/builders/resid-builder/include ; Main deadbeef : - codec.c cvorbis.c cmp3.c cgme.c cdumb.c cwav.c cflac.c csid.cpp playlist.c psdl.c streamer.c md5.c main.c support.c interface.c callbacks.c threading.c messagepump.c gtkplaylist.c ; + codec.c cvorbis.c cmp3.c cgme.c cdumb.c cwav.c cflac.c csid.cpp playlist.c psdl.c streamer.c md5.c main.c support.c interface.c callbacks.c threading_pthread.c messagepump.c gtkplaylist.c ; LINKLIBS on deadbeef = -lm -lvorbis -logg -lvorbisfile -lmad -lFLAC -lSDL -lsamplerate -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lgthread-2.0 -lstdc++ ; @@ -19,6 +19,7 @@ int psdl_terminate = 0; void psdl_thread (uintptr_t ctx) { + printf ("psdl_thread started!\n"); psdl_play (); while (!psdl_terminate) { uint32_t msg; diff --git a/threading_pthread.c b/threading_pthread.c new file mode 100644 index 00000000..76dd65a5 --- /dev/null +++ b/threading_pthread.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <pthread.h> +#include <stdlib.h> +#include "threading.h" + +void thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx) { + printf ("thread_start called!\n"); + pthread_t tid; + pthread_attr_t attr; + printf ("pthread_attr_init!\n"); + int s = pthread_attr_init (&attr); + if (s) { + printf ("pthread_attr_init failed\n"); + return; + } + + printf ("pthread_create!\n"); + if (pthread_create (&tid, &attr, (void *(*)(void *))fn, (void*)ctx)) { + printf ("pthread_create failed\n"); + return; + } + printf ("pthread_attr_destroy!\n"); + s = pthread_attr_destroy (&attr); + if (s) { + printf ("pthread_attr_destroy failed\n"); + return; + } +#if 0 + void *res; + printf ("pthread_join!\n"); + s = pthread_join (tid, &res); + if (s) { + printf ("pthread_join failed\n"); + return; + } + free (res); +#endif +} +uintptr_t mutex_create (void) { + pthread_mutex_t *mtx = malloc (sizeof (pthread_mutex_t)); + if (pthread_mutex_init (mtx, NULL)) { + printf ("pthread_mutex_init failed!\n"); + } + return (uintptr_t)mtx; +} +void mutex_free (uintptr_t _mtx) { + pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx; + mutex_lock (_mtx); + mutex_unlock (_mtx); + pthread_mutex_destroy (mtx); + free (mtx); +} +int mutex_lock (uintptr_t _mtx) { + pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx; + pthread_mutex_lock (mtx); +} +int mutex_unlock (uintptr_t _mtx) { + pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx; + pthread_mutex_unlock (mtx); +} + |