Skip to main content
Fixed formatting on the second code snippet.
Source Link
glampert
  • 17.3k
  • 4
  • 31
  • 89
bool ThreadPool::ThreadTask::finished() {
    if(isFinished->load()){
        if(onFinish && !handled){
            handled = true;
            onFinish();
            if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){
                (*onGroupFinish)();
            }
        }
        return true;
    }
    return false; }
  • This is a minor stylistic thing. I prefer for code to return as soon as possible, so the main body of the program continues the normal execution path, and reducing the indent level. I'd write it this way:

    bool ThreadPool::ThreadTask::finished() { if(!isFinished->load()){ return false; } if(onFinish && !handled){ handled = true; onFinish(); if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){ (*onGroupFinish)(); } } return true; }

      bool ThreadPool::ThreadTask::finished() {
          if(!isFinished->load()){
              return false;
          }
          if(onFinish && !handled){
              handled = true;
              onFinish();
              if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){
                  (*onGroupFinish)();
              }
          }
          return true;
      }
    
  • In ThreadPool::ThreadPool(size_t a_threads) you're using std::cout to log. This violates two paradigms: your code that does the work shouldn't have any user interface stuff in it, and you should use a flexible logging package that can easily be switched on and off. How about Boost::Log?

  • ThreadPool::tasks() and ThreadPool::task() have some common code. How about factoring it out?

  • Emitter::randomMix has repeated randomNumber(0.0, 1.0). Make a helper function.

bool ThreadPool::ThreadTask::finished() {
    if(isFinished->load()){
        if(onFinish && !handled){
            handled = true;
            onFinish();
            if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){
                (*onGroupFinish)();
            }
        }
        return true;
    }
    return false; }
  • This is a minor stylistic thing. I prefer for code to return as soon as possible, so the main body of the program continues the normal execution path, and reducing the indent level. I'd write it this way:

    bool ThreadPool::ThreadTask::finished() { if(!isFinished->load()){ return false; } if(onFinish && !handled){ handled = true; onFinish(); if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){ (*onGroupFinish)(); } } return true; }

  • In ThreadPool::ThreadPool(size_t a_threads) you're using std::cout to log. This violates two paradigms: your code that does the work shouldn't have any user interface stuff in it, and you should use a flexible logging package that can easily be switched on and off. How about Boost::Log?

  • ThreadPool::tasks() and ThreadPool::task() have some common code. How about factoring it out?

  • Emitter::randomMix has repeated randomNumber(0.0, 1.0). Make a helper function.

bool ThreadPool::ThreadTask::finished() {
    if(isFinished->load()){
        if(onFinish && !handled){
            handled = true;
            onFinish();
            if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){
                (*onGroupFinish)();
            }
        }
        return true;
    }
    return false; }
  • This is a minor stylistic thing. I prefer for code to return as soon as possible, so the main body of the program continues the normal execution path, and reducing the indent level. I'd write it this way:

      bool ThreadPool::ThreadTask::finished() {
          if(!isFinished->load()){
              return false;
          }
          if(onFinish && !handled){
              handled = true;
              onFinish();
              if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){
                  (*onGroupFinish)();
              }
          }
          return true;
      }
    
  • In ThreadPool::ThreadPool(size_t a_threads) you're using std::cout to log. This violates two paradigms: your code that does the work shouldn't have any user interface stuff in it, and you should use a flexible logging package that can easily be switched on and off. How about Boost::Log?

  • ThreadPool::tasks() and ThreadPool::task() have some common code. How about factoring it out?

  • Emitter::randomMix has repeated randomNumber(0.0, 1.0). Make a helper function.

Source Link
Snowbody
  • 8.7k
  • 25
  • 50

bool ThreadPool::ThreadTask::finished() {
    if(isFinished->load()){
        if(onFinish && !handled){
            handled = true;
            onFinish();
            if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){
                (*onGroupFinish)();
            }
        }
        return true;
    }
    return false; }
  • This is a minor stylistic thing. I prefer for code to return as soon as possible, so the main body of the program continues the normal execution path, and reducing the indent level. I'd write it this way:

    bool ThreadPool::ThreadTask::finished() { if(!isFinished->load()){ return false; } if(onFinish && !handled){ handled = true; onFinish(); if(groupFinishWaitForFrame && (onGroupFinish && groupCounter && *groupCounter == 0)){ (*onGroupFinish)(); } } return true; }

  • In ThreadPool::ThreadPool(size_t a_threads) you're using std::cout to log. This violates two paradigms: your code that does the work shouldn't have any user interface stuff in it, and you should use a flexible logging package that can easily be switched on and off. How about Boost::Log?

  • ThreadPool::tasks() and ThreadPool::task() have some common code. How about factoring it out?

  • Emitter::randomMix has repeated randomNumber(0.0, 1.0). Make a helper function.