used the following commands: find . -type f -name "*.h" | xargs sed -i 's/\s*$//g' find . -type f -name "*.cpp" | xargs sed -i 's/\s*$//g'
Showing the changes to src/core/util_thread.cpp (1 of 90 files). Show all
Unified · Split
| @@ -102,7 +102,7 @@ XThread::~XThread( ) · 101 unmodified lines | ||
| 102 | 102 | bool XThread::start( THREAD_FUNCTION routine, void * ptr ) |
| 103 | 103 | { |
| 104 | 104 | bool result = false; |
| 105 | − | |
| 105 | + | |
| 106 | 106 | #if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) ) |
| 107 | 107 | if( pthread_create( &thread, NULL, *routine, ptr ) == 0 ) |
| 108 | 108 | result = true; |
| @@ -124,7 +124,7 @@ bool XThread::start( THREAD_FUNCTION routine, void * ptr ) · 15 unmodified lines | ||
| 124 | 124 | bool XThread::wait( long milliseconds, bool cancel ) |
| 125 | 125 | { |
| 126 | 126 | bool result = false; |
| 127 | − | |
| 127 | + | |
| 128 | 128 | // TODO: find an alternative for Android? |
| 129 | 129 | #if( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) ) |
| 130 | 130 | // cancel the thread? |
| @@ -174,7 +174,7 @@ XMutex::XMutex( ) · 43 unmodified lines | ||
| 174 | 174 | pthread_mutex_init(&mutex, NULL); |
| 175 | 175 | #elif defined(__PLATFORM_WIN32__) |
| 176 | 176 | InitializeCriticalSection(&mutex); |
| 177 | −#endif | |
| 177 | +#endif | |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
| @@ -190,7 +190,7 @@ XMutex::~XMutex( ) · 9 unmodified lines | ||
| 190 | 190 | pthread_mutex_destroy( &mutex ); |
| 191 | 191 | #elif defined(__PLATFORM_WIN32__) |
| 192 | 192 | DeleteCriticalSection(&mutex); |
| 193 | −#endif | |
| 193 | +#endif | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
| @@ -206,7 +206,7 @@ void XMutex::acquire( ) · 9 unmodified lines | ||
| 206 | 206 | pthread_mutex_lock(&mutex); |
| 207 | 207 | #elif defined(__PLATFORM_WIN32__) |
| 208 | 208 | EnterCriticalSection(&mutex); |
| 209 | −#endif | |
| 209 | +#endif | |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | |
| @@ -222,7 +222,7 @@ void XMutex::release( ) · 9 unmodified lines | ||
| 222 | 222 | pthread_mutex_unlock(&mutex); |
| 223 | 223 | #elif defined(__PLATFORM_WIN32__) |
| 224 | 224 | LeaveCriticalSection(&mutex); |
| 225 | −#endif | |
| 225 | +#endif | |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
| @@ -239,7 +239,7 @@ XWriteThread * XWriteThread::shared() · 10 unmodified lines | ||
| 239 | 239 | // check |
| 240 | 240 | if( o_defaultWriteThread == NULL ) |
| 241 | 241 | o_defaultWriteThread = new XWriteThread(); |
| 242 | − | |
| 242 | + | |
| 243 | 243 | return o_defaultWriteThread; |
| 244 | 244 | } |
| 245 | 245 | |
| @@ -290,7 +290,7 @@ void XWriteThread::shutdown() · 44 unmodified lines | ||
| 290 | 290 | Message msg; |
| 291 | 291 | msg.operation = Message::SHUTDOWN; |
| 292 | 292 | m_msg_buffer->put( msg ); |
| 293 | − | |
| 293 | + | |
| 294 | 294 | // smart log push |
| 295 | 295 | SmartPushLog logPush; |
| 296 | 296 | |
| @@ -313,19 +313,19 @@ size_t XWriteThread::fwrite(const void * ptr, size_t size, size_t nitems, FILE * · 16 unmodified lines | ||
| 313 | 313 | { |
| 314 | 314 | if(stream != m_stream) |
| 315 | 315 | flush_data_buffer(); |
| 316 | − | |
| 316 | + | |
| 317 | 317 | // TODO: overflow detection |
| 318 | 318 | if(m_data_buffer->put((char*)ptr, size*nitems) == 0) |
| 319 | 319 | { |
| 320 | 320 | EM_log(CK_LOG_SEVERE, "XWriteThread::fwrite: data buffer overflow"); |
| 321 | 321 | } |
| 322 | − | |
| 322 | + | |
| 323 | 323 | m_bytes_in_buffer += size*nitems; |
| 324 | 324 | m_stream = stream; |
| 325 | − | |
| 325 | + | |
| 326 | 326 | if(m_bytes_in_buffer >= PRODUCER_BUFFER_SIZE) |
| 327 | 327 | flush_data_buffer(); |
| 328 | − | |
| 328 | + | |
| 329 | 329 | return nitems; |
| 330 | 330 | } |
| 331 | 331 | |
| @@ -339,14 +339,14 @@ size_t XWriteThread::fwrite(const void * ptr, size_t size, size_t nitems, FILE * · 7 unmodified lines | ||
| 339 | 339 | int XWriteThread::fseek(FILE *stream, long offset, int whence) |
| 340 | 340 | { |
| 341 | 341 | flush_data_buffer(); |
| 342 | − | |
| 342 | + | |
| 343 | 343 | Message msg; |
| 344 | 344 | msg.file = stream; |
| 345 | 345 | msg.operation = Message::SEEK; |
| 346 | 346 | msg.seek.offset = offset; |
| 347 | 347 | msg.seek.whence = whence; |
| 348 | 348 | m_msg_buffer->put(msg); |
| 349 | − | |
| 349 | + | |
| 350 | 350 | return 0; |
| 351 | 351 | } |
| 352 | 352 | |
| @@ -360,12 +360,12 @@ int XWriteThread::fseek(FILE *stream, long offset, int whence) · 7 unmodified lines | ||
| 360 | 360 | int XWriteThread::fflush(FILE *stream) |
| 361 | 361 | { |
| 362 | 362 | flush_data_buffer(); |
| 363 | − | |
| 363 | + | |
| 364 | 364 | Message msg; |
| 365 | 365 | msg.file = stream; |
| 366 | 366 | msg.operation = Message::FLUSH; |
| 367 | 367 | m_msg_buffer->put(msg); |
| 368 | − | |
| 368 | + | |
| 369 | 369 | return 0; |
| 370 | 370 | } |
| 371 | 371 | |
| @@ -379,12 +379,12 @@ int XWriteThread::fflush(FILE *stream) · 7 unmodified lines | ||
| 379 | 379 | int XWriteThread::fclose(FILE *stream) |
| 380 | 380 | { |
| 381 | 381 | flush_data_buffer(); |
| 382 | − | |
| 382 | + | |
| 383 | 383 | Message msg; |
| 384 | 384 | msg.file = stream; |
| 385 | 385 | msg.operation = Message::CLOSE; |
| 386 | 386 | m_msg_buffer->put(msg); |
| 387 | − | |
| 387 | + | |
| 388 | 388 | return 0; |
| 389 | 389 | } |
| 390 | 390 | |
| @@ -404,7 +404,7 @@ void XWriteThread::flush_data_buffer() · 13 unmodified lines | ||
| 404 | 404 | msg.operation = Message::WRITE; |
| 405 | 405 | msg.write.data_size = m_bytes_in_buffer; |
| 406 | 406 | m_msg_buffer->put(msg); |
| 407 | − | |
| 407 | + | |
| 408 | 408 | m_bytes_in_buffer = 0; |
| 409 | 409 | } |
| 410 | 410 | } |
| @@ -424,7 +424,7 @@ unsigned XWriteThread::write_cb(void * _thiss) · 13 unmodified lines | ||
| 424 | 424 | { |
| 425 | 425 | XWriteThread * _this = (XWriteThread *) _thiss; |
| 426 | 426 | Message msg; |
| 427 | − | |
| 427 | + | |
| 428 | 428 | while(!_this->m_thread_exit) |
| 429 | 429 | { |
| 430 | 430 | while(_this->m_msg_buffer->get(msg)) |
| @@ -438,7 +438,7 @@ unsigned XWriteThread::write_cb(void * _thiss) · 7 unmodified lines | ||
| 438 | 438 | EM_log(CK_LOG_SEVERE, "XWriteThread: buffered data size mismatch (%li : %li)", |
| 439 | 439 | msg.write.data_size, actual_size); |
| 440 | 440 | } |
| 441 | − | |
| 441 | + | |
| 442 | 442 | ::fwrite(_this->m_thread_buffer, 1, actual_size, msg.file); |
| 443 | 443 | } |
| 444 | 444 | else if(msg.operation == Message::SEEK) |
| @@ -459,13 +459,13 @@ unsigned XWriteThread::write_cb(void * _thiss) · 14 unmodified lines | ||
| 459 | 459 | break; |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | − | |
| 462 | + | |
| 463 | 463 | usleep(1000); |
| 464 | 464 | } |
| 465 | − | |
| 465 | + | |
| 466 | 466 | delete _this; |
| 467 | 467 | _thiss = _this = NULL; |
| 468 | − | |
| 468 | + | |
| 469 | 469 | return 0; |
| 470 | 470 | } |
| 471 | 471 | |
| @@ -490,14 +490,14 @@ t_CKBOOL XThreadUtil::set_priority( CHUCK_THREAD tid, t_CKINT priority ) · 18 unmodified lines | ||
| 490 | 490 | { |
| 491 | 491 | struct sched_param param; |
| 492 | 492 | int policy; |
| 493 | − | |
| 493 | + | |
| 494 | 494 | // log |
| 495 | 495 | EM_log( CK_LOG_INFO, "setting thread priority to: %ld...", priority ); |
| 496 | − | |
| 496 | + | |
| 497 | 497 | // get for thread |
| 498 | 498 | if( pthread_getschedparam( tid, &policy, ¶m) ) |
| 499 | 499 | return FALSE; |
| 500 | − | |
| 500 | + | |
| 501 | 501 | // pthread_attr_t attr; |
| 502 | 502 | // pthread_attr_init( &attr ); |
| 503 | 503 | // pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED ); |
| @@ -550,14 +550,14 @@ t_CKBOOL XThreadUtil::set_priority( CHUCK_THREAD tid, t_CKINT priority ) · 46 unmodified lines | ||
| 550 | 550 | { |
| 551 | 551 | // if priority is 0 then done |
| 552 | 552 | if( !priority ) return TRUE; |
| 553 | − | |
| 553 | + | |
| 554 | 554 | // log |
| 555 | 555 | EM_log( CK_LOG_FINE, "setting thread priority to: %ld...", priority ); |
| 556 | − | |
| 556 | + | |
| 557 | 557 | // set the priority the thread, windows style |
| 558 | 558 | if( !SetThreadPriority( tid, priority ) ) |
| 559 | 559 | return FALSE; |
| 560 | − | |
| 560 | + | |
| 561 | 561 | return TRUE; |
| 562 | 562 | } |
| 563 | 563 | //----------------------------------------------------------------------------- |