diff options
| author | Wu, Ke <wuke@cs.umd.edu> | 2014-12-17 16:15:13 -0500 | 
|---|---|---|
| committer | Wu, Ke <wuke@cs.umd.edu> | 2014-12-17 16:15:13 -0500 | 
| commit | 6829a0bc624b02ebefc79f8cf9ec89d7d64a7c30 (patch) | |
| tree | 125dfb20f73342873476c793995397b26fd202dd /klm/util/stream/io.hh | |
| parent | b455a108a21f4ba5a58ab1bc53a8d2bf4d829067 (diff) | |
| parent | 7468e8d85e99b4619442c7afaf4a0d92870111bb (diff) | |
Merge branch 'const_reorder_2' into softsyn_2
Diffstat (limited to 'klm/util/stream/io.hh')
| -rw-r--r-- | klm/util/stream/io.hh | 21 | 
1 files changed, 16 insertions, 5 deletions
| diff --git a/klm/util/stream/io.hh b/klm/util/stream/io.hh index 934b6b3f..8dae2cbf 100644 --- a/klm/util/stream/io.hh +++ b/klm/util/stream/io.hh @@ -1,5 +1,5 @@ -#ifndef UTIL_STREAM_IO__ -#define UTIL_STREAM_IO__ +#ifndef UTIL_STREAM_IO_H +#define UTIL_STREAM_IO_H  #include "util/exception.hh"  #include "util/file.hh" @@ -41,6 +41,8 @@ class Write {      int file_;  }; +// It's a common case that stuff is written and then recycled.  So rather than +// spawn another thread to Recycle, this combines the two roles.  class WriteAndRecycle {    public:      explicit WriteAndRecycle(int fd) : file_(fd) {} @@ -49,14 +51,23 @@ class WriteAndRecycle {      int file_;  }; +class PWriteAndRecycle { +  public: +    explicit PWriteAndRecycle(int fd) : file_(fd) {} +    void Run(const ChainPosition &position); +  private: +    int file_; +}; + +  // Reuse the same file over and over again to buffer output.    class FileBuffer {    public:      explicit FileBuffer(int fd) : file_(fd) {} -    WriteAndRecycle Sink() const { +    PWriteAndRecycle Sink() const {        util::SeekOrThrow(file_.get(), 0); -      return WriteAndRecycle(file_.get()); +      return PWriteAndRecycle(file_.get());      }      PRead Source() const { @@ -73,4 +84,4 @@ class FileBuffer {  } // namespace stream  } // namespace util -#endif // UTIL_STREAM_IO__ +#endif // UTIL_STREAM_IO_H | 
