From 9b82d275c627b1f4f64b5d3c82d54422fe6b5d5a Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Wed, 23 May 2007 05:16:07 +0000 Subject: [PATCH] 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 --- lib/cpp/src/concurrency/Monitor.cpp | 6 ++--- lib/cpp/src/concurrency/Monitor.h | 2 +- lib/cpp/src/concurrency/Thread.h | 2 +- lib/cpp/src/concurrency/ThreadManager.cpp | 4 +-- lib/cpp/src/concurrency/ThreadManager.h | 2 +- lib/cpp/src/concurrency/TimerManager.cpp | 16 ++++++------ lib/cpp/src/concurrency/TimerManager.h | 4 +-- lib/cpp/src/concurrency/Util.h | 14 +++++----- lib/cpp/src/concurrency/test/Tests.cpp | 8 +++--- .../src/concurrency/test/ThreadFactoryTests.h | 6 ++--- .../src/concurrency/test/ThreadManagerTests.h | 26 +++++++++---------- .../src/concurrency/test/TimerManagerTests.h | 12 ++++----- lib/cpp/src/processor/StatsProcessor.h | 4 +-- lib/cpp/src/server/TThreadPoolServer.cpp | 9 +++++-- lib/cpp/src/server/TThreadPoolServer.h | 7 ++--- lib/cpp/src/transport/TFileTransport.cpp | 12 ++++----- lib/cpp/src/transport/TFileTransport.h | 2 +- 17 files changed, 71 insertions(+), 65 deletions(-) diff --git a/lib/cpp/src/concurrency/Monitor.cpp b/lib/cpp/src/concurrency/Monitor.cpp index 8517c03c..1c826c80 100644 --- a/lib/cpp/src/concurrency/Monitor.cpp +++ b/lib/cpp/src/concurrency/Monitor.cpp @@ -51,7 +51,7 @@ class Monitor::Impl { 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 @@ class Monitor::Impl { 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::lock() const { impl_->lock(); } 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 b6a9f715..1eb36ebe 100644 --- a/lib/cpp/src/concurrency/Monitor.h +++ b/lib/cpp/src/concurrency/Monitor.h @@ -37,7 +37,7 @@ class Monitor { 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 e928fc44..3e5964fb 100644 --- a/lib/cpp/src/concurrency/Thread.h +++ b/lib/cpp/src/concurrency/Thread.h @@ -55,7 +55,7 @@ class Thread { 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 1260e5aa..56de4d00 100644 --- a/lib/cpp/src/concurrency/ThreadManager.cpp +++ b/lib/cpp/src/concurrency/ThreadManager.cpp @@ -100,7 +100,7 @@ class ThreadManager::Impl : public ThreadManager { bool canSleep(); - void add(shared_ptr value, long long timeout); + void add(shared_ptr value, int64_t timeout); void remove(shared_ptr task); @@ -412,7 +412,7 @@ void ThreadManager::Impl::removeWorker(size_t value) { return idMap_.find(id) == idMap_.end(); } - void ThreadManager::Impl::add(shared_ptr value, long long timeout) { + void ThreadManager::Impl::add(shared_ptr 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 19f77cca..4c564615 100644 --- a/lib/cpp/src/concurrency/ThreadManager.h +++ b/lib/cpp/src/concurrency/ThreadManager.h @@ -127,7 +127,7 @@ class ThreadManager { * * @throws TooManyPendingTasksException Pending task count exceeds max pending task count */ - virtual void add(boost::shared_ptrtask, long long timeout=0LL) = 0; + virtual void add(boost::shared_ptrtask, 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 07f05adc..2134e37f 100644 --- a/lib/cpp/src/concurrency/TimerManager.cpp +++ b/lib/cpp/src/concurrency/TimerManager.cpp @@ -16,7 +16,7 @@ namespace facebook { namespace thrift { namespace concurrency { using boost::shared_ptr; -typedef std::multimap >::iterator task_iterator; +typedef std::multimap >::iterator task_iterator; typedef std::pair task_range; /** @@ -89,10 +89,10 @@ class TimerManager::Dispatcher: public Runnable { { 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 @@ size_t TimerManager::taskCount() const { return taskCount_; } -void TimerManager::add(shared_ptr task, long long timeout) { - long long now = Util::currentTime(); +void TimerManager::add(shared_ptr task, int64_t timeout) { + int64_t now = Util::currentTime(); timeout += now; { @@ -240,7 +240,7 @@ void TimerManager::add(shared_ptr task, long long timeout) { } taskCount_++; - taskMap_.insert(std::pair >(timeout, shared_ptr(new Task(task)))); + taskMap_.insert(std::pair >(timeout, shared_ptr(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 task, long long timeout) { void TimerManager::add(shared_ptr 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 a150e8a1..86900ce5 100644 --- a/lib/cpp/src/concurrency/TimerManager.h +++ b/lib/cpp/src/concurrency/TimerManager.h @@ -57,7 +57,7 @@ class TimerManager { * @param task The task to execute * @param timeout Time in milliseconds to delay before executing task */ - virtual void add(boost::shared_ptr task, long long timeout); + virtual void add(boost::shared_ptr task, int64_t timeout); /** * Adds a task to be executed at some time in the future by a worker thread. @@ -93,7 +93,7 @@ class TimerManager { boost::shared_ptr threadFactory_; class Task; friend class Task; - std::multimap > taskMap_; + std::multimap > 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 fe12b497..8a1ead31 100644 --- a/lib/cpp/src/concurrency/Util.h +++ b/lib/cpp/src/concurrency/Util.h @@ -34,9 +34,9 @@ namespace facebook { namespace thrift { namespace concurrency { */ 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 @@ class Util { * @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 @@ class Util { /** * 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 @@ class Util { /** * 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 @@ class Util { 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 f4b0b627..5fe46513 100644 --- a/lib/cpp/src/concurrency/test/Tests.cpp +++ b/lib/cpp/src/concurrency/test/Tests.cpp @@ -53,8 +53,8 @@ int main(int argc, char** argv) { 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 @@ int main(int argc, char** argv) { 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 @@ int main(int argc, char** argv) { 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 2e2dbddd..f7d607a3 100644 --- a/lib/cpp/src/concurrency/test/ThreadFactoryTests.h +++ b/lib/cpp/src/concurrency/test/ThreadFactoryTests.h @@ -228,11 +228,11 @@ public: /** 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 @@ public: } } - 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 89e68438..5f518cae 100644 --- a/lib/cpp/src/concurrency/test/ThreadManagerTests.h +++ b/lib/cpp/src/concurrency/test/ThreadManagerTests.h @@ -36,7 +36,7 @@ public: 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 @@ public: 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 @@ public: * 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 @@ public: tasks.insert(shared_ptr(new ThreadManagerTests::Task(monitor, activeCount, timeout))); } - long long time00 = Util::currentTime(); + int64_t time00 = Util::currentTime(); for (std::set >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) { @@ -129,20 +129,20 @@ public: } } - 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 >::iterator ix = tasks.begin(); ix != tasks.end(); ix++) { shared_ptr task = *ix; - long long delta = task->_endTime - task->_startTime; + int64_t delta = task->_endTime - task->_startTime; assert(delta > 0); @@ -222,7 +222,7 @@ public: * 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 0041d9cb..e7948e43 100644 --- a/lib/cpp/src/concurrency/test/TimerManagerTests.h +++ b/lib/cpp/src/concurrency/test/TimerManagerTests.h @@ -31,7 +31,7 @@ class TimerManagerTests { 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 @@ class TimerManagerTests { // 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 @@ class TimerManagerTests { } } - 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 @@ class TimerManagerTests { * 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 orphanTask = shared_ptr(new TimerManagerTests::Task(_monitor, 10 * timeout)); diff --git a/lib/cpp/src/processor/StatsProcessor.h b/lib/cpp/src/processor/StatsProcessor.h index e0804329..b1a4e63a 100644 --- a/lib/cpp/src/processor/StatsProcessor.h +++ b/lib/cpp/src/processor/StatsProcessor.h @@ -74,7 +74,7 @@ public: return true; } - const std::map& get_frequency_map() { + const std::map& get_frequency_map() { return frequency_map_; } @@ -241,7 +241,7 @@ protected: } boost::shared_ptr piprot_; - std::map frequency_map_; + std::map frequency_map_; bool print_; bool frequency_; diff --git a/lib/cpp/src/server/TThreadPoolServer.cpp b/lib/cpp/src/server/TThreadPoolServer.cpp index a2719349..26eb373d 100644 --- a/lib/cpp/src/server/TThreadPoolServer.cpp +++ b/lib/cpp/src/server/TThreadPoolServer.cpp @@ -156,7 +156,12 @@ void TThreadPoolServer::serve() { } -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 b8b64f22..769db47b 100644 --- a/lib/cpp/src/server/TThreadPoolServer.h +++ b/lib/cpp/src/server/TThreadPoolServer.h @@ -42,8 +42,9 @@ class TThreadPoolServer : public TServer { 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 @@ class TThreadPoolServer : public TServer { 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 f3685999..5039564f 100644 --- a/lib/cpp/src/transport/TFileTransport.cpp +++ b/lib/cpp/src/transport/TFileTransport.cpp @@ -90,7 +90,7 @@ TFileTransport::TFileTransport(string path, bool readOnly) 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 @@ void TFileTransport::writerThread() { } // 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 @@ void TFileTransport::writerThread() { 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 03b0cf3e..2cb50b49 100644 --- a/lib/cpp/src/transport/TFileTransport.h +++ b/lib/cpp/src/transport/TFileTransport.h @@ -175,7 +175,7 @@ class TFileTransport : public TFileReaderTransport, 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) { -- 2.17.1