You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2020/03/04 23:40:21 UTC
[kudu] branch master updated: blocking_queue: replace gscoped_ptr
with unique_ptr
This is an automated email from the ASF dual-hosted git repository.
adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 61ddfe3 blocking_queue: replace gscoped_ptr with unique_ptr
61ddfe3 is described below
commit 61ddfe31bf8abe95484d4bd83e2ecee0155e7b13
Author: Adar Dembo <ad...@cloudera.com>
AuthorDate: Fri Feb 28 17:21:09 2020 -0800
blocking_queue: replace gscoped_ptr with unique_ptr
Change-Id: I6f63bebeb1c450523ff89921ec0f75872937c14f
Reviewed-on: http://gerrit.cloudera.org:8080/15357
Reviewed-by: Andrew Wong <aw...@cloudera.com>
Tested-by: Kudu Jenkins
---
src/kudu/util/blocking_queue-test.cc | 9 +++++----
src/kudu/util/blocking_queue.h | 29 ++++++++++++++++-------------
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/src/kudu/util/blocking_queue-test.cc b/src/kudu/util/blocking_queue-test.cc
index bc897e1..a0f1297 100644
--- a/src/kudu/util/blocking_queue-test.cc
+++ b/src/kudu/util/blocking_queue-test.cc
@@ -21,13 +21,13 @@
#include <cstdint>
#include <list>
#include <map>
+#include <memory>
#include <string>
#include <thread>
#include <vector>
#include <gtest/gtest.h>
-#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/util/countdown_latch.h"
#include "kudu/util/monotime.h"
#include "kudu/util/mutex.h"
@@ -37,6 +37,7 @@
using std::string;
using std::thread;
+using std::unique_ptr;
using std::vector;
namespace kudu {
@@ -241,11 +242,11 @@ TEST(BlockingQueueTest, TestGetFromShutdownQueue) {
ASSERT_FALSE(s.ok()) << s.ToString();
}
-TEST(BlockingQueueTest, TestGscopedPtrMethods) {
+TEST(BlockingQueueTest, TestUniquePtrMethods) {
BlockingQueue<int*> test_queue(2);
- gscoped_ptr<int> input_int(new int(123));
+ unique_ptr<int> input_int(new int(123));
ASSERT_EQ(test_queue.Put(&input_int), QUEUE_SUCCESS);
- gscoped_ptr<int> output_int;
+ unique_ptr<int> output_int;
ASSERT_OK(test_queue.BlockingGet(&output_int));
ASSERT_EQ(123, *output_int.get());
test_queue.Shutdown();
diff --git a/src/kudu/util/blocking_queue.h b/src/kudu/util/blocking_queue.h
index a26b3aa..40734b4 100644
--- a/src/kudu/util/blocking_queue.h
+++ b/src/kudu/util/blocking_queue.h
@@ -17,13 +17,13 @@
#pragma once
#include <list>
+#include <memory>
#include <string>
#include <type_traits>
#include <unistd.h>
#include <vector>
#include "kudu/gutil/basictypes.h"
-#include "kudu/gutil/gscoped_ptr.h"
#include "kudu/util/condition_variable.h"
#include "kudu/util/monotime.h"
#include "kudu/util/mutex.h"
@@ -79,7 +79,7 @@ class BlockingQueue {
// - OK if successful
// - TimedOut if the deadline passed
// - Aborted if the queue shut down
- Status BlockingGet(T *out, MonoTime deadline = MonoTime()) {
+ Status BlockingGet(T* out, MonoTime deadline = MonoTime()) {
MutexLock l(lock_);
while (true) {
if (!list_.empty()) {
@@ -102,7 +102,7 @@ class BlockingQueue {
// Get an element from the queue. Returns false if the queue is empty and
// we were shut down prior to getting the element.
- Status BlockingGet(gscoped_ptr<T_VAL> *out, MonoTime deadline = MonoTime()) {
+ Status BlockingGet(std::unique_ptr<T_VAL>* out, MonoTime deadline = MonoTime()) {
T t = nullptr;
RETURN_NOT_OK(BlockingGet(&t, deadline));
out->reset(t);
@@ -148,10 +148,10 @@ class BlockingQueue {
// Attempts to put the given value in the queue.
// Returns:
- // QUEUE_SUCCESS: if successfully inserted
+ // QUEUE_SUCCESS: if successfully enqueued
// QUEUE_FULL: if the queue has reached max_size
// QUEUE_SHUTDOWN: if someone has already called Shutdown()
- QueueStatus Put(const T &val) {
+ QueueStatus Put(const T& val) {
MutexLock l(lock_);
if (size_ >= max_size_) {
return QUEUE_FULL;
@@ -166,9 +166,10 @@ class BlockingQueue {
return QUEUE_SUCCESS;
}
- // Returns the same as the other Put() overload above.
- // If the element was inserted, the gscoped_ptr releases its contents.
- QueueStatus Put(gscoped_ptr<T_VAL> *val) {
+ // Same as other Put() overload above.
+ //
+ // If the element was enqueued, the contents of 'val' are released.
+ QueueStatus Put(std::unique_ptr<T_VAL>* val) {
QueueStatus s = Put(val->get());
if (s == QUEUE_SUCCESS) {
ignore_result<>(val->release());
@@ -211,17 +212,20 @@ class BlockingQueue {
}
}
- // Same as other BlockingPut() overload above. If the element was
- // enqueued, gscoped_ptr releases its contents.
- Status BlockingPut(gscoped_ptr<T_VAL>* val, MonoTime deadline = MonoTime()) {
+ // Same as other BlockingPut() overload above.
+ //
+ // If the element was enqueued, the contents of 'val' are released.
+ Status BlockingPut(std::unique_ptr<T_VAL>* val, MonoTime deadline = MonoTime()) {
RETURN_NOT_OK(BlockingPut(val->get(), deadline));
ignore_result(val->release());
return Status::OK();
}
- // Shut down the queue.
+ // Shuts down the queue.
+ //
// When a blocking queue is shut down, no more elements can be added to it,
// and Put() will return QUEUE_SHUTDOWN.
+ //
// Existing elements will drain out of it, and then BlockingGet will start
// returning false.
void Shutdown() {
@@ -273,4 +277,3 @@ class BlockingQueue {
};
} // namespace kudu
-