mirror of https://github.com/grpc/grpc.git
Remove unused eventmanager_libuv code (#25796)
parent
0147d99c41
commit
077f627aef
21 changed files with 0 additions and 466 deletions
@ -1,35 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_INTERFACE_H |
||||
#define GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_INTERFACE_H |
||||
|
||||
namespace grpc { |
||||
namespace experimental { |
||||
|
||||
class BaseEventManagerInterface { |
||||
public: |
||||
virtual ~BaseEventManagerInterface() {} |
||||
}; |
||||
|
||||
class EpollEventManagerInterface : public BaseEventManagerInterface {}; |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc
|
||||
|
||||
#endif /* GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_INTERFACE_H */ |
@ -1,88 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/iomgr/poller/eventmanager_libuv.h" |
||||
|
||||
#include <grpc/support/time.h> |
||||
|
||||
grpc::experimental::LibuvEventManager::Options::Options() : num_workers_(-1) {} |
||||
grpc::experimental::LibuvEventManager::Options::Options(int num_workers) |
||||
: num_workers_(num_workers) {} |
||||
|
||||
grpc::experimental::LibuvEventManager::LibuvEventManager(const Options& options) |
||||
: options_(options) { |
||||
int num_workers = options_.num_workers(); |
||||
// Number of workers can't be 0 if we do not accept thread donation.
|
||||
// TODO(guantaol): replaces the hard-coded number with a flag.
|
||||
if (num_workers <= 0) num_workers = 32; |
||||
|
||||
for (int i = 0; i < num_workers; i++) { |
||||
workers_.emplace_back( |
||||
options_.thread_name_prefix().c_str(), |
||||
[](void* em) { static_cast<LibuvEventManager*>(em)->RunWorkerLoop(); }, |
||||
this); |
||||
workers_.back().Start(); |
||||
} |
||||
} |
||||
|
||||
grpc::experimental::LibuvEventManager::~LibuvEventManager() { |
||||
Shutdown(); |
||||
for (auto& th : workers_) { |
||||
th.Join(); |
||||
} |
||||
} |
||||
|
||||
void grpc::experimental::LibuvEventManager::RunWorkerLoop() { |
||||
while (true) { |
||||
// TODO(guantaol): extend the worker loop with real work.
|
||||
if (ShouldStop()) return; |
||||
gpr_sleep_until(gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), |
||||
gpr_time_from_micros(10, GPR_TIMESPAN))); |
||||
} |
||||
} |
||||
|
||||
bool grpc::experimental::LibuvEventManager::ShouldStop() { |
||||
return should_stop_.Load(grpc_core::MemoryOrder::ACQUIRE) != 0; |
||||
} |
||||
|
||||
void grpc::experimental::LibuvEventManager::Shutdown() { |
||||
if (should_stop_.Load(grpc_core::MemoryOrder::ACQUIRE)) { |
||||
return; // Already shut down.
|
||||
} |
||||
|
||||
{ |
||||
grpc_core::MutexLock lock(&shutdown_mu_); |
||||
while (shutdown_refcount_.Load(grpc_core::MemoryOrder::ACQUIRE) > 0) { |
||||
shutdown_cv_.Wait(&shutdown_mu_); |
||||
} |
||||
} |
||||
should_stop_.Store(true, grpc_core::MemoryOrder::RELEASE); |
||||
} |
||||
|
||||
void grpc::experimental::LibuvEventManager::ShutdownRef() { |
||||
shutdown_refcount_.FetchAdd(1, grpc_core::MemoryOrder::RELAXED); |
||||
} |
||||
|
||||
void grpc::experimental::LibuvEventManager::ShutdownUnref() { |
||||
if (shutdown_refcount_.FetchSub(1, grpc_core::MemoryOrder::ACQ_REL) == 1) { |
||||
grpc_core::MutexLock lock(&shutdown_mu_); |
||||
shutdown_cv_.Signal(); |
||||
} |
||||
} |
@ -1,88 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_LIBUV_H |
||||
#define GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_LIBUV_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "src/core/lib/gprpp/atomic.h" |
||||
#include "src/core/lib/gprpp/sync.h" |
||||
#include "src/core/lib/gprpp/thd.h" |
||||
|
||||
namespace grpc { |
||||
namespace experimental { |
||||
|
||||
class LibuvEventManager { |
||||
public: |
||||
class Options { |
||||
public: |
||||
Options(); |
||||
explicit Options(int num_workers); |
||||
|
||||
int num_workers() const { return num_workers_; } |
||||
void set_num_workers(int num) { num_workers_ = num; } |
||||
|
||||
const std::string& thread_name_prefix() const { |
||||
return thread_name_prefix_; |
||||
} |
||||
void set_thread_name_prefix(const std::string& name) { |
||||
thread_name_prefix_ = name; |
||||
} |
||||
|
||||
private: |
||||
// Number of worker threads to create at startup. If less than 0, uses the
|
||||
// default value of 32.
|
||||
int num_workers_; |
||||
// Name prefix used for worker.
|
||||
std::string thread_name_prefix_; |
||||
}; |
||||
|
||||
explicit LibuvEventManager(const Options& options); |
||||
virtual ~LibuvEventManager(); |
||||
|
||||
void Shutdown(); |
||||
void ShutdownRef(); |
||||
void ShutdownUnref(); |
||||
|
||||
private: |
||||
// Function run by the worker threads.
|
||||
void RunWorkerLoop(); |
||||
|
||||
// Whether the EventManager has been shut down.
|
||||
bool ShouldStop(); |
||||
|
||||
const Options options_; |
||||
// Whether the EventManager workers should be stopped.
|
||||
grpc_core::Atomic<bool> should_stop_{false}; |
||||
// A refcount preventing the EventManager from shutdown.
|
||||
grpc_core::Atomic<int> shutdown_refcount_{0}; |
||||
// Worker threads of the EventManager.
|
||||
std::vector<grpc_core::Thread> workers_; |
||||
// Mutex and condition variable used for shutdown.
|
||||
grpc_core::Mutex shutdown_mu_; |
||||
grpc_core::CondVar shutdown_cv_; |
||||
}; |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc
|
||||
|
||||
#endif /* GRPC_CORE_LIB_IOMGR_POLLER_EVENTMANAGER_LIBUV_H */ |
@ -1,42 +0,0 @@ |
||||
# Copyright 2019 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") |
||||
|
||||
licenses(["notice"]) |
||||
|
||||
grpc_package( |
||||
name = "test/core/iomgr/poller", |
||||
visibility = "public", |
||||
) # Used to test IO poller implementations. |
||||
|
||||
grpc_cc_test( |
||||
name = "eventmanager_libuv_test", |
||||
srcs = ["eventmanager_libuv_test.cc"], |
||||
external_deps = [ |
||||
"gtest", |
||||
], |
||||
language = "C++", |
||||
tags = [ |
||||
# TSAN has a false-positive for ShutdownRefAsync |
||||
# https://github.com/grpc/grpc/issues/24242 |
||||
"notsan", |
||||
], |
||||
uses_polling = False, |
||||
deps = [ |
||||
"//:eventmanager_libuv", |
||||
"//:grpc_base_c", |
||||
"//test/core/util:grpc_test_util", |
||||
], |
||||
) |
@ -1,90 +0,0 @@ |
||||
|
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/lib/iomgr/poller/eventmanager_libuv.h" |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/time.h> |
||||
#include <gtest/gtest.h> |
||||
|
||||
#include "test/core/util/test_config.h" |
||||
|
||||
using grpc::experimental::LibuvEventManager; |
||||
|
||||
namespace grpc_core { |
||||
namespace { |
||||
|
||||
TEST(LibuvEventManager, Allocation) { |
||||
for (int i = 0; i < 10; i++) { |
||||
LibuvEventManager* em = |
||||
new LibuvEventManager(LibuvEventManager::Options(i)); |
||||
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1)); |
||||
delete em; |
||||
} |
||||
} |
||||
|
||||
TEST(LibuvEventManager, ShutdownRef) { |
||||
for (int i = 0; i < 10; i++) { |
||||
LibuvEventManager* em = |
||||
new LibuvEventManager(LibuvEventManager::Options(i)); |
||||
for (int j = 0; j < i; j++) { |
||||
em->ShutdownRef(); |
||||
} |
||||
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1)); |
||||
for (int j = 0; j < i; j++) { |
||||
em->ShutdownUnref(); |
||||
} |
||||
delete em; |
||||
} |
||||
} |
||||
|
||||
TEST(LibuvEventManager, ShutdownRefAsync) { |
||||
for (int i = 0; i < 10; i++) { |
||||
LibuvEventManager* em = |
||||
new LibuvEventManager(LibuvEventManager::Options(i)); |
||||
for (int j = 0; j < i; j++) { |
||||
em->ShutdownRef(); |
||||
} |
||||
// TSAN doesn't like this approach although this would work. TSAN considers
|
||||
// it dangerous to have a destructor being called while its member function
|
||||
// is called but LibuvEventManager handles this by making LibuvEventManager
|
||||
// wait until all pending operations finish.
|
||||
grpc_core::Thread deleter( |
||||
"deleter", [](void* em) { delete static_cast<LibuvEventManager*>(em); }, |
||||
em); |
||||
deleter.Start(); |
||||
gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(1)); |
||||
for (int j = 0; j < i; j++) { |
||||
em->ShutdownUnref(); |
||||
} |
||||
deleter.Join(); |
||||
} |
||||
} |
||||
|
||||
} // namespace
|
||||
} // namespace grpc_core
|
||||
|
||||
int main(int argc, char** argv) { |
||||
grpc_init(); |
||||
grpc::testing::TestEnvironment env(argc, argv); |
||||
::testing::InitGoogleTest(&argc, argv); |
||||
int retval = RUN_ALL_TESTS(); |
||||
grpc_shutdown(); |
||||
return retval; |
||||
} |
Loading…
Reference in new issue