size_t -> int

This commit is contained in:
Rasmus Munk Larsen 2016-06-03 18:06:37 -07:00
parent 76308e7fd2
commit f1f2ff8208
5 changed files with 21 additions and 21 deletions

View File

@ -172,7 +172,7 @@ struct ThreadPoolDevice {
pool_->Schedule(func);
}
EIGEN_STRONG_INLINE size_t currentThreadId() const {
EIGEN_STRONG_INLINE int currentThreadId() const {
return pool_->CurrentThreadId();
}

View File

@ -95,17 +95,17 @@ class NonBlockingThreadPoolTempl : public Eigen::ThreadPoolInterface {
env_.ExecuteTask(t); // Push failed, execute directly.
}
size_t NumThreads() const final {
return threads_.size();
int NumThreads() const final {
return static_cast<int>(threads_.size());
}
size_t CurrentThreadId() const {
int CurrentThreadId() const {
const PerThread* pt =
const_cast<NonBlockingThreadPoolTempl*>(this)->GetPerThread();
if (pt->pool == this) {
return static_cast<size_t>(pt->thread_id);
return pt->thread_id;
} else {
return threads_.size();
return NumThreads();
}
}
@ -114,9 +114,9 @@ class NonBlockingThreadPoolTempl : public Eigen::ThreadPoolInterface {
struct PerThread {
bool inited;
NonBlockingThreadPoolTempl* pool; // Parent pool, or null for normal threads.
unsigned thread_id; // Worker thread index in pool.
unsigned rand; // Random generator state.
NonBlockingThreadPoolTempl* pool; // Parent pool, or null for normal threads.
int thread_id; // Worker thread index in pool.
unsigned rand; // Random generator state.
};
Environment env_;
@ -130,7 +130,7 @@ class NonBlockingThreadPoolTempl : public Eigen::ThreadPoolInterface {
EventCount ec_;
// Main worker thread loop.
void WorkerLoop(unsigned thread_id) {
void WorkerLoop(int thread_id) {
PerThread* pt = GetPerThread();
pt->pool = this;
pt->thread_id = thread_id;

View File

@ -69,21 +69,21 @@ class SimpleThreadPoolTempl : public ThreadPoolInterface {
}
}
size_t NumThreads() const final {
return threads_.size();
int NumThreads() const final {
return static_cast<int>(threads_.size());
}
size_t CurrentThreadId() const final {
int CurrentThreadId() const final {
const PerThread* pt = this->GetPerThread();
if (pt->pool == this) {
return pt->thread_id;
} else {
return threads_.size();
return NumThreads();
}
}
protected:
void WorkerLoop(size_t thread_id) {
void WorkerLoop(int thread_id) {
std::unique_lock<std::mutex> l(mu_);
PerThread* pt = GetPerThread();
pt->pool = this;
@ -129,15 +129,15 @@ class SimpleThreadPoolTempl : public ThreadPoolInterface {
struct PerThread {
ThreadPoolTempl* pool; // Parent pool, or null for normal threads.
size_t thread_id; // Worker thread index in pool.
int thread_id; // Worker thread index in pool.
};
Environment env_;
std::mutex mu_;
MaxSizeVector<Thread*> threads_; // All threads
MaxSizeVector<Waiter*> waiters_; // Stack of waiting threads.
std::deque<Task> pending_; // Queue of pending work
std::condition_variable empty_; // Signaled on pending_.empty()
std::deque<Task> pending_; // Queue of pending work
std::condition_variable empty_; // Signaled on pending_.empty()
bool exiting_ = false;
PerThread* GetPerThread() const {

View File

@ -19,11 +19,11 @@ class ThreadPoolInterface {
virtual void Schedule(std::function<void()> fn) = 0;
// Returns the number of threads in the pool.
virtual size_t NumThreads() const = 0;
virtual int NumThreads() const = 0;
// Returns a logical thread index between 0 and NumThreads() - 1 if called
// from one of the threads in the pool. Returns NumThreads() otherwise.
virtual size_t CurrentThreadId() const = 0;
virtual int CurrentThreadId() const = 0;
virtual ~ThreadPoolInterface() {}
};

View File

@ -36,7 +36,7 @@ static void test_parallelism()
// Schedule kThreads tasks and ensure that they all are running.
for (int i = 0; i < kThreads; ++i) {
tp.Schedule([&]() {
const size_t thread_id = tp.CurrentThreadId();
const int thread_id = tp.CurrentThreadId();
VERIFY_GE(thread_id, 0);
VERIFY_LE(thread_id, kThreads - 1);
running++;