[Mplayerxp-cvslog] SF.net SVN: mplayerxp:[444] mplayerxp
Brought to you by:
olov
From: <nic...@us...> - 2012-11-23 17:08:26
|
Revision: 444 http://mplayerxp.svn.sourceforge.net/mplayerxp/?rev=444&view=rev Author: nickols_k Date: 2012-11-23 17:08:19 +0000 (Fri, 23 Nov 2012) Log Message: ----------- use more clear name for thread sleeping Modified Paths: -------------- mplayerxp/libao2/ao_nas.cpp mplayerxp/libmpcodecs/dec_video.cpp mplayerxp/libmpstream/cache2.cpp mplayerxp/libmpstream/s_dvdnav.cpp mplayerxp/libvo/vosub_vidix.cpp mplayerxp/mplayerxp.cpp mplayerxp/mplayerxp.h mplayerxp/xmpcore/xmp_adecoder.cpp mplayerxp/xmpcore/xmp_aplayer.cpp mplayerxp/xmpcore/xmp_core.cpp mplayerxp/xmpcore/xmp_vdecoder.cpp mplayerxp/xmpcore/xmp_vplayer.cpp Modified: mplayerxp/libao2/ao_nas.cpp =================================================================== --- mplayerxp/libao2/ao_nas.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/libao2/ao_nas.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -246,7 +246,7 @@ "ao_nas: event thread heartbeat (state=%s)\n", nas_state(priv->state)); nas_empty_event_queue(priv); - usleep(1000); + yield_timeslice(); } while (!priv->stop_thread); return NULL; @@ -523,7 +523,7 @@ MSG_DBG3("ao_nas: uninit()\n"); priv->expect_underrun = 1; - while (priv->state != AuStateStop) usleep(1000); + while (priv->state != AuStateStop) yield_timeslice(); priv->stop_thread = 1; pthread_join(priv->event_thread, NULL); AuCloseServer(priv->aud); @@ -547,7 +547,7 @@ AuStopFlow(priv->aud, priv->flow, &as); if (as != AuSuccess) nas_print_error(priv->aud, "reset(): AuStopFlow", as); - usleep(1000); + yield_timeslice(); } } Modified: mplayerxp/libmpcodecs/dec_video.cpp =================================================================== --- mplayerxp/libmpcodecs/dec_video.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/libmpcodecs/dec_video.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -296,7 +296,7 @@ sh_video->active_slices=0; mpi=priv->mpvdec->decode(sh_video, frame); MSG_DBG2("decvideo: decoding video %u bytes\n",frame->len); - while(sh_video->active_slices!=0) usleep(0); + while(sh_video->active_slices!=0) yield_timeslice(); /* ------------------------ frame decoded. -------------------- */ if(!mpi) return 0; // error / skipped frame Modified: mplayerxp/libmpstream/cache2.cpp =================================================================== --- mplayerxp/libmpstream/cache2.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/libmpstream/cache2.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -360,7 +360,7 @@ MSG_DBG2("CACHE2_SEEK: %lli,%lli,%lli <> %lli\n",START_FILEPOS(c),c->read_filepos,END_FILEPOS(c),pos); if(pos<0/* || pos>END_FILEPOS(c)*/) { c->eof=1; return 0; } - while(c->in_fill) usleep(0); + while(c->in_fill) yield_timeslice(); CACHE2_LOCK(c); if(c->eof) c2_stream_reset(c); C2_ASSERT(pos < c->stream->start_pos); Modified: mplayerxp/libmpstream/s_dvdnav.cpp =================================================================== --- mplayerxp/libmpstream/s_dvdnav.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/libmpstream/s_dvdnav.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -275,13 +275,13 @@ if(event == DVDNAV_STILL_FRAME) { dvdnav_still_skip(dvdnav_priv->dvdnav); /* don't let dvdnav stall on this image */ - while (dvdnav_stream_sleeping(stream)) usleep(1000); /* 1ms */ + while (dvdnav_stream_sleeping(stream)) yield_timeslice(); /* 10ms */ } #ifdef DVDNAV_WAIT else if(event == DVDNAV_WAIT) { - usleep(1000); + yield_timeslice(); dvdnav_wait_skip(dvdnav_priv->dvdnav); /* don't let dvdnav stall on this image */ } #endif @@ -382,15 +382,14 @@ uint32_t length=1; uint32_t sector; - if (pos==0) - { + if (pos==0) { dvdnav_priv->started=0; dvdnav_priv->cpos=0; return 0; } sector=pos/DVD_BLOCK_SIZE; dvdnav_sector_search(dvdnav_priv->dvdnav,sector,SEEK_SET); - usleep(0); /* wait for HOP_CHANNEL event */ + yield_timeslice(); /* wait for HOP_CHANNEL event */ dvdnav_get_position(dvdnav_priv->dvdnav, &newpos, &length); if(newpos > sector) newpos=sector; dvdnav_priv->cpos = (newpos)*2048; @@ -486,7 +485,7 @@ const dvdnav_still_event_t *still_event = (const dvdnav_still_event_t*)(sp->buf); MSG_DBG2( "######## DVDNAV Event: Still Frame: %d sec(s)\n", still_event->length ); while (dvdnav_stream_sleeping(s)) { - usleep(1000); /* 1ms */ + yield_timeslice(); } dvdnav_stream_sleep(s,still_event->length); break; Modified: mplayerxp/libvo/vosub_vidix.cpp =================================================================== --- mplayerxp/libvo/vosub_vidix.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/libvo/vosub_vidix.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -156,7 +156,7 @@ i=5; if(!sync_mode) while(dma_busy && i) { - usleep(0); + yield_timeslice(); dma_busy = priv.vidix.dma_status(); i--; } Modified: mplayerxp/mplayerxp.cpp =================================================================== --- mplayerxp/mplayerxp.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/mplayerxp.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -1379,14 +1379,14 @@ if (MPXPSys->ao_inited==MPXP_Ok && sh_audio) { if(xmp_test_model(XMP_Run_AudioPlayer)) { xp_core->in_pause=1; - while( !dec_ahead_can_aseek ) usleep(0); + while( !dec_ahead_can_aseek ) yield_timeslice(); } ao_pause(ao_data); // pause audio, keep data if possible } while( (cmd = mp_input_get_cmd(MPXPSys->libinput(),20,1,1)) == NULL) { if(sh_video && MPXPSys->vo_inited) vo_check_events(vo_data); - usleep(20000); + yield_timeslice(); } if (cmd && cmd->id == MP_CMD_PAUSE) { Modified: mplayerxp/mplayerxp.h =================================================================== --- mplayerxp/mplayerxp.h 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/mplayerxp.h 2012-11-23 17:08:19 UTC (rev 444) @@ -4,6 +4,7 @@ #include <pthread.h> #include <stdint.h> #include <string.h> +#include <unistd.h> #include "mp_config.h" #include "osdep/mplib.h" #include "xmpcore/xmp_enums.h" @@ -146,13 +147,15 @@ void exit_player(const char* why); + /* 10 ms or 10'000 microsecs is optimal time for thread sleeping */ + inline int yield_timeslice() { return usleep(10000); } - static inline void escape_player(const char* why,unsigned num_calls) { + inline void escape_player(const char* why,unsigned num_calls) { show_backtrace(why,num_calls); exit_player(why); } - static inline MPXP_Rc check_pin(const char* module,unsigned pin1,unsigned pin2) { + inline MPXP_Rc check_pin(const char* module,unsigned pin1,unsigned pin2) { if(pin1!=pin2) { char msg[4096]; strcpy(msg,"Found incorrect PIN in module: "); Modified: mplayerxp/xmpcore/xmp_adecoder.cpp =================================================================== --- mplayerxp/xmpcore/xmp_adecoder.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/xmpcore/xmp_adecoder.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -5,7 +5,6 @@ #include <errno.h> #include <stdio.h> -#include <unistd.h> // for usleep() #include <math.h> #include <sys/time.h> @@ -101,7 +100,7 @@ int loops = 10; pthread_cond_broadcast( &audio_buffer.wait_buffer_cond ); while( audio_buffer.blocked_readers > 0 && loops > 0 ) { - usleep(1); + yield_timeslice(); loops--; } if( audio_buffer.blocked_readers > 0 ) @@ -446,7 +445,7 @@ while(priv->state!=Pth_Canceling) { if(priv->state==Pth_Sleep) { priv->state=Pth_ASleep; - while(priv->state==Pth_ASleep) usleep(0); + while(priv->state==Pth_ASleep) yield_timeslice(); continue; } __MP_UNIT(priv->p_idx,"decode audio"); @@ -486,7 +485,7 @@ } pthread_cond_timedwait( &audio_decode_cond, &audio_decode_mutex, &timeout ); } else - usleep(1); + yield_timeslice(); } UNLOCK_AUDIO_DECODE(); Modified: mplayerxp/xmpcore/xmp_aplayer.cpp =================================================================== --- mplayerxp/xmpcore/xmp_aplayer.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/xmpcore/xmp_aplayer.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -4,7 +4,6 @@ #include <algorithm> #include <stdio.h> -#include <unistd.h> // for usleep() #include <pthread.h> #include <math.h> #include <sys/time.h> @@ -171,7 +170,7 @@ while(priv->state!=Pth_Canceling) { if(priv->state==Pth_Sleep) { priv->state=Pth_ASleep; - while(priv->state==Pth_ASleep) usleep(0); + while(priv->state==Pth_ASleep) yield_timeslice(); continue; } __MP_UNIT(priv->p_idx,"audio decore_audio"); Modified: mplayerxp/xmpcore/xmp_core.cpp =================================================================== --- mplayerxp/xmpcore/xmp_core.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/xmpcore/xmp_core.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -167,7 +167,7 @@ void dae_wait_decoder_outrun(const dec_ahead_engine_t* it) { if(it) { do { - usleep(0); + yield_timeslice(); }while(dae_get_decoder_outrun(it) < xp_core->num_v_buffs/2); } } @@ -321,11 +321,11 @@ unsigned rc; if(xp_core->audio && xmp_test_model(XMP_Run_AudioDecoder)) { if((rc=xmp_register_thread(xp_core->audio,sig_audio_decode,a_dec_ahead_routine,"audio decoder"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); + while(xp_core->mpxp_threads[rc]->state!=Pth_Run) yield_timeslice(); } if(xp_core->video && xmp_test_model(XMP_Run_VideoDecoder|XMP_Run_VA_Decoder)) { if((rc=xmp_register_thread(xp_core->video,sig_video_decode,xmp_video_decoder,"video+audio decoders"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); + while(xp_core->mpxp_threads[rc]->state!=Pth_Run) yield_timeslice(); } return 0; } @@ -335,11 +335,11 @@ unsigned rc; if(xp_core->audio && xmp_test_model(XMP_Run_AudioPlayer|XMP_Run_AudioPlayback)) { if((rc=xmp_register_thread(xp_core->audio,sig_audio_play,audio_play_routine,"audio player"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); + while(xp_core->mpxp_threads[rc]->state!=Pth_Run) yield_timeslice(); } if(xp_core->video && xmp_test_model(XMP_Run_VideoPlayer)) { if((rc=xmp_register_thread(xp_core->video,sig_video_play,xmp_video_player,"video player"))==UINT_MAX) return rc; - while(xp_core->mpxp_threads[rc]->state!=Pth_Run) usleep(0); + while(xp_core->mpxp_threads[rc]->state!=Pth_Run) yield_timeslice(); } return 0; } @@ -352,7 +352,7 @@ if(force) pthread_kill(xp_core->mpxp_threads[i]->pth_id,SIGKILL); else { xp_core->mpxp_threads[i]->state=Pth_Canceling; - while(xp_core->mpxp_threads[i]->state==Pth_Canceling) usleep(0); + while(xp_core->mpxp_threads[i]->state==Pth_Canceling) yield_timeslice(); } print_stopped_thread(i); delete xp_core->mpxp_threads[i]; @@ -366,7 +366,7 @@ unsigned i; for(i=1;i<xp_core->num_threads;i++) { xp_core->mpxp_threads[i]->state=Pth_Sleep; - while(xp_core->mpxp_threads[i]->state==Pth_Sleep) usleep(0); + while(xp_core->mpxp_threads[i]->state==Pth_Sleep) yield_timeslice(); } } @@ -384,7 +384,7 @@ unsigned i; for(i=1;i<xp_core->num_threads;i++) { xp_core->mpxp_threads[i]->state=Pth_Run; - while(xp_core->mpxp_threads[i]->state==Pth_ASleep) usleep(0); + while(xp_core->mpxp_threads[i]->state==Pth_ASleep) yield_timeslice(); } } Modified: mplayerxp/xmpcore/xmp_vdecoder.cpp =================================================================== --- mplayerxp/xmpcore/xmp_vdecoder.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/xmpcore/xmp_vdecoder.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -2,7 +2,6 @@ #include "osdep/mplib.h" using namespace mpxp; #include <stdio.h> -#include <unistd.h> // for usleep() #include <math.h> #include "libmpcodecs/dec_video.h" @@ -152,7 +151,7 @@ if(priv->state==Pth_Sleep) { pt_sleep: priv->state=Pth_ASleep; - while(priv->state==Pth_ASleep) usleep(0); + while(priv->state==Pth_ASleep) yield_timeslice(); if(xp_core->bad_pts) mpeg_timer=HUGE; continue; } @@ -204,7 +203,7 @@ { int i,delay; /* sleeping 200 ms is far enough for 25 fps */ delay=xp_n_frame_to_drop?0:20; - for(i=0;i<delay;i++) usleep(0); + for(i=0;i<delay;i++) yield_timeslice(); } #endif if(xp_n_frame_to_drop) drop_param=mp_conf.frame_dropping; @@ -254,7 +253,7 @@ xp_thread_decode_audio(d_audio); __MP_UNIT(priv->p_idx,"dec_ahead 5"); } - usleep(1); + yield_timeslice(); } free_enc_frame(frame); /*------------------------ frame decoded. --------------------*/ @@ -263,7 +262,7 @@ if(xp_core->audio && xmp_test_model(XMP_Run_VA_Decoder)) { while(!xp_core->audio->eof && priv->state!=Pth_Canceling && priv->state!=Pth_Sleep) { __MP_UNIT(priv->p_idx,"decode audio"); - if(!xp_thread_decode_audio(d_audio)) usleep(1); + if(!xp_thread_decode_audio(d_audio)) yield_timeslice(); __MP_UNIT(priv->p_idx,NULL); } } Modified: mplayerxp/xmpcore/xmp_vplayer.cpp =================================================================== --- mplayerxp/xmpcore/xmp_vplayer.cpp 2012-11-23 16:09:06 UTC (rev 443) +++ mplayerxp/xmpcore/xmp_vplayer.cpp 2012-11-23 17:08:19 UTC (rev 444) @@ -2,7 +2,6 @@ #include "osdep/mplib.h" using namespace mpxp; #include <stdio.h> -#include <unistd.h> // for usleep() #include <math.h> #include "help_mp.h" @@ -72,7 +71,7 @@ if(MPXPCtx->use_pts_fix2 && sh_audio) { if(sh_video->chapter_change == -1) { /* First frame after seek */ while(v_pts < 1.0 && sh_audio->timer==0.0 && ao_get_delay(ao_data)==0.0) - usleep(0); /* Wait for audio to start play */ + yield_timeslice(); /* Wait for audio to start play */ if(sh_audio->timer > 2.0 && v_pts < 1.0) { MSG_V("Video chapter change detected\n"); sh_video->chapter_change=1; @@ -138,8 +137,7 @@ } while(sleep_time>XP_MIN_TIMESLICE) { - /* mp_free cpu for threads */ - usleep(1); + yield_timeslice(); sleep_time-=GetRelativeTime(); } MP_UNIT("sleep_usleep"); @@ -201,7 +199,7 @@ /* Don't burn CPU here! With using of v_pts for A-V sync we will enter xp_decore_video without any delay (like while(1);) Sleeping for 10 ms doesn't matter with frame dropping */ - usleep(0); + yield_timeslice(); } else { unsigned int t2=GetTimer(); double tt; @@ -291,7 +289,7 @@ if(priv->state==Pth_Canceling) break; if(priv->state==Pth_Sleep) { priv->state=Pth_ASleep; - while(priv->state==Pth_ASleep) usleep(0); + while(priv->state==Pth_ASleep) yield_timeslice(); continue; } __MP_UNIT(priv->p_idx,"play video"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |