summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-03 15:44:37 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-03 15:44:37 +0200
commitac5ec9950ba2ba88f858edb683a534e204637d4c (patch)
treef1e0e8051f2df69fecb4312f769da0abff4f0091
parent35557467f9b71fe4f50ab378101190e3127cff87 (diff)
fixed playlist locking and few redraw issues
-rw-r--r--playlist.c37
-rw-r--r--streamer.c25
-rw-r--r--threading.h3
3 files changed, 47 insertions, 18 deletions
diff --git a/playlist.c b/playlist.c
index a431dccd..f556a3ef 100644
--- a/playlist.c
+++ b/playlist.c
@@ -43,7 +43,8 @@
#include "threading.h"
#include "metacache.h"
-#define DISABLE_LOCKING 1
+#define DISABLE_LOCKING 0
+#define DEBUG_LOCKING 0
// file format revision history
// 1.0->1.1 changelog:
@@ -51,8 +52,8 @@
#define PLAYLIST_MAJOR_VER 1
#define PLAYLIST_MINOR_VER 1
-#define trace(...) { fprintf(stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
+//#define trace(...) { fprintf(stderr, __VA_ARGS__); }
+#define trace(fmt,...)
#define SKIP_BLANK_CUE_TRACKS 1
@@ -84,8 +85,8 @@ static uintptr_t mutex_plt;
int
pl_init (void) {
#if !DISABLE_LOCKING
- mutex = mutex_create_recursive ();
- mutex_plt = mutex_create_recursive ();
+ mutex = mutex_create ();
+ mutex_plt = mutex_create ();
#endif
}
@@ -103,10 +104,17 @@ pl_free (void) {
#endif
}
+#if DEBUG_LOCKING
+int plt_lock_cnt = 0;
+#endif
void
plt_lock (void) {
#if !DISABLE_LOCKING
mutex_lock (mutex_plt);
+#if DEBUG_LOCKING
+ plt_lock_cnt++;
+ printf ("cnt: %d\n", plt_lock_cnt);
+#endif
#endif
}
@@ -114,13 +122,24 @@ void
plt_unlock (void) {
#if !DISABLE_LOCKING
mutex_unlock (mutex_plt);
+#if DEBUG_LOCKING
+ plt_lock_cnt--;
+ printf ("cnt: %d\n", plt_lock_cnt);
+#endif
#endif
}
+#if DEBUG_LOCKING
+int pl_lock_cnt = 0;
+#endif
void
pl_lock (void) {
#if !DISABLE_LOCKING
mutex_lock (mutex);
+#if DEBUG_LOCKING
+ pl_lock_cnt++;
+ printf ("pcnt: %d\n", pl_lock_cnt);
+#endif
#endif
}
@@ -128,6 +147,10 @@ void
pl_unlock (void) {
#if !DISABLE_LOCKING
mutex_unlock (mutex);
+#if DEBUG_LOCKING
+ pl_lock_cnt--;
+ printf ("pcnt: %d\n", pl_lock_cnt);
+#endif
#endif
}
@@ -1226,8 +1249,10 @@ pl_get_for_idx_and_iter (int idx, int iter) {
LOCK;
playItem_t *it = playlist->head[iter];
while (idx--) {
- if (!it)
+ if (!it) {
+ UNLOCK;
return NULL;
+ }
it = it->next[iter];
}
if (it) {
diff --git a/streamer.c b/streamer.c
index 8c7732b3..118d1d1a 100644
--- a/streamer.c
+++ b/streamer.c
@@ -114,7 +114,9 @@ src_unlock (void) {
playItem_t *
streamer_get_streaming_track (void) {
- pl_item_ref (streaming_track);
+ if (streaming_track) {
+ pl_item_ref (streaming_track);
+ }
return streaming_track;
}
@@ -140,6 +142,7 @@ str_get_idx_of (playItem_t *it) {
idx++;
}
if (!c) {
+ plt_unlock ();
return -1;
}
plt_unlock ();
@@ -154,8 +157,10 @@ str_get_for_idx (int idx) {
}
playItem_t *it = streamer_playlist->head[PL_MAIN];
while (idx--) {
- if (!it)
+ if (!it) {
+ plt_unlock ();
return NULL;
+ }
it = it->next[PL_MAIN];
}
if (it) {
@@ -354,6 +359,7 @@ streamer_move_to_prevsong (void) {
}
int r = str_get_idx_of (it);
streamer_set_nextsong (r, 1);
+ plt_unlock ();
return 0;
}
}
@@ -418,20 +424,21 @@ streamer_set_current (playItem_t *it) {
from = playing_track ? str_get_idx_of (playing_track) : -1;
to = it ? str_get_idx_of (it) : -1;
if (!playing_track || p_isstopped ()) {
+ trace ("buffering = on\n");
streamer_buffering = 1;
playlist_track = it;
//trace ("from=%d, to=%d\n", from, to);
//messagepump_push (M_SONGCHANGED, 0, from, to);
+ if (playing_track) {
+ pl_item_unref (playing_track);
+ }
+ playing_track = it;
+ if (playing_track) {
+ pl_item_ref (playing_track);
+ }
}
// code below breaks seekbar drawing during transition between tracks
-// if (playing_track) {
-// pl_item_unref (playing_track);
-// }
-// playing_track = it;
-// if (playing_track) {
-// pl_item_ref (playing_track);
-// }
trace ("streamer_set_current %p, buns=%d\n", it);
mutex_lock (decodemutex);
if (fileinfo) {
diff --git a/threading.h b/threading.h
index d543f14c..dee1cc3c 100644
--- a/threading.h
+++ b/threading.h
@@ -35,9 +35,6 @@ mutex_create (void);
uintptr_t
mutex_create_nonrecursive (void);
-uintptr_t
-mutex_create_recursive (void);
-
void
mutex_free (uintptr_t mtx);