Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switch to using condition variables.

Recursive mutexes are not supported on Mac/FreeBSD.
libuv doesn't have platform independent wrappers for condition variables.
  • Loading branch information...
commit 2b7a80381063e5c26d025f344cbae575af99639f 1 parent 16547a2
Nikhil Marathe authored
Showing with 27 additions and 3 deletions.
  1. +22 −3 src/taglib.cc
  2. +5 −0 src/taglib.h
25 src/taglib.cc
View
@@ -312,7 +312,11 @@ void CallbackResolver::invokeResolverCb(uv_async_t *handle, int status)
{
AsyncResolverBaton *baton = (AsyncResolverBaton *) handle->data;
invokeResolver(baton);
- uv_mutex_unlock(&baton->mutex);
+#ifdef _WIN32
+ WakeAllConditionVariable(&baton->cv);
+#else
+ pthread_cond_broadcast(&baton->cv);
+#endif
uv_close((uv_handle_t*)&baton->request, 0);
}
@@ -343,10 +347,21 @@ TagLib::File *CallbackResolver::createFile(TagLib::FileName fileName, bool readA
#endif
uv_async_init(uv_default_loop(), &baton.request, invokeResolverCb);
uv_mutex_init(&baton.mutex);
-
uv_mutex_lock(&baton.mutex);
+
+#ifdef _WIN32
+ InitializeConditionVariable(&baton.cv);
+#else
+ if (pthread_cond_init(&baton.cv, NULL))
+ abort();
+#endif
+
uv_async_send(&baton.request);
- uv_mutex_lock(&baton.mutex);
+#ifdef _WIN32
+ SleepConditionVariableCS(&baton.cv, &baton.mutex, INFINITE);
+#else
+ pthread_cond_wait(&baton.cv, &baton.mutex);
+#endif
}
else {
invokeResolver(&baton);
@@ -361,6 +376,10 @@ TagLib::File *CallbackResolver::createFile(TagLib::FileName fileName, bool readA
#endif
uv_mutex_unlock(&baton.mutex);
uv_mutex_destroy(&baton.mutex);
+#ifdef _WIN32
+#else
+ pthread_cond_destroy(&baton.cv);
+#endif
}
return node_taglib::createFile(stream, baton.type);
5 src/taglib.h
View
@@ -55,6 +55,11 @@ class CallbackResolver;
struct AsyncResolverBaton {
uv_async_t request;
uv_mutex_t mutex;
+#ifdef _WIN32
+ CONDITION_VARIABLE cv;
+#else
+ pthread_cond_t cv;
+#endif
const CallbackResolver *resolver;
TagLib::FileName fileName;
TagLib::String type;
Please sign in to comment.
Something went wrong with that request. Please try again.