mutexInitialized_(false),
condInitialized_(false) {
- if(pthread_mutex_init(&pthread_mutex_, NULL) == 0) {
+ if (pthread_mutex_init(&pthread_mutex_, NULL) == 0) {
mutexInitialized_ = true;
- if(pthread_cond_init(&pthread_cond_, NULL) == 0) {
+ if (pthread_cond_init(&pthread_cond_, NULL) == 0) {
condInitialized_ = true;
}
}
- if(!mutexInitialized_ || !condInitialized_) {
+ if (!mutexInitialized_ || !condInitialized_) {
cleanup();
throw SystemResourceException();
}
&pthread_mutex_,
&abstime);
if (result == ETIMEDOUT) {
- assert(Util::currentTime() >= (now + timeout));
+ assert(Util::currentTime() >= (now + timeout));
throw TimedOutException();
}
}
state_ = starting;
pthread_attr_t thread_attr;
- if(pthread_attr_init(&thread_attr) != 0) {
+ if (pthread_attr_init(&thread_attr) != 0) {
throw SystemResourceException("pthread_attr_init failed");
}
- if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE) != 0) {
- throw SystemResourceException("pthread_attr_setdetachstate failed");
+ if (pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE) != 0) {
+ throw SystemResourceException("pthread_attr_setdetachstate failed");
}
// Set thread stack size
- if(pthread_attr_setstacksize(&thread_attr, MB * stackSize_) != 0) {
- throw SystemResourceException("pthread_attr_setstacksize failed");
+ if (pthread_attr_setstacksize(&thread_attr, MB * stackSize_) != 0) {
+ throw SystemResourceException("pthread_attr_setstacksize failed");
}
// Set thread policy
- if(pthread_attr_setschedpolicy(&thread_attr, policy_) != 0) {
- throw SystemResourceException("pthread_attr_setschedpolicy failed");
+ if (pthread_attr_setschedpolicy(&thread_attr, policy_) != 0) {
+ throw SystemResourceException("pthread_attr_setschedpolicy failed");
}
struct sched_param sched_param;
sched_param.sched_priority = priority_;
// Set thread priority
- if(pthread_attr_setschedparam(&thread_attr, &sched_param) != 0) {
- throw SystemResourceException("pthread_attr_setschedparam failed");
+ if (pthread_attr_setschedparam(&thread_attr, &sched_param) != 0) {
+ throw SystemResourceException("pthread_attr_setschedparam failed");
}
// Create reference
shared_ptr<PthreadThread>* selfRef = new shared_ptr<PthreadThread>();
*selfRef = self_.lock();
- if(pthread_create(&pthread_, &thread_attr, threadMain, (void*)selfRef) != 0) {
- throw SystemResourceException("pthread_create failed");
+ if (pthread_create(&pthread_, &thread_attr, threadMain, (void*)selfRef) != 0) {
+ throw SystemResourceException("pthread_create failed");
}
}
PRIORITY priority() const { return priority_; }
- Thread::id_t currentThreadId() const {return pthread_self();}
+ Thread::id_t currentThreadId() const { return pthread_self(); }
/**
* Sets priority.
void PosixThreadFactory::priority(PosixThreadFactory::PRIORITY value) { impl_->priority(value); }
-Thread::id_t PosixThreadFactory::currentThreadId() const {return impl_->currentThreadId();}
+Thread::id_t PosixThreadFactory::currentThreadId() const { return impl_->currentThreadId(); }
}}} // facebook::thrift::concurrency
/* If we have a pending task max and we just dropped below it, wakeup any
thread that might be blocked on add. */
- if(manager_->pendingTaskCountMax_ != 0 &&
- manager_->tasks_.size() == manager_->pendingTaskCountMax_ - 1) {
+ if (manager_->pendingTaskCountMax_ != 0 &&
+ manager_->tasks_.size() == manager_->pendingTaskCountMax_ - 1) {
manager_->workerMonitor_.notify();
}
}
throw IllegalStateException();
}
- if(pendingTaskCountMax_ > 0 && (tasks_.size() >= pendingTaskCountMax_)) {
+ if (pendingTaskCountMax_ > 0 && (tasks_.size() >= pendingTaskCountMax_)) {
- if(canSleep()) {
+ if (canSleep()) {
- while(pendingTaskCountMax_ > 0 && tasks_.size() >= pendingTaskCountMax_) {
+ while (pendingTaskCountMax_ > 0 && tasks_.size() >= pendingTaskCountMax_) {
monitor_.wait(timeout);
}
} else {
class SimpleThreadManager : public ThreadManager::Impl {
-public:
+ public:
SimpleThreadManager(size_t workerCount=4, size_t pendingTaskCountMax=0) :
workerCount_(workerCount),
pendingTaskCountMax_(pendingTaskCountMax),
addWorker(workerCount_);
}
-private:
+ private:
const size_t workerCount_;
const size_t pendingTaskCountMax_;
bool firstTime_;