[x264-devel] commit: Fix static pthreads + dynamically linked x264 on win32 ( Anton Mitrofanov )
git version control
git at videolan.org
Thu Jan 14 05:51:07 CET 2010
x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Wed Jan 13 15:44:00 2010 -0500| [d26e79d982ec6d0aea40e6d0b21ee799994007ca] | committer: Jason Garrett-Glaser
Fix static pthreads + dynamically linked x264 on win32
Add the necessary static pthread initialization code to a new DLLmain function.
> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=d26e79d982ec6d0aea40e6d0b21ee799994007ca
---
Makefile | 17 +++++++++++++----
x264dll.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index fdb42ac..f643228 100644
--- a/Makefile
+++ b/Makefile
@@ -16,6 +16,8 @@ SRCCLI = x264.c input/yuv.c input/y4m.c output/raw.c \
output/matroska.c output/matroska_ebml.c \
output/flv.c output/flv_bytestream.c
+SRCSO =
+
MUXERS := $(shell grep -E "(IN|OUT)PUT" config.h)
# Optional muxer module sources
@@ -99,8 +101,15 @@ ifneq ($(HAVE_GETOPT_LONG),1)
SRCS += extras/getopt.c
endif
+ifneq ($(SONAME),)
+ifeq ($(SYS),MINGW)
+SRCSO += x264dll.c
+endif
+endif
+
OBJS = $(SRCS:%.c=%.o)
OBJCLI = $(SRCCLI:%.c=%.o)
+OBJSO = $(SRCSO:%.c=%.o)
DEP = depend
.PHONY: all default fprofiled clean distclean install uninstall dox test testclean
@@ -111,8 +120,8 @@ libx264.a: .depend $(OBJS) $(OBJASM)
$(AR) rc libx264.a $(OBJS) $(OBJASM)
$(RANLIB) libx264.a
-$(SONAME): .depend $(OBJS) $(OBJASM)
- $(CC) -shared -o $@ $(OBJS) $(OBJASM) $(SOFLAGS) $(LDFLAGS)
+$(SONAME): .depend $(OBJS) $(OBJASM) $(OBJSO)
+ $(CC) -shared -o $@ $(OBJS) $(OBJASM) $(OBJSO) $(SOFLAGS) $(LDFLAGS)
x264$(EXE): $(OBJCLI) libx264.a
$(CC) -o $@ $+ $(LDFLAGS) $(LDFLAGSCLI)
@@ -130,7 +139,7 @@ checkasm: tools/checkasm.o libx264.a
.depend: config.mak
rm -f .depend
- $(foreach SRC, $(SRCS) $(SRCCLI), $(CC) $(CFLAGS) $(ALTIVECFLAGS) $(SRC) -MT $(SRC:%.c=%.o) -MM -g0 1>> .depend;)
+ $(foreach SRC, $(SRCS) $(SRCCLI) $(SRCSO), $(CC) $(CFLAGS) $(ALTIVECFLAGS) $(SRC) -MT $(SRC:%.c=%.o) -MM -g0 1>> .depend;)
config.mak:
./configure
@@ -171,7 +180,7 @@ fprofiled:
endif
clean:
- rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(SONAME) *.a x264 x264.exe .depend TAGS
+ rm -f $(OBJS) $(OBJASM) $(OBJCLI) $(OBJSO) $(SONAME) *.a x264 x264.exe .depend TAGS
rm -f checkasm checkasm.exe tools/checkasm.o tools/checkasm-a.o
rm -f $(SRC2:%.c=%.gcda) $(SRC2:%.c=%.gcno)
- sed -e 's/ *-fprofile-\(generate\|use\)//g' config.mak > config.mak2 && mv config.mak2 config.mak
diff --git a/x264dll.c b/x264dll.c
new file mode 100644
index 0000000..2b6524d
--- /dev/null
+++ b/x264dll.c
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * x264dll: x264 DLLMain for win32
+ *****************************************************************************
+ * Copyright (C) 2009 x264 project
+ *
+ * Authors: Anton Mitrofanov <BugMaster at narod.ru>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+#include "common/common.h"
+#include <windows.h>
+
+/* Callback for our DLL so we can initialize pthread */
+BOOL WINAPI DllMain( HANDLE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
+{
+#ifdef PTW32_STATIC_LIB
+ switch( fdwReason )
+ {
+ case DLL_PROCESS_ATTACH:
+ pthread_win32_process_attach_np();
+
+ case DLL_THREAD_ATTACH:
+ pthread_win32_thread_attach_np();
+ break;
+
+ case DLL_THREAD_DETACH:
+ pthread_win32_thread_detach_np();
+ break;
+
+ case DLL_PROCESS_DETACH:
+ pthread_win32_thread_detach_np();
+ pthread_win32_process_detach_np();
+ break;
+ }
+#endif
+
+ return TRUE;
+}
More information about the x264-devel
mailing list