Modified facebook::thrift::concurrency::Monitor.wait:
        Throw TimedOutException on wait timeout so caller can distinguish between timeout and event.

Modified facebook::thrift::concurrency::PthreadThread.start:
        Throw SystemrResourceException on any pthread_* function call failure rather than asserting 0.

Added facebook::thrift::concurrency::Thread.id() and  facebook::thrift::concurrency::ThreadFactory.currentThreadId():
        Return thread-id of thread and current thread respectively.  Needed for reentrancy tests in ThreadManager

Added facebook::thrift::concurrency::ThreadManager.pendingTaskCountMaxN
Modified facebook::thrift::concurrency::ThreadManager.add():
        Now support a maximum pending task count and block if the current pending task count is max.
        If timeout is specified for add, TimedOutException is thrown if pending task count doesn't decrease
        in the timeout interval.  If add() is called by a ThreadManager worker thread and the task cannot
        be added, a TooManyPendingTasksException is thrown rather than blocking, since deadlocks can ensue
        if worker threads block waiting for works threads to complete tasks.

Reviewed By: mcslee, aditya

Revert Plan: revertible

Test Plan: concurrency/test/ThreadManagerTests.h
           run concurrency-test thread-manager


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665120 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Thread.h b/lib/cpp/src/concurrency/Thread.h
index 96ca668..e928fc4 100644
--- a/lib/cpp/src/concurrency/Thread.h
+++ b/lib/cpp/src/concurrency/Thread.h
@@ -10,12 +10,12 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 
-namespace facebook { namespace thrift { namespace concurrency { 
+namespace facebook { namespace thrift { namespace concurrency {
 
 class Thread;
 
 /**
- * Minimal runnable class.  More or less analogous to java.lang.Runnable. 
+ * Minimal runnable class.  More or less analogous to java.lang.Runnable.
  *
  * @author marc
  * @version $Id:$
@@ -43,7 +43,7 @@
 };
 
 /**
- * Minimal thread class. Returned by thread factory bound to a Runnable object 
+ * Minimal thread class. Returned by thread factory bound to a Runnable object
  * and ready to start execution.  More or less analogous to java.lang.Thread
  * (minus all the thread group, priority, mode and other baggage, since that
  * is difficult to abstract across platforms and is left for platform-specific
@@ -52,8 +52,11 @@
  * @see facebook::thrift::concurrency::ThreadFactory)
  */
 class Thread {
-  
+
  public:
+
+  typedef unsigned long long id_t;
+
   virtual ~Thread() {};
 
   /**
@@ -70,6 +73,11 @@
   virtual void join() = 0;
 
   /**
+   * Gets the thread's platform-specific ID
+   */
+  virtual id_t id() = 0;
+
+  /**
    * Gets the runnable object this thread is hosting
    */
   virtual boost::shared_ptr<Runnable> runnable() const { return _runnable; }
@@ -79,6 +87,7 @@
 
  private:
   boost::shared_ptr<Runnable> _runnable;
+
 };
 
 /**
@@ -90,6 +99,12 @@
  public:
   virtual ~ThreadFactory() {}
   virtual boost::shared_ptr<Thread> newThread(boost::shared_ptr<Runnable> runnable) const = 0;
+
+  /** Gets the current thread id or unknown_thread_id if the current thread is not a thrift thread */
+
+  static const Thread::id_t unknown_thread_id;
+
+  virtual Thread::id_t currentThreadId() const = 0;
 };
 
 }}} // facebook::thrift::concurrency