Commit 2f1eccd4 authored by John Esmet's avatar John Esmet

The code in <functional> is not supported on reasonably old systems.

Revert "fixes #190 Use the locktree escalator lambda function API, remove"

This reverts commit 34666ecb.
parent e20bccc1
...@@ -92,8 +92,6 @@ PATENT RIGHTS GRANT: ...@@ -92,8 +92,6 @@ PATENT RIGHTS GRANT:
#ifndef TOKU_LOCKTREE_H #ifndef TOKU_LOCKTREE_H
#define TOKU_LOCKTREE_H #define TOKU_LOCKTREE_H
#include <functional>
#include <db.h> #include <db.h>
#include <toku_time.h> #include <toku_time.h>
#include <toku_pthread.h> #include <toku_pthread.h>
...@@ -107,6 +105,11 @@ PATENT RIGHTS GRANT: ...@@ -107,6 +105,11 @@ PATENT RIGHTS GRANT:
#include "wfg.h" #include "wfg.h"
#include "range_buffer.h" #include "range_buffer.h"
#define TOKU_LOCKTREE_ESCALATOR_LAMBDA 0
#if TOKU_LOCKTREE_ESCALATOR_LAMBDA
#include <functional>
#endif
enum { enum {
LTM_SIZE_CURRENT = 0, LTM_SIZE_CURRENT = 0,
LTM_SIZE_LIMIT, LTM_SIZE_LIMIT,
...@@ -222,7 +225,11 @@ public: ...@@ -222,7 +225,11 @@ public:
public: public:
void create(void); void create(void);
void destroy(void); void destroy(void);
#if TOKU_LOCKTREE_ESCALATOR_LAMBDA
void run(manager *mgr, std::function<void (void)> escalate_locktrees_fun); void run(manager *mgr, std::function<void (void)> escalate_locktrees_fun);
#else
void run(manager *mgr, void (*escalate_locktrees_fun)(void *extra), void *extra);
#endif
private: private:
toku_mutex_t m_escalator_mutex; toku_mutex_t m_escalator_mutex;
toku_cond_t m_escalator_done; toku_cond_t m_escalator_done;
...@@ -335,7 +342,7 @@ public: ...@@ -335,7 +342,7 @@ public:
void escalate_all_locktrees(void); void escalate_all_locktrees(void);
// Escalate a set of locktrees // Escalate a set of locktrees
void escalate_locktrees(locktree *const *locktrees, int num_locktrees); void escalate_locktrees(locktree **locktrees, int num_locktrees);
// Add time t to the escalator's wait time statistics // Add time t to the escalator's wait time statistics
void add_escalator_wait_time(uint64_t t); void add_escalator_wait_time(uint64_t t);
......
...@@ -304,15 +304,27 @@ void locktree::manager::release_lt(locktree *lt) { ...@@ -304,15 +304,27 @@ void locktree::manager::release_lt(locktree *lt) {
} }
// test-only version of lock escalation // test-only version of lock escalation
#if TOKU_LOCKTREE_ESCALATOR_LAMBDA
void locktree::manager::run_escalation(void) { void locktree::manager::run_escalation(void) {
m_escalator.run(this, [this] () -> void { escalate_all_locktrees(); }); m_escalator.run(this, [this] () -> void { escalate_all_locktrees(); });
} }
#else
static void manager_run_escalation_fun(void *extra) {
locktree::manager *thismanager = (locktree::manager *) extra;
thismanager->escalate_all_locktrees();
}
void locktree::manager::run_escalation(void) {
m_escalator.run(this, manager_run_escalation_fun, this);
}
#endif
void locktree::manager::run_escalation_for_test(void) { void locktree::manager::run_escalation_for_test(void) {
run_escalation(); run_escalation();
} }
void locktree::manager::escalate_all_locktrees(void) { void locktree::manager::escalate_all_locktrees(void) {
if (0) fprintf(stderr, "%d %s:%u\n", toku_os_gettid(), __PRETTY_FUNCTION__, __LINE__);
uint64_t t0 = toku_current_time_microsec(); uint64_t t0 = toku_current_time_microsec();
// get all locktrees // get all locktrees
...@@ -446,7 +458,8 @@ void locktree::manager::add_escalator_wait_time(uint64_t t) { ...@@ -446,7 +458,8 @@ void locktree::manager::add_escalator_wait_time(uint64_t t) {
toku_mutex_unlock(&m_escalation_mutex); toku_mutex_unlock(&m_escalation_mutex);
} }
void locktree::manager::escalate_locktrees(locktree *const *locktrees, int num_locktrees) { void locktree::manager::escalate_locktrees(locktree **locktrees, int num_locktrees) {
if (0) fprintf(stderr, "%d %s:%u %d\n", toku_os_gettid(), __PRETTY_FUNCTION__, __LINE__, num_locktrees);
// there are too many row locks in the system and we need to tidy up. // there are too many row locks in the system and we need to tidy up.
// //
// a simple implementation of escalation does not attempt // a simple implementation of escalation does not attempt
...@@ -468,17 +481,34 @@ void locktree::manager::escalate_locktrees(locktree *const *locktrees, int num_l ...@@ -468,17 +481,34 @@ void locktree::manager::escalate_locktrees(locktree *const *locktrees, int num_l
toku_mutex_unlock(&m_escalation_mutex); toku_mutex_unlock(&m_escalation_mutex);
} }
#if !TOKU_LOCKTREE_ESCALATOR_LAMBDA
struct escalate_args {
locktree::manager *mgr;
locktree **locktrees;
int num_locktrees;
};
static void manager_escalate_locktrees(void *extra) {
escalate_args *args = (escalate_args *) extra;
args->mgr->escalate_locktrees(args->locktrees, args->num_locktrees);
}
#endif
void locktree::manager::escalate_lock_trees_for_txn(TXNID txnid UU(), locktree *lt UU()) { void locktree::manager::escalate_lock_trees_for_txn(TXNID txnid UU(), locktree *lt UU()) {
// get lock trees for txnid
const int num_locktrees = 1;
locktree *locktrees[1] = { lt };
reference_lt(lt); reference_lt(lt);
// escalate these lock trees // escalate these lock trees
locktree::escalator this_escalator; locktree::escalator this_escalator;
this_escalator.create(); this_escalator.create();
this_escalator.run(this, #if TOKU_LOCKTREE_ESCALATOR_LAMBDA
[this, lt] () -> void { this_escalator.run(this, [this,locktrees,num_locktrees] () -> void { escalate_locktrees(locktrees, num_locktrees); });
locktree *locktrees[1] = { lt }; #else
escalate_locktrees(locktrees, 1); escalate_args args = { this, locktrees, num_locktrees };
}); this_escalator.run(this, manager_escalate_locktrees, &args);
#endif
this_escalator.destroy(); this_escalator.destroy();
} }
...@@ -494,14 +524,22 @@ void locktree::escalator::destroy(void) { ...@@ -494,14 +524,22 @@ void locktree::escalator::destroy(void) {
toku_mutex_destroy(&m_escalator_mutex); toku_mutex_destroy(&m_escalator_mutex);
} }
#if TOKU_LOCKTREE_ESCALATOR_LAMBDA
void locktree::escalator::run(locktree::manager *mgr, std::function<void (void)> escalate_locktrees_fun) { void locktree::escalator::run(locktree::manager *mgr, std::function<void (void)> escalate_locktrees_fun) {
#else
void locktree::escalator::run(locktree::manager *mgr, void (*escalate_locktrees_fun)(void *extra), void *extra) {
#endif
uint64_t t0 = toku_current_time_microsec(); uint64_t t0 = toku_current_time_microsec();
toku_mutex_lock(&m_escalator_mutex); toku_mutex_lock(&m_escalator_mutex);
if (!m_escalator_running) { if (!m_escalator_running) {
// run escalation on this thread // run escalation on this thread
m_escalator_running = true; m_escalator_running = true;
toku_mutex_unlock(&m_escalator_mutex); toku_mutex_unlock(&m_escalator_mutex);
#if TOKU_LOCKTREE_ESCALATOR_LAMBDA
escalate_locktrees_fun(); escalate_locktrees_fun();
#else
escalate_locktrees_fun(extra);
#endif
toku_mutex_lock(&m_escalator_mutex); toku_mutex_lock(&m_escalator_mutex);
m_escalator_running = false; m_escalator_running = false;
toku_cond_broadcast(&m_escalator_done); toku_cond_broadcast(&m_escalator_done);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment