diff options
-rw-r--r-- | Jamfile | 2 | ||||
-rw-r--r-- | main.c | 32 | ||||
-rw-r--r-- | threading.c | 27 | ||||
-rw-r--r-- | threading.h | 13 |
4 files changed, 61 insertions, 13 deletions
@@ -11,7 +11,7 @@ HDRS += /usr/include/pango-1.0 ; HDRS += /usr/include/cairo ; Main deadbeef : - cmod.c codec.c cvorbis.c cwav.c playlist.c psdl.c main.c support.c interface.c callbacks.c ; + cmod.c codec.c cvorbis.c cwav.c playlist.c psdl.c main.c support.c interface.c callbacks.c threading.c ; LINKLIBS on deadbeef = -lmikmod -lm -lvorbis -logg -lvorbisfile -lmikmod -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 ; @@ -1,28 +1,37 @@ #include <gtk/gtk.h> +#include <stdio.h> +#include <stdint.h> #include "interface.h" #include "support.h" -#include <stdio.h> #include "playlist.h" #include "psdl.h" #include "unistd.h" - +#include "threading.h" GtkWidget *mainwin; +int psdl_terminate = 0; + +void +psdl_thread (uintptr_t ctx) { + psdl_init (); + while (!psdl_terminate) { + sleep(1); + // handle message pump here + } + psdl_free (); + ps_free (); +} + int main (int argc, char *argv[]) { if (argc <= 1) { printf ("syntax: deadbeef <filename>\n"); return -1; } - psdl_init (); - if (!ps_add_file (argv[1])) { - printf ("playing %s\n", argv[1]); - psdl_play (playlist_head); - } - else { - printf ("failed to play %s\n", argv[1]); - } + + thread_start (psdl_thread, 0); + gtk_set_locale (); gtk_init (&argc, &argv); @@ -34,7 +43,6 @@ main (int argc, char *argv[]) { mainwin = create_mainwin (); gtk_widget_show (mainwin); gtk_main (); - psdl_free (); - ps_free (); + psdl_terminate = 1; return 0; } diff --git a/threading.c b/threading.c new file mode 100644 index 00000000..c5d5a6c8 --- /dev/null +++ b/threading.c @@ -0,0 +1,27 @@ +#include <SDL/SDL.h> +#include <SDL/SDL_thread.h> +#include "threading.h" + +void thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx) { + if (!SDL_CreateThread ((int (*)(void*))fn, (void*)ctx)) { + printf ("SDL_CreateThread failed!\n"); + } +} +uintptr_t mutex_create (void) { + SDL_mutex *mtx = SDL_CreateMutex (); + if (!mtx) { + printf ("SDL_CreateMutex failed!\n"); + } + return (uintptr_t)mtx; +} +void mutex_free (uintptr_t mtx) { + SDL_mutexP ((SDL_mutex*)mtx); // grant that no thread does processing now + SDL_DestroyMutex ((SDL_mutex*)mtx); +} +int mutex_lock (uintptr_t mtx) { + return SDL_mutexP ((SDL_mutex*)mtx); +} +int mutex_unlock (uintptr_t mtx) { + return SDL_mutexV ((SDL_mutex*)mtx); +} + diff --git a/threading.h b/threading.h new file mode 100644 index 00000000..6b2b9237 --- /dev/null +++ b/threading.h @@ -0,0 +1,13 @@ +#ifndef __THREADING_H +#define __THREADING_H + +#include <stdint.h> + +void thread_start (void (*fn)(uintptr_t ctx), uintptr_t ctx); +uintptr_t mutex_create (void); +void mutex_free (uintptr_t mtx); +int mutex_lock (uintptr_t mtx); +int mutex_unlock (uintptr_t mtx); + +#endif + |