Get the long longs out of the Thrift codebase

Summary: Replace with int64_t and don't worry about what architecture machine you're on, the typedefed int64_t will do the right thing.

Reviewed By: aditya, marc


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665123 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/concurrency/Monitor.cpp b/lib/cpp/src/concurrency/Monitor.cpp
index 8517c03..1c826c8 100644
--- a/lib/cpp/src/concurrency/Monitor.cpp
+++ b/lib/cpp/src/concurrency/Monitor.cpp
@@ -51,7 +51,7 @@
 
   void unlock() const { pthread_mutex_unlock(&pthread_mutex_); }
 
-  void wait(long long timeout) const {
+  void wait(int64_t timeout) const {
 
     // XXX Need to assert that caller owns mutex
     assert(timeout >= 0LL);
@@ -60,7 +60,7 @@
       assert(iret == 0);
     } else {
       struct timespec abstime;
-      long long now = Util::currentTime();
+      int64_t now = Util::currentTime();
       Util::toTimespec(abstime, now + timeout);
       int result = pthread_cond_timedwait(&pthread_cond_,
                                           &pthread_mutex_,
@@ -114,7 +114,7 @@
 
 void Monitor::unlock() const { impl_->unlock(); }
 
-void Monitor::wait(long long timeout) const { impl_->wait(timeout); }
+void Monitor::wait(int64_t timeout) const { impl_->wait(timeout); }
 
 void Monitor::notify() const { impl_->notify(); }
 
diff --git a/lib/cpp/src/concurrency/Monitor.h b/lib/cpp/src/concurrency/Monitor.h
index b6a9f71..1eb36eb 100644
--- a/lib/cpp/src/concurrency/Monitor.h
+++ b/lib/cpp/src/concurrency/Monitor.h
@@ -37,7 +37,7 @@
 
   virtual void unlock() const;
 
-  virtual void wait(long long timeout=0LL) const;
+  virtual void wait(int64_t timeout=0LL) const;
 
   virtual void notify() const;
 
diff --git a/lib/cpp/src/concurrency/Thread.h b/lib/cpp/src/concurrency/Thread.h
index e928fc4..3e5964f 100644
--- a/lib/cpp/src/concurrency/Thread.h
+++ b/lib/cpp/src/concurrency/Thread.h
@@ -55,7 +55,7 @@
 
  public:
 
-  typedef unsigned long long id_t;
+  typedef uint64_t id_t;
 
   virtual ~Thread() {};
 
diff --git a/lib/cpp/src/concurrency/ThreadManager.cpp b/lib/cpp/src/concurrency/ThreadManager.cpp
index 1260e5a..56de4d0 100644
--- a/lib/cpp/src/concurrency/ThreadManager.cpp
+++ b/lib/cpp/src/concurrency/ThreadManager.cpp
@@ -100,7 +100,7 @@
 
   bool canSleep();
 
-  void add(shared_ptr<Runnable> value, long long timeout);
+  void add(shared_ptr<Runnable> value, int64_t timeout);
 
   void remove(shared_ptr<Runnable> task);
 
@@ -412,7 +412,7 @@
     return idMap_.find(id) == idMap_.end();
   }
 
-  void ThreadManager::Impl::add(shared_ptr<Runnable> value, long long timeout) {
+  void ThreadManager::Impl::add(shared_ptr<Runnable> value, int64_t timeout) {
     Synchronized s(monitor_);
 
     if (state_ != ThreadManager::STARTED) {
diff --git a/lib/cpp/src/concurrency/ThreadManager.h b/lib/cpp/src/concurrency/ThreadManager.h
index 19f77cc..4c56461 100644
--- a/lib/cpp/src/concurrency/ThreadManager.h
+++ b/lib/cpp/src/concurrency/ThreadManager.h
@@ -127,7 +127,7 @@
    *
    * @throws TooManyPendingTasksException Pending task count exceeds max pending task count
    */
-  virtual void add(boost::shared_ptr<Runnable>task, long long timeout=0LL) = 0;
+  virtual void add(boost::shared_ptr<Runnable>task, int64_t timeout=0LL) = 0;
 
   /**
    * Removes a pending task
diff --git a/lib/cpp/src/concurrency/TimerManager.cpp b/lib/cpp/src/concurrency/TimerManager.cpp
index 07f05ad..2134e37 100644
--- a/lib/cpp/src/concurrency/TimerManager.cpp
+++ b/lib/cpp/src/concurrency/TimerManager.cpp
@@ -16,7 +16,7 @@
 
 using boost::shared_ptr;
 
-typedef std::multimap<long long, shared_ptr<TimerManager::Task> >::iterator task_iterator;
+typedef std::multimap<int64_t, shared_ptr<TimerManager::Task> >::iterator task_iterator;
 typedef std::pair<task_iterator, task_iterator> task_range;
 
 /**
@@ -89,10 +89,10 @@
       {
         Synchronized s(manager_->monitor_);
 	task_iterator expiredTaskEnd;
-	long long now = Util::currentTime();
+	int64_t now = Util::currentTime();
 	while (manager_->state_ == TimerManager::STARTED && 
                (expiredTaskEnd = manager_->taskMap_.upper_bound(now)) == manager_->taskMap_.begin()) {
-	  long long timeout = 0LL;
+	  int64_t timeout = 0LL;
 	  if (!manager_->taskMap_.empty()) {
             timeout = manager_->taskMap_.begin()->first - now;
 	  }
@@ -229,8 +229,8 @@
   return taskCount_;
 }
       
-void TimerManager::add(shared_ptr<Runnable> task, long long timeout) {
-  long long now = Util::currentTime();
+void TimerManager::add(shared_ptr<Runnable> task, int64_t timeout) {
+  int64_t now = Util::currentTime();
   timeout += now;
 
   {
@@ -240,7 +240,7 @@
     }
 
     taskCount_++;
-    taskMap_.insert(std::pair<long long, shared_ptr<Task> >(timeout, shared_ptr<Task>(new Task(task))));
+    taskMap_.insert(std::pair<int64_t, shared_ptr<Task> >(timeout, shared_ptr<Task>(new Task(task))));
 
     // If the task map was empty, or if we have an expiration that is earlier
     // than any previously seen, kick the dispatcher so it can update its
@@ -253,10 +253,10 @@
 
 void TimerManager::add(shared_ptr<Runnable> task, const struct timespec& value) {
 
-  long long expiration;
+  int64_t expiration;
   Util::toMilliseconds(expiration, value);
 
-  long long now = Util::currentTime();
+  int64_t now = Util::currentTime();
 
   if (expiration < now) {
     throw  InvalidArgumentException();
diff --git a/lib/cpp/src/concurrency/TimerManager.h b/lib/cpp/src/concurrency/TimerManager.h
index a150e8a..86900ce 100644
--- a/lib/cpp/src/concurrency/TimerManager.h
+++ b/lib/cpp/src/concurrency/TimerManager.h
@@ -57,7 +57,7 @@
    * @param task The task to execute
    * @param timeout Time in milliseconds to delay before executing task
    */
-  virtual void add(boost::shared_ptr<Runnable> task, long long timeout);
+  virtual void add(boost::shared_ptr<Runnable> task, int64_t timeout);
 
   /**
    * Adds a task to be executed at some time in the future by a worker thread.
@@ -93,7 +93,7 @@
   boost::shared_ptr<const ThreadFactory> threadFactory_;
   class Task;
   friend class Task;
-  std::multimap<long long, boost::shared_ptr<Task> > taskMap_;
+  std::multimap<int64_t, boost::shared_ptr<Task> > taskMap_;
   size_t taskCount_;
   Monitor monitor_;
   STATE state_;
diff --git a/lib/cpp/src/concurrency/Util.h b/lib/cpp/src/concurrency/Util.h
index fe12b49..8a1ead3 100644
--- a/lib/cpp/src/concurrency/Util.h
+++ b/lib/cpp/src/concurrency/Util.h
@@ -34,9 +34,9 @@
  */
 class Util {
 
-  static const long long NS_PER_S = 1000000000LL;
-  static const long long MS_PER_S = 1000LL;
-  static const long long NS_PER_MS = 1000000LL;
+  static const int64_t NS_PER_S = 1000000000LL;
+  static const int64_t MS_PER_S = 1000LL;
+  static const int64_t NS_PER_MS = 1000000LL;
 
  public:
 
@@ -46,7 +46,7 @@
    * @param struct timespec& result
    * @param time or duration in milliseconds
    */
-  static void toTimespec(struct timespec& result, long long value) {
+  static void toTimespec(struct timespec& result, int64_t value) {
     result.tv_sec = value / MS_PER_S; // ms to s   
     result.tv_nsec = (value % MS_PER_S) * NS_PER_MS; // ms to ns
   }
@@ -54,7 +54,7 @@
   /**
    * Converts timespec to milliseconds
    */
-  static const void toMilliseconds(long long& result, const struct timespec& value) {
+  static const void toMilliseconds(int64_t& result, const struct timespec& value) {
     result =
       (value.tv_sec * MS_PER_S) +
       (value.tv_nsec / NS_PER_MS) +
@@ -64,7 +64,7 @@
   /**
    * Get current time as milliseconds from epoch
    */
-  static const long long currentTime() {
+  static const int64_t currentTime() {
 #if defined(HAVE_CLOCK_GETTIME)
     struct timespec now;
     int ret = clock_gettime(CLOCK_REALTIME, &now);
@@ -78,7 +78,7 @@
     int ret = gettimeofday(&now, NULL);
     assert(ret == 0);
     return
-      (((long long)now.tv_sec) * MS_PER_S) +
+      (((int64_t)now.tv_sec) * MS_PER_S) +
       (now.tv_usec / MS_PER_S) +
       (now.tv_usec % MS_PER_S >= 500 ? 1 : 0);
 #endif // defined(HAVE_GETTIMEDAY)
diff --git a/lib/cpp/src/concurrency/test/Tests.cpp b/lib/cpp/src/concurrency/test/Tests.cpp
index f4b0b62..5fe4651 100644
--- a/lib/cpp/src/concurrency/test/Tests.cpp
+++ b/lib/cpp/src/concurrency/test/Tests.cpp
@@ -53,8 +53,8 @@
 
     std::cout << "\t\tUtil minimum time" << std::endl;
 
-    long long time00 = Util::currentTime();
-    long long time01 = Util::currentTime();
+    int64_t time00 = Util::currentTime();
+    int64_t time01 = Util::currentTime();
 
     std::cout << "\t\t\tMinimum time: " << time01 - time00 << "ms" << std::endl;
 
@@ -92,7 +92,7 @@
 
       size_t taskCount = 100000;
 
-      long long delay = 10LL;
+      int64_t delay = 10LL;
 
       std::cout << "\t\tThreadManager load test: worker count: " << workerCount << " task count: " << taskCount << " delay: " << delay << std::endl;
 
@@ -119,7 +119,7 @@
 
       size_t tasksPerWorker = 1000;
 
-      long long delay = 10LL;
+      int64_t delay = 10LL;
 
       for (size_t workerCount = minWorkerCount; workerCount < maxWorkerCount; workerCount*= 2) {
 
diff --git a/lib/cpp/src/concurrency/test/ThreadFactoryTests.h b/lib/cpp/src/concurrency/test/ThreadFactoryTests.h
index 2e2dbdd..f7d607a 100644
--- a/lib/cpp/src/concurrency/test/ThreadFactoryTests.h
+++ b/lib/cpp/src/concurrency/test/ThreadFactoryTests.h
@@ -228,11 +228,11 @@
 
   /** See how accurate monitor timeout is. */
 
-  bool monitorTimeoutTest(size_t count=1000, long long timeout=10) {
+  bool monitorTimeoutTest(size_t count=1000, int64_t timeout=10) {
 
     Monitor monitor;
 
-    long long startTime = Util::currentTime();
+    int64_t startTime = Util::currentTime();
 
     for (size_t ix = 0; ix < count; ix++) {
       {
@@ -244,7 +244,7 @@
       }
     }
 
-    long long endTime = Util::currentTime();
+    int64_t endTime = Util::currentTime();
 
     double error = ((endTime - startTime) - (count * timeout)) / (double)(count * timeout);
 
diff --git a/lib/cpp/src/concurrency/test/ThreadManagerTests.h b/lib/cpp/src/concurrency/test/ThreadManagerTests.h
index 89e6843..5f518ca 100644
--- a/lib/cpp/src/concurrency/test/ThreadManagerTests.h
+++ b/lib/cpp/src/concurrency/test/ThreadManagerTests.h
@@ -36,7 +36,7 @@
 
   public:
 
-    Task(Monitor& monitor, size_t& count, long long timeout) :
+    Task(Monitor& monitor, size_t& count, int64_t timeout) :
       _monitor(monitor),
       _count(count),
       _timeout(timeout),
@@ -78,9 +78,9 @@
 
     Monitor& _monitor;
     size_t& _count;
-    long long _timeout;
-    long long _startTime;
-    long long _endTime;
+    int64_t _timeout;
+    int64_t _startTime;
+    int64_t _endTime;
     bool _done;
     Monitor _sleep;
   };
@@ -90,7 +90,7 @@
    * completes. Verify that all tasks completed and that thread manager cleans
    * up properly on delete.
    */
-  bool loadTest(size_t count=100, long long timeout=100LL, size_t workerCount=4) {
+  bool loadTest(size_t count=100, int64_t timeout=100LL, size_t workerCount=4) {
 
     Monitor monitor;
 
@@ -113,7 +113,7 @@
       tasks.insert(shared_ptr<ThreadManagerTests::Task>(new ThreadManagerTests::Task(monitor, activeCount, timeout)));
     }
 
-    long long time00 = Util::currentTime();
+    int64_t time00 = Util::currentTime();
 
     for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) {
 
@@ -129,20 +129,20 @@
       }
     }
 
-    long long time01 = Util::currentTime();
+    int64_t time01 = Util::currentTime();
 
-    long long firstTime = 9223372036854775807LL;
-    long long lastTime = 0;
+    int64_t firstTime = 9223372036854775807LL;
+    int64_t lastTime = 0;
 
     double averageTime = 0;
-    long long minTime = 9223372036854775807LL;
-    long long maxTime = 0;
+    int64_t minTime = 9223372036854775807LL;
+    int64_t maxTime = 0;
 
     for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) {
 
       shared_ptr<ThreadManagerTests::Task> task = *ix;
 
-      long long delta = task->_endTime - task->_startTime;
+      int64_t delta = task->_endTime - task->_startTime;
 
       assert(delta > 0);
 
@@ -222,7 +222,7 @@
    * Block test.  Create pendingTaskCountMax tasks.  Verify that we block adding the
    * pendingTaskCountMax + 1th task.  Verify that we unblock when a task completes */
 
-  bool blockTest(long long timeout=100LL, size_t workerCount=2) {
+  bool blockTest(int64_t timeout=100LL, size_t workerCount=2) {
 
     bool success = false;
 
diff --git a/lib/cpp/src/concurrency/test/TimerManagerTests.h b/lib/cpp/src/concurrency/test/TimerManagerTests.h
index 0041d9c..e7948e4 100644
--- a/lib/cpp/src/concurrency/test/TimerManagerTests.h
+++ b/lib/cpp/src/concurrency/test/TimerManagerTests.h
@@ -31,7 +31,7 @@
   class Task: public Runnable {
    public:
     
-    Task(Monitor& monitor, long long timeout) : 
+    Task(Monitor& monitor, int64_t timeout) : 
       _timeout(timeout),
       _startTime(Util::currentTime()),
       _monitor(monitor),
@@ -46,7 +46,7 @@
 
       // Figure out error percentage
 
-      long long delta = _endTime - _startTime;
+      int64_t delta = _endTime - _startTime;
 
 
       delta = delta > _timeout ?  delta - _timeout : _timeout - delta;
@@ -66,9 +66,9 @@
       }
     }  
 
-    long long _timeout;
-    long long _startTime;
-    long long _endTime;
+    int64_t _timeout;
+    int64_t _startTime;
+    int64_t _endTime;
     Monitor& _monitor;
     bool _success;
     bool _done;
@@ -80,7 +80,7 @@
    * properly clean up itself and the remaining orphaned timeout task when the
    * manager goes out of scope and its destructor is called.
    */
-  bool test00(long long timeout=1000LL) {
+  bool test00(int64_t timeout=1000LL) {
 
     shared_ptr<TimerManagerTests::Task> orphanTask = shared_ptr<TimerManagerTests::Task>(new TimerManagerTests::Task(_monitor, 10 * timeout));
 
diff --git a/lib/cpp/src/processor/StatsProcessor.h b/lib/cpp/src/processor/StatsProcessor.h
index e080432..b1a4e63 100644
--- a/lib/cpp/src/processor/StatsProcessor.h
+++ b/lib/cpp/src/processor/StatsProcessor.h
@@ -74,7 +74,7 @@
     return true;
   }
 
-  const std::map<std::string, long long>& get_frequency_map() {
+  const std::map<std::string, int64_t>& get_frequency_map() {
     return frequency_map_;
   }
 
@@ -241,7 +241,7 @@
   }
 
   boost::shared_ptr<facebook::thrift::protocol::TProtocol> piprot_;
-  std::map<std::string, long long> frequency_map_;
+  std::map<std::string, int64_t> frequency_map_;
 
   bool print_;
   bool frequency_;
diff --git a/lib/cpp/src/server/TThreadPoolServer.cpp b/lib/cpp/src/server/TThreadPoolServer.cpp
index a271934..26eb373 100644
--- a/lib/cpp/src/server/TThreadPoolServer.cpp
+++ b/lib/cpp/src/server/TThreadPoolServer.cpp
@@ -156,7 +156,12 @@
 
 }
 
-long long TThreadPoolServer::timeout() const {return timeout_;}
-void TThreadPoolServer::timeout(long long value) {timeout_ = value;}
+int64_t TThreadPoolServer::getTimeout() const {
+  return timeout_;
+}
+
+void TThreadPoolServer::setTimeout(int64_t value) {
+  timeout_ = value;
+}
 
 }}} // facebook::thrift::server
diff --git a/lib/cpp/src/server/TThreadPoolServer.h b/lib/cpp/src/server/TThreadPoolServer.h
index b8b64f2..769db47 100644
--- a/lib/cpp/src/server/TThreadPoolServer.h
+++ b/lib/cpp/src/server/TThreadPoolServer.h
@@ -42,8 +42,9 @@
 
   virtual void serve();
 
-  virtual long long timeout() const;
-  virtual void timeout(long long value);
+  virtual int64_t getTimeout() const;
+
+  virtual void setTimeout(int64_t value);
   
   virtual void stop() {
     stop_ = true;
@@ -56,7 +57,7 @@
 
   volatile bool stop_;
 
-  volatile long long timeout_;
+  volatile int64_t timeout_;
   
 };
 
diff --git a/lib/cpp/src/transport/TFileTransport.cpp b/lib/cpp/src/transport/TFileTransport.cpp
index f368599..5039564 100644
--- a/lib/cpp/src/transport/TFileTransport.cpp
+++ b/lib/cpp/src/transport/TFileTransport.cpp
@@ -90,7 +90,7 @@
   openLogFile();
 }
 
-void TFileTransport::resetOutputFile(int fd, string filename, long long offset) {
+void TFileTransport::resetOutputFile(int fd, string filename, int64_t offset) {
   filename_ = filename;
   offset_ = offset;
 
@@ -326,13 +326,13 @@
         }
 
         // sanity check on event
-        if ( (maxEventSize_ > 0) && (outEvent->eventSize_ > maxEventSize_)) {
+        if ((maxEventSize_ > 0) && (outEvent->eventSize_ > maxEventSize_)) {
           T_ERROR("msg size is greater than max event size: %u > %u\n", outEvent->eventSize_, maxEventSize_);
           continue;
         }
 
         // If chunking is required, then make sure that msg does not cross chunk boundary
-        if( (outEvent->eventSize_ > 0) && (chunkSize_ != 0)) {
+        if ((outEvent->eventSize_ > 0) && (chunkSize_ != 0)) {
 
           // event size must be less than chunk size
           if(outEvent->eventSize_ > chunkSize_) {
@@ -341,11 +341,11 @@
             continue;
           }
 
-          long long chunk1 = offset_/chunkSize_;
-          long long chunk2 = (offset_ + outEvent->eventSize_ - 1)/chunkSize_;
+          int64_t chunk1 = offset_/chunkSize_;
+          int64_t chunk2 = (offset_ + outEvent->eventSize_ - 1)/chunkSize_;
           
           // if adding this event will cross a chunk boundary, pad the chunk with zeros
-          if(chunk1 != chunk2) {
+          if (chunk1 != chunk2) {
             // refetch the offset to keep in sync
             offset_ = lseek(fd_, 0, SEEK_CUR);
             int32_t padding = (int32_t)(chunk2*chunkSize_ - offset_);
diff --git a/lib/cpp/src/transport/TFileTransport.h b/lib/cpp/src/transport/TFileTransport.h
index 03b0cf3..2cb50b4 100644
--- a/lib/cpp/src/transport/TFileTransport.h
+++ b/lib/cpp/src/transport/TFileTransport.h
@@ -175,7 +175,7 @@
   uint32_t getCurChunk();
 
   // for changing the output file
-  void resetOutputFile(int fd, std::string filename, long long offset);
+  void resetOutputFile(int fd, std::string filename, int64_t offset);
 
   // Setter/Getter functions for user-controllable options
   void setReadBuffSize(uint32_t readBuffSize) {