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