TPIE

11a2c2d
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 <tpie/tpie_export.h>
28 #include <thread>
29 #include <mutex>
30 #include <memory>
31 #include <tpie/array.h>
33 #include <tpie/file_accessor/byte_stream_accessor.h>
35 #include <tpie/compressed/scheme.h>
36 
37 namespace tpie {
38 
39 class TPIE_EXPORT compressor_thread {
40  class impl;
41  impl * pimpl;
42 
43 public:
44  typedef std::shared_ptr<compressor_buffer> buffer_t;
46  typedef std::mutex mutex_t;
47 
48  static stream_size_type subtract_block_header(stream_size_type dataOffset);
49 
52 
53  mutex_t & mutex();
54 
55  // Locking: Caller must lock the thread (with a compressor_thread_lock).
56  void request(compressor_request & r);
57 
58  void wait_for_request_done(compressor_thread_lock & l);
59 
60  void run();
61 
62  void stop(compressor_thread_lock & lock);
63 
64  void set_preferred_compression(compressor_thread_lock &, compression_scheme::type);
65 };
66 
67 class TPIE_EXPORT compressor_thread_lock {
68 public:
69  typedef std::unique_lock<compressor_thread::mutex_t> lock_t;
70 
72  : t1(ptime::now())
73  , m_lock(c.mutex())
74  , t2(ptime::now())
75  {
76  }
77 
79  ptime t3 = ptime::now();
80  // Time blocked
81  increment_user(0, (stream_size_type)(ptime::seconds(t1, t2)*1000000));
82  // Time held
83  increment_user(1, (stream_size_type)(ptime::seconds(t2, t3)*1000000));
84  }
85 
86  lock_t & get_lock() {
87  return m_lock;
88  }
89 
90 private:
91  ptime t1;
92  lock_t m_lock;
93  ptime t2;
94 };
95 
96 } // namespace tpie
97 
98 #endif // TPIE_COMPRESSED_THREAD_H
tpie::ptime
Definition: stats.h:69
file_accessor.h
scheme.h
array.h
tpie::compressor_thread_lock
Definition: thread.h:67
tpie::file_accessor::byte_stream_accessor
Definition: byte_stream_accessor.h:31
tpie::compressor_thread
Definition: thread.h:39
predeclare.h
tpie::compressor_request
Tagged union containing either a read_request or a write_request.
Definition: request.h:346
tpie
Definition: access_type.h:26