Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code to work with recent abseil changes #1919

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cartographer/cloud/internal/map_builder_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ class MapBuilderServer : public MapBuilderServerInterface {
absl::Mutex subscriptions_lock_;
int current_subscription_index_ = 0;
std::map<int /* trajectory ID */, LocalSlamResultHandlerSubscriptions>
local_slam_subscriptions_ GUARDED_BY(subscriptions_lock_);
local_slam_subscriptions_ ABSL_GUARDED_BY(subscriptions_lock_);
std::map<int /* subscription_index */,
MapBuilderContextInterface::GlobalSlamOptimizationCallback>
global_slam_subscriptions_ GUARDED_BY(subscriptions_lock_);
global_slam_subscriptions_ ABSL_GUARDED_BY(subscriptions_lock_);
std::unique_ptr<LocalTrajectoryUploaderInterface> local_trajectory_uploader_;
int starting_submap_index_ = 0;
};
Expand Down
20 changes: 10 additions & 10 deletions cartographer/common/internal/blocking_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BlockingQueue {

// Pushes a value onto the queue. Blocks if the queue is full.
void Push(T t) {
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return QueueNotFullCondition();
};
absl::MutexLock lock(&mutex_);
Expand All @@ -57,7 +57,7 @@ class BlockingQueue {

// Like push, but returns false if 'timeout' is reached.
bool PushWithTimeout(T t, const common::Duration timeout) {
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return QueueNotFullCondition();
};
absl::MutexLock lock(&mutex_);
Expand All @@ -71,7 +71,7 @@ class BlockingQueue {

// Pops the next value from the queue. Blocks until a value is available.
T Pop() {
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return !QueueEmptyCondition();
};
absl::MutexLock lock(&mutex_);
Expand All @@ -84,7 +84,7 @@ class BlockingQueue {

// Like Pop, but can timeout. Returns nullptr in this case.
T PopWithTimeout(const common::Duration timeout) {
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return !QueueEmptyCondition();
};
absl::MutexLock lock(&mutex_);
Expand All @@ -100,7 +100,7 @@ class BlockingQueue {
// Like Peek, but can timeout. Returns nullptr in this case.
template <typename R>
R* PeekWithTimeout(const common::Duration timeout) {
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return !QueueEmptyCondition();
};
absl::MutexLock lock(&mutex_);
Expand Down Expand Up @@ -131,7 +131,7 @@ class BlockingQueue {

// Blocks until the queue is empty.
void WaitUntilEmpty() {
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return QueueEmptyCondition();
};
absl::MutexLock lock(&mutex_);
Expand All @@ -140,18 +140,18 @@ class BlockingQueue {

private:
// Returns true iff the queue is empty.
bool QueueEmptyCondition() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
bool QueueEmptyCondition() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return deque_.empty();
}

// Returns true iff the queue is not full.
bool QueueNotFullCondition() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
bool QueueNotFullCondition() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return queue_size_ == kInfiniteQueueSize || deque_.size() < queue_size_;
}

absl::Mutex mutex_;
const size_t queue_size_ GUARDED_BY(mutex_);
std::deque<T> deque_ GUARDED_BY(mutex_);
const size_t queue_size_ ABSL_GUARDED_BY(mutex_);
std::deque<T> deque_ ABSL_GUARDED_BY(mutex_);
};

} // namespace common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ std::weak_ptr<Task> ThreadPoolForTesting::Schedule(std::unique_ptr<Task> task) {

void ThreadPoolForTesting::WaitUntilIdle() {
const auto predicate = [this]()
EXCLUSIVE_LOCKS_REQUIRED(mutex_) { return idle_; };
ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) { return idle_; };
for (;;) {
{
absl::MutexLock locker(&mutex_);
Expand All @@ -85,7 +85,7 @@ void ThreadPoolForTesting::WaitUntilIdle() {
}

void ThreadPoolForTesting::DoWork() {
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return !task_queue_.empty() || !running_;
};
for (;;) {
Expand Down
14 changes: 7 additions & 7 deletions cartographer/common/internal/testing/thread_pool_for_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ThreadPoolForTesting : public ThreadPoolInterface {
~ThreadPoolForTesting();

std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task)
LOCKS_EXCLUDED(mutex_) override;
ABSL_LOCKS_EXCLUDED(mutex_) override;

void WaitUntilIdle();

Expand All @@ -44,14 +44,14 @@ class ThreadPoolForTesting : public ThreadPoolInterface {

void DoWork();

void NotifyDependenciesCompleted(Task* task) LOCKS_EXCLUDED(mutex_) override;
void NotifyDependenciesCompleted(Task* task) ABSL_LOCKS_EXCLUDED(mutex_) override;

absl::Mutex mutex_;
bool running_ GUARDED_BY(mutex_) = true;
bool idle_ GUARDED_BY(mutex_) = true;
std::deque<std::shared_ptr<Task>> task_queue_ GUARDED_BY(mutex_);
std::map<Task*, std::shared_ptr<Task>> tasks_not_ready_ GUARDED_BY(mutex_);
std::thread thread_ GUARDED_BY(mutex_);
bool running_ ABSL_GUARDED_BY(mutex_) = true;
bool idle_ ABSL_GUARDED_BY(mutex_) = true;
std::deque<std::shared_ptr<Task>> task_queue_ ABSL_GUARDED_BY(mutex_);
std::map<Task*, std::shared_ptr<Task>> tasks_not_ready_ ABSL_GUARDED_BY(mutex_);
std::thread thread_ ABSL_GUARDED_BY(mutex_);
};

} // namespace testing
Expand Down
20 changes: 10 additions & 10 deletions cartographer/common/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,34 @@ class Task {
Task() = default;
~Task();

State GetState() LOCKS_EXCLUDED(mutex_);
State GetState() ABSL_LOCKS_EXCLUDED(mutex_);

// State must be 'NEW'.
void SetWorkItem(const WorkItem& work_item) LOCKS_EXCLUDED(mutex_);
void SetWorkItem(const WorkItem& work_item) ABSL_LOCKS_EXCLUDED(mutex_);

// State must be 'NEW'. 'dependency' may be nullptr, in which case it is
// assumed completed.
void AddDependency(std::weak_ptr<Task> dependency) LOCKS_EXCLUDED(mutex_);
void AddDependency(std::weak_ptr<Task> dependency) ABSL_LOCKS_EXCLUDED(mutex_);

private:
// Allowed in all states.
void AddDependentTask(Task* dependent_task);

// State must be 'DEPENDENCIES_COMPLETED' and becomes 'COMPLETED'.
void Execute() LOCKS_EXCLUDED(mutex_);
void Execute() ABSL_LOCKS_EXCLUDED(mutex_);

// State must be 'NEW' and becomes 'DISPATCHED' or 'DEPENDENCIES_COMPLETED'.
void SetThreadPool(ThreadPoolInterface* thread_pool) LOCKS_EXCLUDED(mutex_);
void SetThreadPool(ThreadPoolInterface* thread_pool) ABSL_LOCKS_EXCLUDED(mutex_);

// State must be 'NEW' or 'DISPATCHED'. If 'DISPATCHED', may become
// 'DEPENDENCIES_COMPLETED'.
void OnDependenyCompleted();

WorkItem work_item_ GUARDED_BY(mutex_);
ThreadPoolInterface* thread_pool_to_notify_ GUARDED_BY(mutex_) = nullptr;
State state_ GUARDED_BY(mutex_) = NEW;
unsigned int uncompleted_dependencies_ GUARDED_BY(mutex_) = 0;
std::set<Task*> dependent_tasks_ GUARDED_BY(mutex_);
WorkItem work_item_ ABSL_GUARDED_BY(mutex_);
ThreadPoolInterface* thread_pool_to_notify_ ABSL_GUARDED_BY(mutex_) = nullptr;
State state_ ABSL_GUARDED_BY(mutex_) = NEW;
unsigned int uncompleted_dependencies_ ABSL_GUARDED_BY(mutex_) = 0;
std::set<Task*> dependent_tasks_ ABSL_GUARDED_BY(mutex_);

absl::Mutex mutex_;
};
Expand Down
2 changes: 1 addition & 1 deletion cartographer/common/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void ThreadPool::DoWork() {
// away CPU resources from more important foreground threads.
CHECK_NE(nice(10), -1);
#endif
const auto predicate = [this]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
const auto predicate = [this]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return !task_queue_.empty() || !running_;
};
for (;;) {
Expand Down
12 changes: 6 additions & 6 deletions cartographer/common/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ class ThreadPool : public ThreadPoolInterface {
// When the returned weak pointer is expired, 'task' has certainly completed,
// so dependants no longer need to add it as a dependency.
std::weak_ptr<Task> Schedule(std::unique_ptr<Task> task)
LOCKS_EXCLUDED(mutex_) override;
ABSL_LOCKS_EXCLUDED(mutex_) override;

private:
void DoWork();

void NotifyDependenciesCompleted(Task* task) LOCKS_EXCLUDED(mutex_) override;
void NotifyDependenciesCompleted(Task* task) ABSL_LOCKS_EXCLUDED(mutex_) override;

absl::Mutex mutex_;
bool running_ GUARDED_BY(mutex_) = true;
std::vector<std::thread> pool_ GUARDED_BY(mutex_);
std::deque<std::shared_ptr<Task>> task_queue_ GUARDED_BY(mutex_);
bool running_ ABSL_GUARDED_BY(mutex_) = true;
std::vector<std::thread> pool_ ABSL_GUARDED_BY(mutex_);
std::deque<std::shared_ptr<Task>> task_queue_ ABSL_GUARDED_BY(mutex_);
absl::flat_hash_map<Task*, std::shared_ptr<Task>> tasks_not_ready_
GUARDED_BY(mutex_);
ABSL_GUARDED_BY(mutex_);
};

} // namespace common
Expand Down
4 changes: 2 additions & 2 deletions cartographer/common/thread_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Receiver {

void WaitForNumberSequence(const std::vector<int>& expected_numbers) {
const auto predicate =
[this, &expected_numbers]() EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
[this, &expected_numbers]() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
return (received_numbers_.size() >= expected_numbers.size());
};
absl::MutexLock locker(&mutex_);
Expand All @@ -43,7 +43,7 @@ class Receiver {
}

absl::Mutex mutex_;
std::vector<int> received_numbers_ GUARDED_BY(mutex_);
std::vector<int> received_numbers_ ABSL_GUARDED_BY(mutex_);
};

TEST(ThreadPoolTest, RunTask) {
Expand Down
Loading