cpp: TNonBlockingServer overload handling and optimizations

- Establish a mechanism for TNonBlockingServer to handle overloads by
  limiting the number of connections accepted or in-process.

- Provide a framework for further work in handling server overloads.

- Limit memory consumption of connection object pool.

- Drop connections when overloaded.

- Add overload-handling behavior allowing pending tasks to be dropped
  from the front of the task queue (short of the ability to terminate
  running tasks, these are the oldest tasks in the system and thus the
  most likely to be beyond their freshness date).  This reduces the
  chance of spending valuable CPU time processing a request that the
  client has already timed out.

- Uses a single persistent pipe() to communicate task completion instead
  of constructing and monitoring a new socketpair() for every task in
  the system.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@920664 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/ThreadManager.cpp b/lib/cpp/src/concurrency/ThreadManager.cpp
index abfcf6e..7bba0e6 100644
--- a/lib/cpp/src/concurrency/ThreadManager.cpp
+++ b/lib/cpp/src/concurrency/ThreadManager.cpp
@@ -117,6 +117,8 @@
 
   void remove(shared_ptr<Runnable> task);
 
+  shared_ptr<Runnable> removeNextPending();
+
 private:
   void stopImpl(bool join);
 
@@ -163,6 +165,10 @@
     }
   }
 
+  shared_ptr<Runnable> getRunnable() {
+    return runnable_;
+  }
+
  private:
   shared_ptr<Runnable> runnable_;
   friend class ThreadManager::Worker;
@@ -458,6 +464,22 @@
   }
 }
 
+boost::shared_ptr<Runnable> ThreadManager::Impl::removeNextPending() {
+  Guard g(mutex_);
+  if (state_ != ThreadManager::STARTED) {
+    throw IllegalStateException();
+  }
+
+  if (tasks_.empty()) {
+    return boost::shared_ptr<Runnable>();
+  }
+
+  shared_ptr<ThreadManager::Task> task = tasks_.front();
+  tasks_.pop();
+  
+  return task->getRunnable();
+}
+
 class SimpleThreadManager : public ThreadManager::Impl {
 
  public: