[MPlayer-cvslog] r27928 - trunk/stream/cache2.c
reimar
subversion at mplayerhq.hu
Sat Nov 15 20:08:50 CET 2008
Author: reimar
Date: Sat Nov 15 20:08:50 2008
New Revision: 27928
Log:
Use pthreads for the cache on Cygwin, since _beginthread is not available
and the previous CreateThread method would probably leak memory here, too.
Also pthreads seems to be the official Cygwin threading API.
Modified:
trunk/stream/cache2.c
Modified: trunk/stream/cache2.c
==============================================================================
--- trunk/stream/cache2.c (original)
+++ trunk/stream/cache2.c Sat Nov 15 20:08:50 2008
@@ -16,15 +16,22 @@
#include <sys/types.h>
#include <unistd.h>
+#ifdef __CYGWIN__
+#define PTHREAD_CACHE 1
+#endif
+
#include "osdep/shmem.h"
#include "osdep/timer.h"
-#if defined(__MINGW32__) || defined(__CYGWIN__)
+#if defined(__MINGW32__)
#include <windows.h>
static void ThreadProc( void *s );
#elif defined(__OS2__)
#define INCL_DOS
#include <os2.h>
static void ThreadProc( void *s );
+#elif defined(PTHREAD_CACHE)
+#include <pthread.h>
+static void *ThreadProc(void *s);
#else
#include <sys/wait.h>
#endif
@@ -245,7 +252,7 @@ static int cache_execute_control(cache_v
cache_vars_t* cache_init(int size,int sector){
int num;
-#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__)
+#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
cache_vars_t* s=shmem_alloc(sizeof(cache_vars_t));
#else
cache_vars_t* s=malloc(sizeof(cache_vars_t));
@@ -259,14 +266,14 @@ cache_vars_t* cache_init(int size,int se
}//32kb min_size
s->buffer_size=num*sector;
s->sector_size=sector;
-#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__)
+#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
s->buffer=shmem_alloc(s->buffer_size);
#else
s->buffer=malloc(s->buffer_size);
#endif
if(s->buffer == NULL){
-#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__)
+#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
shmem_free(s,sizeof(cache_vars_t));
#else
free(s);
@@ -282,14 +289,14 @@ cache_vars_t* cache_init(int size,int se
void cache_uninit(stream_t *s) {
cache_vars_t* c = s->cache_data;
if(!s->cache_pid) return;
-#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
+#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
cache_do_control(s, -2, NULL);
#else
kill(s->cache_pid,SIGKILL);
waitpid(s->cache_pid,NULL,0);
#endif
if(!c) return;
-#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
+#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
free(c->stream);
free(c->buffer);
free(s->cache_data);
@@ -330,17 +337,19 @@ int stream_enable_cache(stream_t *stream
min = s->buffer_size - s->fill_limit;
}
-#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__)
+#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
if((stream->cache_pid=fork())){
#else
{
stream_t* stream2=malloc(sizeof(stream_t));
memcpy(stream2,s->stream,sizeof(stream_t));
s->stream=stream2;
-#if defined(__MINGW32__) || defined(__CYGWIN__)
+#if defined(__MINGW32__)
stream->cache_pid = _beginthread( ThreadProc, 0, s );
-#else
+#elif defined(__OS2__)
stream->cache_pid = _beginthread( ThreadProc, NULL, 256 * 1024, s );
+#else
+ pthread_create(&stream->cache_pid, NULL, ThreadProc, s);
#endif
#endif
// wait until cache is filled at least prefill_init %
@@ -359,10 +368,14 @@ int stream_enable_cache(stream_t *stream
return 1; // parent exits
}
-#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
+#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
}
+#ifdef PTHREAD_CACHE
+static void *ThreadProc( void *s ){
+#else
static void ThreadProc( void *s ){
#endif
+#endif
#ifdef CONFIG_GUI
use_gui = 0; // mp_msg may not use gui stuff in forked code
@@ -375,9 +388,12 @@ static void ThreadProc( void *s ){
}
// cache_stats(s->cache_data);
} while (cache_execute_control(s));
-#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__)
+#if defined(__MINGW32__) || defined(__OS2__)
_endthread();
#endif
+#ifdef PTHREAD_CACHE
+ return NULL;
+#endif
}
int cache_stream_fill_buffer(stream_t *s){
More information about the MPlayer-cvslog
mailing list