From 1f52c9ed8ba7885c51f20404f726c5ac6b4f9d15 Mon Sep 17 00:00:00 2001 From: reimar Date: Fri, 14 Nov 2008 19:29:04 +0000 Subject: Include cache2.h in cache2.c, fixes an implicit declaration warning for cache_do_control git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27910 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 1 + 1 file changed, 1 insertion(+) (limited to 'stream/cache2.c') diff --git a/stream/cache2.c b/stream/cache2.c index aa06bc1b51..f81cc1cce9 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -33,6 +33,7 @@ static void ThreadProc( void *s ); #include "help_mp.h" #include "stream.h" +#include "cache2.h" extern int use_gui; int stream_fill_buffer(stream_t *s); -- cgit v1.2.3 From ca77ee41f0d91974a4dff93de611dced9cffb11f Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 15 Nov 2008 19:08:50 +0000 Subject: 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. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27928 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'stream/cache2.c') diff --git a/stream/cache2.c b/stream/cache2.c index f81cc1cce9..30766ffc6d 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -16,15 +16,22 @@ #include #include +#ifdef __CYGWIN__ +#define PTHREAD_CACHE 1 +#endif + #include "osdep/shmem.h" #include "osdep/timer.h" -#if defined(__MINGW32__) || defined(__CYGWIN__) +#if defined(__MINGW32__) #include static void ThreadProc( void *s ); #elif defined(__OS2__) #define INCL_DOS #include static void ThreadProc( void *s ); +#elif defined(PTHREAD_CACHE) +#include +static void *ThreadProc(void *s); #else #include #endif @@ -245,7 +252,7 @@ static int cache_execute_control(cache_vars_t *s) { 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 sector){ }//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 sector){ 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,int size,int min,int seek_limit){ 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,int size,int min,int seek_limit){ 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){ -- cgit v1.2.3 From 7ecf9a6d0489a6bd5b9e6df2048cdb54bb70d861 Mon Sep 17 00:00:00 2001 From: reimar Date: Sat, 15 Nov 2008 19:43:39 +0000 Subject: 100l, stream->cache_pid can not be used directly in pthread_create, it has the wrong type. Luckily we currently do not need the value anyway. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27930 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/cache2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'stream/cache2.c') diff --git a/stream/cache2.c b/stream/cache2.c index 30766ffc6d..f84d221e13 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -349,7 +349,11 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ #elif defined(__OS2__) stream->cache_pid = _beginthread( ThreadProc, NULL, 256 * 1024, s ); #else - pthread_create(&stream->cache_pid, NULL, ThreadProc, s); + { + pthread_t tid; + pthread_create(&tid, NULL, ThreadProc, s); + stream->cache_pid = 1; + } #endif #endif // wait until cache is filled at least prefill_init % -- cgit v1.2.3