TPIE

2362a60
thread.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2013, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef TPIE_COMPRESSED_THREAD_H
21 #define TPIE_COMPRESSED_THREAD_H
22 
26 
27 #include <thread>
28 #include <mutex>
29 #include <memory>
30 #include <tpie/array.h>
32 #include <tpie/file_accessor/byte_stream_accessor.h>
34 #include <tpie/compressed/scheme.h>
35 
36 namespace tpie {
37 
39  class impl;
40  impl * pimpl;
41 
42 public:
43  typedef std::shared_ptr<compressor_buffer> buffer_t;
45  typedef std::mutex mutex_t;
46 
47  static stream_size_type subtract_block_header(stream_size_type dataOffset);
48 
51 
52  mutex_t & mutex();
53 
54  // Locking: Caller must lock the thread (with a compressor_thread_lock).
55  void request(compressor_request & r);
56 
57  void wait_for_request_done(compressor_thread_lock & l);
58 
59  void run();
60 
61  void stop(compressor_thread_lock & lock);
62 
63  void set_preferred_compression(compressor_thread_lock &, compression_scheme::type);
64 };
65 
67 public:
68  typedef std::unique_lock<compressor_thread::mutex_t> lock_t;
69 
71  : t1(ptime::now())
72  , m_lock(c.mutex())
73  , t2(ptime::now())
74  {
75  }
76 
78  ptime t3 = ptime::now();
79  // Time blocked
80  increment_user(0, (stream_size_type)(ptime::seconds(t1, t2)*1000000));
81  // Time held
82  increment_user(1, (stream_size_type)(ptime::seconds(t2, t3)*1000000));
83  }
84 
85  lock_t & get_lock() {
86  return m_lock;
87  }
88 
89 private:
90  ptime t1;
91  lock_t m_lock;
92  ptime t2;
93 };
94 
95 } // namespace tpie
96 
97 #endif // TPIE_COMPRESSED_THREAD_H
Declare default file accessor.
Generic internal array with known memory requirements.
Useful compressed stream predeclarations.
Tagged union containing either a read_request or a write_request.
Definition: request.h:346
Compression scheme virtual interface.