mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 11:49:02 +08:00
size_t -> int
This commit is contained in:
parent
76308e7fd2
commit
f1f2ff8208
@ -172,7 +172,7 @@ struct ThreadPoolDevice {
|
|||||||
pool_->Schedule(func);
|
pool_->Schedule(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_STRONG_INLINE size_t currentThreadId() const {
|
EIGEN_STRONG_INLINE int currentThreadId() const {
|
||||||
return pool_->CurrentThreadId();
|
return pool_->CurrentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,17 +95,17 @@ class NonBlockingThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
env_.ExecuteTask(t); // Push failed, execute directly.
|
env_.ExecuteTask(t); // Push failed, execute directly.
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t NumThreads() const final {
|
int NumThreads() const final {
|
||||||
return threads_.size();
|
return static_cast<int>(threads_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CurrentThreadId() const {
|
int CurrentThreadId() const {
|
||||||
const PerThread* pt =
|
const PerThread* pt =
|
||||||
const_cast<NonBlockingThreadPoolTempl*>(this)->GetPerThread();
|
const_cast<NonBlockingThreadPoolTempl*>(this)->GetPerThread();
|
||||||
if (pt->pool == this) {
|
if (pt->pool == this) {
|
||||||
return static_cast<size_t>(pt->thread_id);
|
return pt->thread_id;
|
||||||
} else {
|
} else {
|
||||||
return threads_.size();
|
return NumThreads();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,9 +114,9 @@ class NonBlockingThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
|
|
||||||
struct PerThread {
|
struct PerThread {
|
||||||
bool inited;
|
bool inited;
|
||||||
NonBlockingThreadPoolTempl* pool; // Parent pool, or null for normal threads.
|
NonBlockingThreadPoolTempl* pool; // Parent pool, or null for normal threads.
|
||||||
unsigned thread_id; // Worker thread index in pool.
|
int thread_id; // Worker thread index in pool.
|
||||||
unsigned rand; // Random generator state.
|
unsigned rand; // Random generator state.
|
||||||
};
|
};
|
||||||
|
|
||||||
Environment env_;
|
Environment env_;
|
||||||
@ -130,7 +130,7 @@ class NonBlockingThreadPoolTempl : public Eigen::ThreadPoolInterface {
|
|||||||
EventCount ec_;
|
EventCount ec_;
|
||||||
|
|
||||||
// Main worker thread loop.
|
// Main worker thread loop.
|
||||||
void WorkerLoop(unsigned thread_id) {
|
void WorkerLoop(int thread_id) {
|
||||||
PerThread* pt = GetPerThread();
|
PerThread* pt = GetPerThread();
|
||||||
pt->pool = this;
|
pt->pool = this;
|
||||||
pt->thread_id = thread_id;
|
pt->thread_id = thread_id;
|
||||||
|
@ -69,21 +69,21 @@ class SimpleThreadPoolTempl : public ThreadPoolInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t NumThreads() const final {
|
int NumThreads() const final {
|
||||||
return threads_.size();
|
return static_cast<int>(threads_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CurrentThreadId() const final {
|
int CurrentThreadId() const final {
|
||||||
const PerThread* pt = this->GetPerThread();
|
const PerThread* pt = this->GetPerThread();
|
||||||
if (pt->pool == this) {
|
if (pt->pool == this) {
|
||||||
return pt->thread_id;
|
return pt->thread_id;
|
||||||
} else {
|
} else {
|
||||||
return threads_.size();
|
return NumThreads();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void WorkerLoop(size_t thread_id) {
|
void WorkerLoop(int thread_id) {
|
||||||
std::unique_lock<std::mutex> l(mu_);
|
std::unique_lock<std::mutex> l(mu_);
|
||||||
PerThread* pt = GetPerThread();
|
PerThread* pt = GetPerThread();
|
||||||
pt->pool = this;
|
pt->pool = this;
|
||||||
@ -129,15 +129,15 @@ class SimpleThreadPoolTempl : public ThreadPoolInterface {
|
|||||||
|
|
||||||
struct PerThread {
|
struct PerThread {
|
||||||
ThreadPoolTempl* pool; // Parent pool, or null for normal threads.
|
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_;
|
Environment env_;
|
||||||
std::mutex mu_;
|
std::mutex mu_;
|
||||||
MaxSizeVector<Thread*> threads_; // All threads
|
MaxSizeVector<Thread*> threads_; // All threads
|
||||||
MaxSizeVector<Waiter*> waiters_; // Stack of waiting threads.
|
MaxSizeVector<Waiter*> waiters_; // Stack of waiting threads.
|
||||||
std::deque<Task> pending_; // Queue of pending work
|
std::deque<Task> pending_; // Queue of pending work
|
||||||
std::condition_variable empty_; // Signaled on pending_.empty()
|
std::condition_variable empty_; // Signaled on pending_.empty()
|
||||||
bool exiting_ = false;
|
bool exiting_ = false;
|
||||||
|
|
||||||
PerThread* GetPerThread() const {
|
PerThread* GetPerThread() const {
|
||||||
|
@ -19,11 +19,11 @@ class ThreadPoolInterface {
|
|||||||
virtual void Schedule(std::function<void()> fn) = 0;
|
virtual void Schedule(std::function<void()> fn) = 0;
|
||||||
|
|
||||||
// Returns the number of threads in the pool.
|
// 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
|
// Returns a logical thread index between 0 and NumThreads() - 1 if called
|
||||||
// from one of the threads in the pool. Returns NumThreads() otherwise.
|
// from one of the threads in the pool. Returns NumThreads() otherwise.
|
||||||
virtual size_t CurrentThreadId() const = 0;
|
virtual int CurrentThreadId() const = 0;
|
||||||
|
|
||||||
virtual ~ThreadPoolInterface() {}
|
virtual ~ThreadPoolInterface() {}
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ static void test_parallelism()
|
|||||||
// Schedule kThreads tasks and ensure that they all are running.
|
// Schedule kThreads tasks and ensure that they all are running.
|
||||||
for (int i = 0; i < kThreads; ++i) {
|
for (int i = 0; i < kThreads; ++i) {
|
||||||
tp.Schedule([&]() {
|
tp.Schedule([&]() {
|
||||||
const size_t thread_id = tp.CurrentThreadId();
|
const int thread_id = tp.CurrentThreadId();
|
||||||
VERIFY_GE(thread_id, 0);
|
VERIFY_GE(thread_id, 0);
|
||||||
VERIFY_LE(thread_id, kThreads - 1);
|
VERIFY_LE(thread_id, kThreads - 1);
|
||||||
running++;
|
running++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user