Skip to content

Commit

Permalink
Remove Callback/Bind/Tuple from butil
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzhangyi committed Sep 18, 2017
1 parent c9039fd commit d921345
Show file tree
Hide file tree
Showing 29 changed files with 11 additions and 6,908 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ BUTIL_SOURCES = \
src/butil/arena.cpp \
src/butil/at_exit.cc \
src/butil/atomicops_internals_x86_gcc.cc \
src/butil/barrier_closure.cc \
src/butil/base64.cc \
src/butil/base_switches.cc \
src/butil/big_endian.cc \
src/butil/bind_helpers.cc \
src/butil/callback_helpers.cc \
src/butil/callback_internal.cc \
src/butil/cpu.cc \
src/butil/debug/alias.cc \
src/butil/debug/asan_invalid_access.cc \
Expand Down
13 changes: 3 additions & 10 deletions src/butil/at_exit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <stddef.h>
#include <ostream>

#include "butil/bind.h"
#include "butil/callback.h"
#include "butil/logging.h"

namespace butil {
Expand Down Expand Up @@ -44,18 +42,13 @@ AtExitManager::~AtExitManager() {
// static
void AtExitManager::RegisterCallback(AtExitCallbackType func, void* param) {
DCHECK(func);
RegisterTask(butil::Bind(func, param));
}

// static
void AtExitManager::RegisterTask(butil::Closure task) {
if (!g_top_manager) {
NOTREACHED() << "Tried to RegisterCallback without an AtExitManager";
return;
}

AutoLock lock(g_top_manager->lock_);
g_top_manager->stack_.push(task);
g_top_manager->stack_.push({func, param});
}

// static
Expand All @@ -68,8 +61,8 @@ void AtExitManager::ProcessCallbacksNow() {
AutoLock lock(g_top_manager->lock_);

while (!g_top_manager->stack_.empty()) {
butil::Closure task = g_top_manager->stack_.top();
task.Run();
Callback task = g_top_manager->stack_.top();
task.func(task.param);
g_top_manager->stack_.pop();
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/butil/at_exit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "butil/base_export.h"
#include "butil/basictypes.h"
#include "butil/callback.h"
#include "butil/synchronization/lock.h"

namespace butil {
Expand Down Expand Up @@ -42,9 +41,6 @@ class BASE_EXPORT AtExitManager {
// the callback function is void func(void*).
static void RegisterCallback(AtExitCallbackType func, void* param);

// Registers the specified task to be called at exit.
static void RegisterTask(butil::Closure task);

// Calls the functions registered with RegisterCallback in LIFO order. It
// is possible to register new callbacks after calling this function.
static void ProcessCallbacksNow();
Expand All @@ -57,8 +53,12 @@ class BASE_EXPORT AtExitManager {
explicit AtExitManager(bool shadow);

private:
struct Callback {
AtExitCallbackType func;
void* param;
};
butil::Lock lock_;
std::stack<butil::Closure> stack_;
std::stack<Callback> stack_;
AtExitManager* next_manager_; // Stack of managers to allow shadowing.

DISALLOW_COPY_AND_ASSIGN(AtExitManager);
Expand Down
52 changes: 0 additions & 52 deletions src/butil/barrier_closure.cc

This file was deleted.

30 changes: 0 additions & 30 deletions src/butil/barrier_closure.h

This file was deleted.

Loading

0 comments on commit d921345

Please sign in to comment.