THRIFT-926. cpp: Fix destructor behavior of TFileTransport
authorDavid Reiss <dreiss@apache.org>
Wed, 6 Oct 2010 17:10:30 +0000 (17:10 +0000)
committerDavid Reiss <dreiss@apache.org>
Wed, 6 Oct 2010 17:10:30 +0000 (17:10 +0000)
commit709b69f14c7c69b83e1752212bf51b4da67db834
treec9f04bd0d15b25832de0b8417d62eda12644d989
parent0e0eb354527cecdc22d1c0e6ecba06d7f747e728
THRIFT-926. cpp: Fix destructor behavior of TFileTransport

Set closing_ to true before we wake up the writer thread in the
destructor.  This way the writer thread flushes the data and exits when
it is woken up.

Previously the writer thread could end up going through 2 full timeout
cycles before exiting.  The writer thread could wake up, notice it has
nothing to do since closing_ is not set, and immediately go back to
sleep.  The destructor would then proceed to call flush(), which would
wait for the writer thread to wake up (1 full time out) and clear the
forceFlush_ flag.  After flush returns, the destructor would set
closing_.  It could take the writer thread another full timeout to wake
up again and process this flag.

There were also some points where the worker threads would detect the
closing_ state in their loops and automatically close the file, but did
not zero out the file descriptor, then the destructer attempted to close
the same file.  Fix by simply zeroing out the fd_ at these points.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005154 13f79535-47bb-0310-9956-ffa450edef68
lib/cpp/src/transport/TFileTransport.cpp
lib/cpp/test/Makefile.am
lib/cpp/test/TFileTransportTest.cpp [new file with mode: 0644]