void CThreadSpinRWLock::SpinLockForWrite( const uint32 threadId ) { int i; for ( i = 1000; i != 0; --i ) { if ( TryLockForWrite( threadId ) ) { return; } ThreadPause(); } for ( i = 20000; i != 0; --i ) { if ( TryLockForWrite( threadId ) ) { return; } ThreadPause(); ThreadSleep( 0 ); } for ( ;; ) // coded as for instead of while to make easy to breakpoint success { if ( TryLockForWrite( threadId ) ) { return; } ThreadPause(); ThreadSleep( 1 ); } }
void CThreadSpinRWLock::UnlockRead() { int i; Assert( m_lockInfo.m_nReaders > 0 && m_lockInfo.m_writerId == 0 ); LockInfo_t oldValue; LockInfo_t newValue; oldValue.m_nReaders = m_lockInfo.m_nReaders; oldValue.m_writerId = 0; newValue.m_nReaders = oldValue.m_nReaders - 1; newValue.m_writerId = 0; if( AssignIf( newValue, oldValue ) ) return; ThreadPause(); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders - 1; for ( i = 500; i != 0; --i ) { if( AssignIf( newValue, oldValue ) ) return; ThreadPause(); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders - 1; } for ( i = 20000; i != 0; --i ) { if( AssignIf( newValue, oldValue ) ) return; ThreadPause(); ThreadSleep( 0 ); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders - 1; } for ( ;; ) // coded as for instead of while to make easy to breakpoint success { if( AssignIf( newValue, oldValue ) ) return; ThreadPause(); ThreadSleep( 1 ); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders - 1; } }
void CThreadSpinRWLock::LockForRead() { int i; // In order to grab a read lock, the number of readers must not change and no thread can own the write lock LockInfo_t oldValue; LockInfo_t newValue; oldValue.m_nReaders = m_lockInfo.m_nReaders; oldValue.m_writerId = 0; newValue.m_nReaders = oldValue.m_nReaders + 1; newValue.m_writerId = 0; if( m_nWriters == 0 && AssignIf( newValue, oldValue ) ) return; ThreadPause(); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders + 1; for ( i = 1000; i != 0; --i ) { if( m_nWriters == 0 && AssignIf( newValue, oldValue ) ) return; ThreadPause(); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders + 1; } for ( i = 20000; i != 0; --i ) { if( m_nWriters == 0 && AssignIf( newValue, oldValue ) ) return; ThreadPause(); ThreadSleep( 0 ); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders + 1; } for ( ;; ) // coded as for instead of while to make easy to breakpoint success { if( m_nWriters == 0 && AssignIf( newValue, oldValue ) ) return; ThreadPause(); ThreadSleep( 1 ); oldValue.m_nReaders = m_lockInfo.m_nReaders; newValue.m_nReaders = oldValue.m_nReaders + 1; } }
void TestSessionKeyTableAPI( CuTest* tc ) { dssl_SessionKeyTable* tbl = NULL; DSSL_Session* sess = NULL; DSSL_SessionKeyData* kd = NULL; tbl = dssl_SessionKT_Create( 100, TEST_CACHE_TIMEOUT ); CuAssert( tc, "SessionKeyTable object should be not NULL", tbl != NULL ); sess = (DSSL_Session*) malloc( sizeof( DSSL_Session ) ); CuAssert( tc, "DSSL_Session object should be not NULL", sess != NULL ); memset( sess, 0, sizeof(*sess) ); dssl_SessionKT_Add( tbl, sess ); CuAssertTrue( tc, tbl->count == 1 ); kd = dssl_SessionKT_Find( tbl, sess->session_id ); CuAssertTrue( tc, kd != NULL ); CuAssertTrue( tc, kd->refcount == 1 ); CuAssertTrue( tc, kd->released_time == 0 ); kd = NULL; dssl_SessionKT_Release( tbl, sess->session_id ); ThreadSleep( (TEST_CACHE_TIMEOUT+1)*1000 ); dssl_SessionKT_CleanSessionCache( tbl ); CuAssertTrue( tc, tbl->count == 0 ); free( sess ); dssl_SessionKT_Destroy( tbl ); }
//////////////////////////////////////////////////////////// /// Wait the thread until the user isn't removed //////////////////////////////////////////////////////////// void UserWaitUntilRemoved(struct UserData * User) { while (UserContains(User)) { MutexLock(&User->MutexData); ThreadSleep(&User->ThreadData, 10); MutexUnlock(&User->MutexData); } }
int ConnWriteFromFile(TConn *c,TFile *file,uint64 start,uint64 end, void *buffer,uint32 buffersize,uint32 rate) { uint64 y = 0; uint64 bytesread=0; uint32 waittime = 0; /* sanity */ if (!c || !buffer) { return FALSE; } if( c->out_bufferpos ) ConnWriteFlush( c ); if (rate>0) { if (buffersize>rate) buffersize=rate; waittime=(1000*buffersize)/rate; } else waittime=0; if (!FileSeek(file,start,SEEK_SET)) return FALSE; while (bytesread<=end-start) { y=(end-start+1)-bytesread; if (y>buffersize) y=buffersize; y=FileRead(file,buffer,y); bytesread+=y; if (y>0) ConnWrite(c,buffer,y); else break; if (waittime) ThreadSleep(waittime); }; return (bytesread>end-start); }
void GameBase::InternalRender(SDLGL* sdlgl, boost::posix_time::time_duration render_delta) { normal_delta += render_delta; if (normal_delta < boost::posix_time::milliseconds(10)) // frame limiting { ThreadSleep(5); } else { boost::posix_time::time_duration delta = normal_delta; normal_delta = boost::posix_time::seconds(0); OnRender(sdlgl, delta); } }
bool File::WriteData(const void* d, int size) { if(mode & FILEWRITE) { switch(srctype) { case MODE_MYFILE: case MODE_EXTFILE: return FileWrite(file,d,size); case MODE_MYDATA: //resize if buffer's not big enough if(datapos + size > datasize) { int a=datapos+size,b=datasize*2; ResizeDataBuffer(Max(a,b)); } memcpy(datafile+datapos, d, size); datapos += size; return true; case MODE_EXTDATA: if(datapos + size > datasize) return false; memcpy(datafile+datapos, d, size); datapos += size; return true; case MODE_TCPSOCKET: case MODE_UDPSOCKET: { const char* msg = (const char*)d; int totalsent = 0; while(totalsent < size) { int n = SocketWrite(socket,msg+totalsent,size-totalsent); if(n < 0) { perror("File(socket) SocketWrite"); return false; } if(n == 0) { printf("File(socket): SocketWrite returned %d, what does it mean?\n",n); ThreadSleep(0.001); } totalsent += n; } assert(totalsent == size); return true; } } } return false; }
bool File::ReadData(void* d, int size) { if(size < 0) fprintf(stderr,"File::ReadData: invalid size %d\n",size); if(mode & FILEREAD) { switch(srctype) { case MODE_MYFILE: case MODE_EXTFILE: return FileRead(file,d,size); case MODE_MYDATA: case MODE_EXTDATA: if(datapos + size > datasize) return false; memcpy(d, datafile+datapos, size); datapos += size; return true; case MODE_TCPSOCKET: case MODE_UDPSOCKET: { char* buffer = (char*)d; int totalread = 0; while(totalread < size) { int n=SocketRead(socket,buffer+totalread,size-totalread); if(n == 0) { printf("File(socket): socketRead returned 0, connection shutdown\n"); return false; } if(n < 0) { if(errno==EWOULDBLOCK) { ThreadSleep(0.001); //just spin? continue; } perror("Unhandled error in socket read"); return false; } totalread += n; } assert(totalread == size); return true; } } } return false; }
int XSocketMgr::Query() { int nRetCode = 0; time_t nTimeNow = time(NULL); int nIOCount = 0; XListenNode* pListenNode = m_ListenHeadNode.pNext; while (pListenNode) { if (!pListenNode->bUsrClose) { nRetCode = ProcessNewSocket(pListenNode, nTimeNow); if (nRetCode > 0) nIOCount++; } pListenNode = pListenNode->pNext; } XStreamNode* pStreamNode = m_StreamHeadNode.pNext; while (pStreamNode) { if (pStreamNode->bComplete && !pStreamNode->bUsrClose) { ProcessReceive(pStreamNode, nTimeNow); nIOCount++; } pStreamNode = pStreamNode->pNext; } if (nTimeNow > m_uNextCycleProcess) { ProcessCycle(nTimeNow); m_uNextCycleProcess = nTimeNow; } // Windows由于IOCP机制问题,这里只是近似的模拟epoll,kqueue的阻塞 if (nIOCount == 0) { ThreadSleep(m_nQueryTimeout); } return nIOCount; }
/*virtual*/ void Application::ThreadDynamicSleep() { float elapsedTime = ElapsedTime(); if (boost::algorithm::clamp(elapsedTime - mOldElapsedTime,0.0001f,1.0f) < 1.0f / mDesiredFramerate) { mDynamicSleepSecs += 0.001f; } else { mDynamicSleepSecs = std::max(0.0f,mDynamicSleepSecs - 0.001f); } mOldElapsedTime = elapsedTime; if (mDynamicSleepSecs > 0.0f) { ThreadSleep(mDynamicSleepSecs); } }
void Run(void) override { ThreadSleep(std::chrono::milliseconds(100)); m_ptr.reset(); }
void ThreadWaitUS(int microSec) { // this is not implemented yet ThreadSleep(1); }
DWORD CAtmoLiveView::Execute(void) { #if defined(_ATMO_VLC_PLUGIN_) vlc_object_t *m_pLog = m_pAtmoDynData->getAtmoFilter(); mtime_t ticks; mtime_t t; mtime_t packet_time; #else DWORD ticks; DWORD t; DWORD packet_time; #endif int i_frame_counter = -1; pColorPacket ColorPacket; pColorPacket PreviousPacket = NULL; CAtmoConnection *pAtmoConnection = this->m_pAtmoDynData->getAtmoConnection(); if((pAtmoConnection == NULL) || (pAtmoConnection->isOpen() == ATMO_FALSE)) return 0; CAtmoConfig *pAtmoConfig = this->m_pAtmoDynData->getAtmoConfig(); /* this object does post processing of the pixel data like jump /scenechange detection fading over the colors */ CAtmoOutputFilter *filter = new CAtmoOutputFilter( this->m_pAtmoDynData->getAtmoConfig() ); CAtmoPacketQueue *pPacketQueue = this->m_pAtmoDynData->getLivePacketQueue(); int frameDelay = pAtmoConfig->getLiveView_FrameDelay(); #if defined(_ATMO_VLC_PLUGIN_) /* because time function of vlc are working with us values instead of ms */ frameDelay = frameDelay * 1000; #endif /* wait for the first frame to go in sync with the other thread */ t = get_time1; if( pPacketQueue->WaitForNextPacket(3000) ) { if( frameDelay > 0 ) do_sleep( frameDelay ); #if defined(_ATMO_VLC_PLUGIN_) msg_Dbg( m_pLog, "First Packet got %"PRId64" ms", (get_time1 - t) / 1000 ); #endif } while(this->m_bTerminated == ATMO_FALSE) { i_frame_counter++; if(i_frame_counter == 50) i_frame_counter = 0; /* grab current Packet from InputQueue (working as FIFO)! */ #if defined(_ATMO_VLC_PLUGIN_) ColorPacket = pPacketQueue->GetNextPacket(get_time1 - frameDelay, (i_frame_counter == 0), m_pLog, packet_time); #else ColorPacket = pPacketQueue->GetNextPacket(get_time1 - frameDelay, (i_frame_counter == 0), packet_time); #endif if(ColorPacket) { /* create a packet copy - for later reuse if the input is slower than 25fps */ if(PreviousPacket && (PreviousPacket->numColors == ColorPacket->numColors)) CopyColorPacket(ColorPacket, PreviousPacket) else { delete (char *)PreviousPacket; DupColorPacket(PreviousPacket, ColorPacket ) } } else { /* packet queue was empty for the given point of time */ if(i_frame_counter == 0) { #if defined(_ATMO_VLC_PLUGIN_) msg_Dbg( m_pLog, "wait for delayed packet..." ); #endif t = get_time1; if( pPacketQueue->WaitForNextPacket(200) ) { if( frameDelay > 0 ) do_sleep( frameDelay ); #if defined(_ATMO_VLC_PLUGIN_) msg_Dbg( m_pLog, "got delayed packet %"PRId64" ms", (mdate() - t) / 1000 ); #endif continue; } } /* reuse previous color packet */ DupColorPacket(ColorPacket, PreviousPacket) } ticks = get_time1; if(ColorPacket) { /* pass it through the outputfilters! */ // Info Filtering will possible free the colorpacket and alloc a new one! ColorPacket = filter->Filtering(ColorPacket); // invert colors if(pAtmoConfig->isUseinvert()) ColorPacket = CAtmoTools::Applyinvert(pAtmoConfig, ColorPacket); /* apply gamma correction - only if the hardware isnt capable doing this */ ColorPacket = CAtmoTools::ApplyGamma(pAtmoConfig, ColorPacket); // load color correction from Kodak 3D-Lut file if(pAtmoConfig->isUse3dlut() && pAtmoConfig->m_3dlut) ColorPacket = CAtmoTools::Apply3dlut(pAtmoConfig, ColorPacket); // our own trilinear CMS if(pAtmoConfig->isUseColorKWhiteAdj()) ColorPacket = CAtmoTools::ApplyColorK(pAtmoConfig, ColorPacket); // apply white calibration - only if it is not done by the hardware if((pAtmoConfig->isUseSoftwareWhiteAdj()))//&&(!pAtmoConfig->isUseColorKWhiteAdj())) ColorPacket = CAtmoTools::WhiteCalibration(pAtmoConfig, ColorPacket); //Sensitivity ColorPacket = CAtmoTools::ApplySens(pAtmoConfig, ColorPacket); /* send color data to the the hardware... */ try { pAtmoConnection->SendData(ColorPacket); delete (char *)ColorPacket; } catch(...) { delete (char *)ColorPacket; } } /* calculate RunTime of thread abbove (doesn't work well - so this threads comes out of sync with Image producer and the framerate (25fps) drifts away */ #if defined(_ATMO_VLC_PLUGIN_) ticks = ((mdate() - ticks) + 999)/1000; #else ticks = GetTickCount() - ticks; #endif if(ticks < 40) { if( ThreadSleep( 40 - ticks ) == ATMO_FALSE ) break; } }
void ThreadMinimalSleep() { ThreadSleep(1); }
static int Init(benchresult* p) { node* Player = Context()->Player; node* Platform = Context()->Platform; node* Format; node* Input; node* VOutput; node* AOutput; winunit y; int i; int Frames; int Samples; int Bytes; tick_t Tick; tick_t OrigTick; point SizeSrc; point SizeDst; packetformat Video; packetformat Audio; tchar_t Buffer[256]; fraction f; p->TimeDate = GetTimeDate(); Player->Get(Player,PLAYER_FORMAT,&Format,sizeof(Format)); Player->Get(Player,PLAYER_INPUT,&Input,sizeof(Input)); VOutput = NULL; AOutput = NULL; OrigTick = 0; Frames = 0; Samples = 0; Bytes = 0; memset(&Video,0,sizeof(Video)); memset(&Audio,0,sizeof(Audio)); stprintf_s(p->Log,TSIZEOF(p->Log),LangStrDef(BENCHRESULT_ID,BENCHRESULT_LOG),Context()->ProgramName,Context()->ProgramVersion); tcscat_s(p->Log,TSIZEOF(p->Log),T("\n\n")); if (Format) { int No; pin Pin; packetformat PacketFormat; Format->Get(Format,FORMAT_FILEPOS,&Bytes,sizeof(Bytes)); for (No=0;Format->Get(Format,FORMAT_STREAM+No,&Pin,sizeof(Pin))==ERR_NONE;++No) if (Pin.Node && Format->Get(Format,(FORMAT_STREAM+No)|PIN_FORMAT,&PacketFormat,sizeof(PacketFormat))==ERR_NONE) { if (PacketFormat.Type == PACKET_VIDEO) { Video = PacketFormat; Player->Get(Player,PLAYER_VOUTPUT,&VOutput,sizeof(VOutput)); if (VOutput) VOutput->Get(VOutput,OUT_TOTAL,&Frames,sizeof(Frames)); } if (PacketFormat.Type == PACKET_AUDIO) { Audio = PacketFormat; Player->Get(Player,PLAYER_AOUTPUT,&AOutput,sizeof(AOutput)); if (AOutput) { packetformat Format; AOutput->Get(AOutput,OUT_TOTAL,&Samples,sizeof(Samples)); if (AOutput->Get(AOutput,OUT_INPUT|PIN_FORMAT,&Format,sizeof(Format))==ERR_NONE && Format.Type == PACKET_AUDIO) { if (Format.Format.Audio.Bits>=8) Samples /= Format.Format.Audio.Bits/8; if (!(Format.Format.Audio.Flags & PCM_PLANES) && Format.Format.Audio.Channels) Samples /= Format.Format.Audio.Channels; } } } } } y = 4; Player->Get(Player,PLAYER_BENCHMARK,&Tick,sizeof(Tick)); if (Frames && Video.PacketRate.Num) OrigTick = Scale64(Frames,(int64_t)Video.PacketRate.Den*TICKSPERSEC,Video.PacketRate.Num); else if (Samples && Audio.Format.Audio.SampleRate) OrigTick = Scale(Samples,TICKSPERSEC,Audio.Format.Audio.SampleRate); if (Tick && OrigTick) { f.Num = OrigTick; f.Den = Tick; FractionToString(Buffer,TSIZEOF(Buffer),&f,1,2); AddItem(p,&y,BENCHRESULT_SPEED,Buffer); } if (Frames) { IntToString(Buffer,TSIZEOF(Buffer),Frames,0); AddItem(p,&y,BENCHRESULT_FRAMES,Buffer); } if (Samples) { IntToString(Buffer,TSIZEOF(Buffer),Samples,0); AddItem(p,&y,BENCHRESULT_SAMPLES,Buffer); } if (Bytes) { IntToString(Buffer,TSIZEOF(Buffer),Bytes/1024,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" KB")); AddItem(p,&y,BENCHRESULT_BYTES,Buffer); } y += 6; tcscat_s(p->Log,TSIZEOF(p->Log),T("\n")); TickToString(Buffer,TSIZEOF(Buffer),Tick,0,1,0); AddItem(p,&y,BENCHRESULT_TIME,Buffer); if (Frames && Tick) { f.Num = Frames; f.Den = Tick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,2); AddItem(p,&y,BENCHRESULT_FPS,Buffer); } if (Samples && Tick) { f.Num = Samples; f.Den = Tick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0); AddItem(p,&y,BENCHRESULT_SRATE,Buffer); } if (Bytes && Tick) { f.Num = Scale(Bytes,8,1000); f.Den = Tick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; if (f.Den && (f.Num/f.Den) > 1000) { Simplify(&f,MAX_INT,MAX_INT/1024); f.Den *= 1000; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,1); tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mbit/s")); } else { FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" kbit/s")); } AddItem(p,&y,BENCHRESULT_BANDWIDTH,Buffer); } y += 6; tcscat_s(p->Log,TSIZEOF(p->Log),T("\n")); if (OrigTick) { TickToString(Buffer,TSIZEOF(Buffer),OrigTick,0,1,0); AddItem(p,&y,BENCHRESULT_ORIG_TIME,Buffer); } if (Video.PacketRate.Num) { FractionToString(Buffer,TSIZEOF(Buffer),&Video.PacketRate,0,2); AddItem(p,&y,BENCHRESULT_ORIG_FPS,Buffer); } if (Audio.Format.Audio.SampleRate) { IntToString(Buffer,TSIZEOF(Buffer),Audio.Format.Audio.SampleRate,0); AddItem(p,&y,BENCHRESULT_ORIG_SRATE,Buffer); } if (Bytes && OrigTick) { f.Num = Scale(Bytes,8,1000); f.Den = OrigTick; Simplify(&f,MAX_INT/TICKSPERSEC,MAX_INT); f.Num *= TICKSPERSEC; if (f.Den && (f.Num/f.Den) > 1000) { f.Den *= 1000; FractionToString(Buffer,TSIZEOF(Buffer),&f,0,1); tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mbit/s")); } else { FractionToString(Buffer,TSIZEOF(Buffer),&f,0,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" kbit/s")); } AddItem(p,&y,BENCHRESULT_ORIG_BANDWIDTH,Buffer); } if (Frames && Samples) { y += 9; WinLabel(&p->Win,&y,-1,-1,LangStr(BENCHRESULT_ID,BENCHRESULT_MSG),11,0,NULL); } tcscat_s(p->Log,TSIZEOF(p->Log),T("\n")); if (Input && Input->Get(Input,STREAM_URL,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,BENCHRESULT_ID,BENCHRESULT_URL,Buffer); if (Input && Input->Get(Input,STREAM_LENGTH,&i,sizeof(i))==ERR_NONE) { IntToString(Buffer,TSIZEOF(Buffer),i,0); AddLog(p,BENCHRESULT_ID,BENCHRESULT_FILESIZE,Buffer); } if (Platform) { if (Platform->Get(Platform,PLATFORM_TYPE,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,PLATFORM_ID,PLATFORM_TYPE,Buffer); if (Platform->Get(Platform,PLATFORM_VERSION,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,PLATFORM_ID,PLATFORM_VERSION,Buffer); if (Platform->Get(Platform,PLATFORM_OEMINFO,Buffer,sizeof(Buffer))==ERR_NONE) AddLog(p,PLATFORM_ID,PLATFORM_OEMINFO,Buffer); ThreadSleep(GetTimeFreq()/10); if (Platform->Get(Platform,PLATFORM_CPUMHZ,&i,sizeof(i))==ERR_NONE) { IntToString(Buffer,TSIZEOF(Buffer),i,0); tcscat_s(Buffer,TSIZEOF(Buffer),T(" Mhz")); AddLog(p,PLATFORM_ID,PLATFORM_CPUMHZ,Buffer); } } if (VOutput) { tcscpy_s(Buffer,TSIZEOF(Buffer),LangStrDef(VOutput->Class,NODE_NAME)); if (VOutput->Get(VOutput,OUT_OUTPUT|PIN_FORMAT,&Video,sizeof(Video))==ERR_NONE) { if (Video.Format.Video.Direction & DIR_SWAPXY) SwapInt(&Video.Format.Video.Width,&Video.Format.Video.Height); stcatprintf_s(Buffer,TSIZEOF(Buffer),T(" %dx%d %dbits"),Video.Format.Video.Width,Video.Format.Video.Height,Video.Format.Video.Pixel.BitCount); } if (QueryAdvanced(ADVANCED_SLOW_VIDEO)) tcscat_s(Buffer,TSIZEOF(Buffer),T(" Slow")); if (QueryAdvanced(ADVANCED_COLOR_LOOKUP)) tcscat_s(Buffer,TSIZEOF(Buffer),T(" Lookup")); AddLog(p,PLAYER_ID,PLAYER_VOUTPUT,Buffer); } if (Player->Get(Player,PLAYER_BENCHMARK_SRC,&SizeSrc,sizeof(point))==ERR_NONE && Player->Get(Player,PLAYER_BENCHMARK_DST,&SizeDst,sizeof(point))==ERR_NONE && SizeSrc.x>0 && SizeSrc.y>0) { stprintf_s(Buffer,TSIZEOF(Buffer),T("%dx%d -> %dx%d"),SizeSrc.x,SizeSrc.y,SizeDst.x,SizeDst.y); AddLog(p,BENCHRESULT_ID,BENCHRESULT_ZOOM,Buffer); } if (AOutput) { tcscpy_s(Buffer,TSIZEOF(Buffer),LangStrDef(AOutput->Class,NODE_NAME)); if (AOutput->Get(AOutput,OUT_OUTPUT|PIN_FORMAT,&Audio,sizeof(Audio))==ERR_NONE) stcatprintf_s(Buffer,TSIZEOF(Buffer),T(" %dHz %dBits %dCh."),Audio.Format.Audio.SampleRate,Audio.Format.Audio.Bits,Audio.Format.Audio.Channels); AddLog(p,PLAYER_ID,PLAYER_AOUTPUT,Buffer); } return ERR_NONE; }
void CAtmoBasicEffect::Interpolation(int iSteps, int iPause, pColorPacket fadeTo) { int s_1; // zählvariablen int s_2; pColorPacket ausgabe; pColorPacket output; // Stepsize for each fading step float *interpolation_r = new float[fadeTo->numColors]; // Differenz zw. 2 R/G/B werten zur Interpolation float *interpolation_g = new float[fadeTo->numColors]; float *interpolation_b = new float[fadeTo->numColors]; if(!m_RGB_alt || (m_RGB_alt->numColors != fadeTo->numColors) ) { delete (char *)m_RGB_alt; m_RGB_alt=NULL; for ( s_1 = 0; s_1 < fadeTo->numColors ; s_1++ ) { interpolation_r[s_1] = (float)(fadeTo->zone[s_1].r) / (float)iSteps; interpolation_g[s_1] = (float)(fadeTo->zone[s_1].g) / (float)iSteps; interpolation_b[s_1] = (float)(fadeTo->zone[s_1].b) / (float)iSteps; } } else { for ( s_1 = 0; s_1 < fadeTo->numColors ; s_1++ ) { interpolation_r[s_1] = (float)(fadeTo->zone[s_1].r - m_RGB_alt->zone[s_1].r) / (float)iSteps; interpolation_g[s_1] = (float)(fadeTo->zone[s_1].g - m_RGB_alt->zone[s_1].g) / (float)iSteps; interpolation_b[s_1] = (float)(fadeTo->zone[s_1].b - m_RGB_alt->zone[s_1].b) / (float)iSteps; } } AllocColorPacket(ausgabe, fadeTo->numColors); // fading... color... for ( s_2 = 1; s_2<=iSteps ; s_2++ ) // anfang interpolation und ausgabe { if(m_RGB_alt) { for(int zone = 0; zone<fadeTo->numColors; zone++) { ausgabe->zone[zone].r = m_RGB_alt->zone[zone].r + (int)((float)s_2 * interpolation_r[zone]); ausgabe->zone[zone].g = m_RGB_alt->zone[zone].g + (int)((float)s_2 * interpolation_g[zone]); ausgabe->zone[zone].b = m_RGB_alt->zone[zone].b + (int)((float)s_2 * interpolation_b[zone]); } } else { for(int zone = 0; zone<fadeTo->numColors; zone++) { ausgabe->zone[zone].r = (int)((float)s_2 * interpolation_r[zone]); ausgabe->zone[zone].g = (int)((float)s_2 * interpolation_g[zone]); ausgabe->zone[zone].b = (int)((float)s_2 * interpolation_b[zone]); } } DupColorPacket(output, ausgabe); output = CAtmoTools::ApplyGamma(m_AtmoConfig, output); if(m_AtmoConfig->isUseSoftwareWhiteAdj()) output = CAtmoTools::WhiteCalibration(m_AtmoConfig, output); m_AtmoConnection->SendData(output); delete (char *)output; if(ThreadSleep(iPause) == ATMO_FALSE) break; } // save last color as start color for next run delete (char *)m_RGB_alt; delete []interpolation_r; delete []interpolation_g; delete []interpolation_b; m_RGB_alt = ausgabe; }
void CThreadFastMutex::Lock( const uint32 threadId, unsigned nSpinSleepTime ) volatile { int i; if ( nSpinSleepTime != TT_INFINITE ) { for ( i = 1000; i != 0; --i ) { if ( TryLock( threadId ) ) { return; } ThreadPause(); } #ifdef _WIN32 if ( !nSpinSleepTime && GetThreadPriority( GetCurrentThread() ) > THREAD_PRIORITY_NORMAL ) { nSpinSleepTime = 1; } else #endif if ( nSpinSleepTime ) { for ( i = 4000; i != 0; --i ) { if ( TryLock( threadId ) ) { return; } ThreadPause(); ThreadSleep( 0 ); } } for ( ;; ) // coded as for instead of while to make easy to breakpoint success { if ( TryLock( threadId ) ) { return; } ThreadPause(); ThreadSleep( nSpinSleepTime ); } } else { for ( ;; ) // coded as for instead of while to make easy to breakpoint success { if ( TryLock( threadId ) ) { return; } ThreadPause(); } } }
///===================================================== /// ///===================================================== void Thread::Sleep(unsigned int milliseconds){ ThreadSleep(milliseconds); }