summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2009-07-04 03:56:35 +0200
committerGravatar waker <wakeroid@gmail.com>2009-07-04 03:56:35 +0200
commit516186b494d00c5dcb27f3f83cd8b9b7abbd6f46 (patch)
tree29fec73b5cc66e4bbd22bc55fc91a2e2af352dc1
parent6f16e4e363936722d7f3c3b819f787e947260310 (diff)
added separate thread for sdl stuff, to be able to pass messages
-rw-r--r--Jamfile2
-rw-r--r--main.c32
-rw-r--r--threading.c27
-rw-r--r--threading.h13
4 files changed, 61 insertions, 13 deletions
diff --git a/Jamfile b/Jamfile
index 0c195a72..58c83f0e 100644
--- a/Jamfile
+++ b/Jamfile
@@ -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 ;
diff --git a/main.c b/main.c
index dfd72ff6..d80fc50e 100644
--- a/main.c
+++ b/main.c
@@ -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
+