# HG changeset patch # User faust3 # Date 1053974142 0 # Node ID 9e11a478a3bcb9af48c3071c4ab58cc1db915b7d # Parent cd4a6d3040fc2d29439823045cfc61dae4f8c95a use threads on windows diff -r cd4a6d3040fc -r 9e11a478a3bc libmpdemux/cache2.c --- a/libmpdemux/cache2.c Mon May 26 16:53:24 2003 +0000 +++ b/libmpdemux/cache2.c Mon May 26 18:35:42 2003 +0000 @@ -17,7 +17,14 @@ #include #include +#include "../osdep/timer.h" +#ifndef WIN32 #include "../osdep/shmem.h" +#else +#undef DATADIR +#include +static DWORD WINAPI ThreadProc(void* s); +#endif #include "mp_msg.h" @@ -71,7 +78,7 @@ // eof? if(s->eof) break; // waiting for buffer fill... - usleep(READ_USLEEP_TIME); // 10ms + usec_sleep(READ_USLEEP_TIME); // 10ms continue; // try again... } @@ -184,12 +191,20 @@ cache_vars_t* cache_init(int size,int sector){ int num; +#ifndef WIN32 cache_vars_t* s=shmem_alloc(sizeof(cache_vars_t)); +#else + cache_vars_t* s=malloc(sizeof(cache_vars_t)); +#endif memset(s,0,sizeof(cache_vars_t)); num=size/sector; s->buffer_size=num*sector; s->sector_size=sector; +#ifndef WIN32 s->buffer=shmem_alloc(s->buffer_size); +#else + s->buffer=malloc(s->buffer_size); +#endif s->fill_limit=8*sector; s->back_size=size/2; s->prefill=size/20; // default: 5% @@ -199,11 +214,21 @@ void cache_uninit(stream_t *s) { cache_vars_t* c = s->cache_data; if(!s->cache_pid) return; +#ifndef WIN32 kill(s->cache_pid,SIGKILL); waitpid(s->cache_pid,NULL,0); +#else + TerminateThread((HANDLE)s->cache_pid,0); + free(c->stream); +#endif if(!c) return; +#ifndef WIN32 shmem_free(c->buffer,c->buffer_size); shmem_free(s->cache_data,sizeof(cache_vars_t)); +#else + free(c->buffer); + free(s->cache_data); +#endif } static void exit_sighandler(int x){ @@ -227,7 +252,16 @@ s->stream=stream; // callback s->prefill=size*prefill; +#ifndef WIN32 if((stream->cache_pid=fork())){ +#else + { + DWORD threadId; + stream_t* stream2=malloc(sizeof(stream_t)); + memcpy(stream2,s->stream,sizeof(stream_t)); + s->stream=stream2; + stream->cache_pid = CreateThread(NULL,0,ThreadProc,s,0,&threadId); +#endif // wait until cache is filled at least prefill_init % mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %d [%d] %d pre:%d eof:%d \n", s->min_filepos,s->read_filepos,s->max_filepos,min,s->eof); @@ -243,11 +277,16 @@ return 1; // parent exits } +#ifdef WIN32 +} +static DWORD WINAPI ThreadProc(void*s){ +#endif + // cache thread mainloop: signal(SIGTERM,exit_sighandler); // kill while(1){ - if(!cache_fill(s)){ - usleep(FILL_USLEEP_TIME); // idle + if(!cache_fill((cache_vars_t*)s)){ + usec_sleep(FILL_USLEEP_TIME); // idle } // cache_stats(s->cache_data); } diff -r cd4a6d3040fc -r 9e11a478a3bc osdep/shmem.c --- a/osdep/shmem.c Mon May 26 16:53:24 2003 +0000 +++ b/osdep/shmem.c Mon May 26 18:35:42 2003 +0000 @@ -8,7 +8,7 @@ #include "../config.h" -#ifdef USE_STREAM_CACHE +#if defined(USE_STREAM_CACHE) && !defined(WIN32) #include #include