[pulseaudio-commits] r1395 - in /trunk/src: Makefile.am pulsecore/once-win32.c pulsecore/thread-win32.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Mon Sep 11 00:56:05 PDT 2006
Author: ossman
Date: Mon Sep 11 09:56:03 2006
New Revision: 1395
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1395&root=pulseaudio&view=rev
Log:
Fix up build structure for platform dependent modules. Also add implementation
on Win32 for pa_once().
Added:
trunk/src/pulsecore/once-win32.c (with props)
Modified:
trunk/src/Makefile.am
trunk/src/pulsecore/thread-win32.c
Modified: trunk/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/Makefile.am?rev=1395&root=pulseaudio&r1=1394&r2=1395&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Mon Sep 11 09:56:03 2006
@@ -68,6 +68,18 @@
if OS_IS_WIN32
AM_LDFLAGS+=-Wl,--export-all-symbols
WINSOCK_LIBS=-lwsock32 -lws2_32 -lwininet
+endif
+
+if OS_IS_WIN32
+PA_THREAD_OBJS = \
+ pulsecore/once-win32.c pulsecore/once.h \
+ pulsecore/mutex-win32.c pulsecore/mutex.h \
+ pulsecore/thread-win32.c pulsecore/thread.h
+else
+PA_THREAD_OBJS = \
+ pulsecore/once-posix.c pulsecore/once.h \
+ pulsecore/mutex-posix.c pulsecore/mutex.h \
+ pulsecore/thread-posix.c pulsecore/thread.h
endif
###################################
@@ -251,14 +263,15 @@
memblock_test_LDADD = $(AM_LDADD) libpulsecore.la
memblock_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
-thread_test_SOURCES = tests/thread-test.c pulse/xmalloc.c pulsecore/flist.c pulsecore/thread-posix.c pulsecore/mutex-posix.c pulsecore/log.c pulsecore/core-util.c pulse/util.c pulse/utf8.c pulsecore/core-error.c pulsecore/once-posix.c
+thread_test_SOURCES = tests/thread-test.c
thread_test_CFLAGS = $(AM_CFLAGS)
-thread_test_LDADD = $(AM_LDADD)
+thread_test_LDADD = $(AM_LDADD) libpulsecore.la
thread_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
-flist_test_SOURCES = tests/flist-test.c pulse/xmalloc.c pulsecore/flist.c pulsecore/thread-posix.c pulsecore/mutex-posix.c pulsecore/log.c pulsecore/core-util.c pulse/util.c pulse/utf8.c pulsecore/core-error.c pulsecore/once-posix.c
+flist_test_SOURCES = tests/flist-test.c \
+ pulsecore/flist.c pulsecore/flist.h
flist_test_CFLAGS = $(AM_CFLAGS)
-flist_test_LDADD = $(AM_LDADD)
+flist_test_LDADD = $(AM_LDADD) libpulsecore.la
flist_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
mcalign_test_SOURCES = tests/mcalign-test.c
@@ -434,7 +447,8 @@
pulsecore/tagstruct.c pulsecore/tagstruct.h \
pulsecore/core-error.c pulsecore/core-error.h \
pulsecore/winsock.h pulsecore/creds.h \
- pulsecore/shm.c pulsecore/shm.h
+ pulsecore/shm.c pulsecore/shm.h \
+ $(PA_THREAD_OBJS)
if OS_IS_WIN32
libpulse_la_SOURCES += \
@@ -544,7 +558,8 @@
pulsecore/llist.h \
pulsecore/refcnt.h \
pulsecore/mutex.h \
- pulsecore/thread.h
+ pulsecore/thread.h \
+ pulsecore/once.h
lib_LTLIBRARIES += libpulsecore.la
@@ -586,7 +601,6 @@
pulsecore/modargs.c pulsecore/modargs.h \
pulsecore/modinfo.c pulsecore/modinfo.h \
pulsecore/module.c pulsecore/module.h \
- pulsecore/mutex.h \
pulsecore/namereg.c pulsecore/namereg.h \
pulsecore/pid.c pulsecore/pid.h \
pulsecore/pipe.c pulsecore/pipe.h \
@@ -609,34 +623,16 @@
pulsecore/source.c pulsecore/source.h \
pulsecore/source-output.c pulsecore/source-output.h \
pulsecore/strbuf.c pulsecore/strbuf.h \
- pulsecore/thread.h \
pulsecore/tokenizer.c pulsecore/tokenizer.h \
pulsecore/winsock.h \
pulsecore/core-error.c pulsecore/core-error.h \
pulsecore/hook-list.c pulsecore/hook-list.h \
- pulsecore/shm.c pulsecore/shm.h
+ pulsecore/shm.c pulsecore/shm.h \
+ $(PA_THREAD_OBJS)
if OS_IS_WIN32
libpulsecore_la_SOURCES += \
pulsecore/dllmain.c
-endif
-
-if OS_IS_WIN32
-libpulsecore_la_SOURCES += \
- pulsecore/mutex-win32.c \
- pulsecore/thread-win32.c
-libpulse_la_SOURCES += \
- pulsecore/mutex-win32.c \
- pulsecore/thread-win32.c
-else
-libpulsecore_la_SOURCES += \
- pulsecore/mutex-posix.c \
- pulsecore/thread-posix.c \
- pulsecore/once-posix.c
-libpulse_la_SOURCES += \
- pulsecore/mutex-posix.c \
- pulsecore/thread-posix.c \
- pulsecore/once-posix.c
endif
libpulsecore_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBOIL_CFLAGS)
Added: trunk/src/pulsecore/once-win32.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/once-win32.c?rev=1395&root=pulseaudio&view=auto
==============================================================================
--- trunk/src/pulsecore/once-win32.c (added)
+++ trunk/src/pulsecore/once-win32.c Mon Sep 11 09:56:03 2006
@@ -1,0 +1,67 @@
+/* $Id$ */
+
+/***
+ This file is part of PulseAudio.
+
+ PulseAudio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ PulseAudio is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <windows.h>
+
+#include <pulsecore/mutex.h>
+
+#include "once.h"
+
+void pa_once(pa_once_t *control, pa_once_func_t func) {
+ HANDLE mutex;
+ char name[64];
+
+ assert(control);
+ assert(func);
+
+ /* Create the global mutex */
+ sprintf(name, "pulse%d", (int)GetCurrentProcessId());
+
+ mutex = CreateMutex(NULL, FALSE, name);
+ assert(mutex);
+
+ /* Create the local mutex */
+ WaitForSingleObject(mutex, INFINITE);
+ if (!control->mutex)
+ control->mutex = pa_mutex_new(1);
+ ReleaseMutex(mutex);
+
+ CloseHandle(mutex);
+
+ /* Execute function */
+ pa_mutex_lock(control->mutex);
+ if (!control->once_value) {
+ control->once_value = 1;
+ func();
+ }
+ pa_mutex_unlock(control->mutex);
+
+ /* Caveat: We have to make sure that the once func has completed
+ * before returning, even if the once func is not actually
+ * executed by us. Hence the awkward locking. */
+}
Propchange: trunk/src/pulsecore/once-win32.c
------------------------------------------------------------------------------
svn:keywords = Id
Modified: trunk/src/pulsecore/thread-win32.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/thread-win32.c?rev=1395&root=pulseaudio&r1=1394&r2=1395&view=diff
==============================================================================
--- trunk/src/pulsecore/thread-win32.c (original)
+++ trunk/src/pulsecore/thread-win32.c Mon Sep 11 09:56:03 2006
@@ -29,6 +29,7 @@
#include <pulse/xmalloc.h>
#include <pulsecore/log.h>
+#include <pulsecore/once.h>
#include "thread.h"
@@ -50,9 +51,9 @@
};
static pa_tls *thread_tls;
-static pa_thread_once_t thread_tls_once = PA_THREAD_ONCE_INIT;
+static pa_once_t thread_tls_once = PA_ONCE_INIT;
static pa_tls *monitor_tls;
-static pa_thread_once_t monitor_tls_once = PA_THREAD_ONCE_INIT;
+static pa_once_t monitor_tls_once = PA_ONCE_INIT;
static void thread_tls_once_func(void) {
thread_tls = pa_tls_new(NULL);
@@ -63,7 +64,7 @@
pa_thread *t = param;
assert(t);
- pa_thread_once(&thread_tls_once, thread_tls_once_func);
+ pa_once(&thread_tls_once, thread_tls_once_func);
pa_tls_set(thread_tls, t);
t->thread_func(t->userdata);
@@ -119,36 +120,12 @@
}
pa_thread* pa_thread_self(void) {
- pa_thread_once(&thread_tls_once, thread_tls_once_func);
+ pa_once(&thread_tls_once, thread_tls_once_func);
return pa_tls_get(thread_tls);
}
void pa_thread_yield(void) {
Sleep(0);
-}
-
-void pa_thread_once(pa_thread_once_t *control, pa_thread_once_func_t once_func) {
- HANDLE mutex;
- char name[64];
-
- assert(control);
- assert(once_func);
-
- sprintf(name, "pulse%d", (int)GetCurrentProcessId());
-
- mutex = CreateMutex(NULL, FALSE, name);
- assert(mutex);
-
- WaitForSingleObject(mutex, INFINITE);
-
- if (*control == PA_THREAD_ONCE_INIT) {
- *control = ~PA_THREAD_ONCE_INIT;
- ReleaseMutex(mutex);
- once_func();
- } else
- ReleaseMutex(mutex);
-
- CloseHandle(mutex);
}
static void monitor_tls_once_func(void) {
@@ -212,7 +189,7 @@
if (t->free_func) {
struct pa_tls_monitor *m;
- pa_thread_once(&monitor_tls_once, monitor_tls_once_func);
+ pa_once(&monitor_tls_once, monitor_tls_once_func);
m = pa_tls_get(monitor_tls);
if (!m) {
More information about the pulseaudio-commits
mailing list