From: Aditya Agarwal Date: Wed, 11 Apr 2007 00:13:09 +0000 (+0000) Subject: -- trying to make TFileTransport destructor quicker X-Git-Tag: 0.2.0~1377 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=8dc76e6a87be426d05331dc3fcbd4c947df04805;p=common%2Fthrift.git -- trying to make TFileTransport destructor quicker Summary: - setFlushMaxTimeUs to a lower value before trying to close the file Reviewed By: jwang git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665095 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/cpp/src/transport/TFileTransport.cpp b/lib/cpp/src/transport/TFileTransport.cpp index 5fb9ef3f..aafdc211 100644 --- a/lib/cpp/src/transport/TFileTransport.cpp +++ b/lib/cpp/src/transport/TFileTransport.cpp @@ -114,6 +114,9 @@ void TFileTransport::resetOutputFile(int fd, string filename, long long offset) TFileTransport::~TFileTransport() { // flush the buffer if a writer thread is active if (writerThreadId_ > 0) { + // reduce the flush timeout so that closing is quicker + setFlushMaxUs(300*1000); + // flush output buffer flush(); @@ -296,13 +299,15 @@ void TFileTransport::writerThread() { while(1) { // this will only be true when the destructor is being invoked - if(closing_) { + if(closing_) { // empty out both the buffers if (enqueueBuffer_->isEmpty() && dequeueBuffer_->isEmpty()) { if(-1 == ::close(fd_)) { perror("TFileTransport: error in close"); throw TTransportException("TFileTransport: error in file close"); } + // just be safe and sync to disk + fsync(fd_); fd_ = 0; pthread_exit(NULL); return;