kwave  18.07.70
Kwave::Stripe::StripeStorage Class Reference
Inheritance diagram for Kwave::Stripe::StripeStorage:
Inheritance graph
Collaboration diagram for Kwave::Stripe::StripeStorage:
Collaboration graph

Public Member Functions

 StripeStorage ()
 
 StripeStorage (const StripeStorage &other)
 
virtual ~StripeStorage ()
 
sample_tmap ()
 
void unmap ()
 
int mapCount () const
 

Public Attributes

sample_index_t m_start
 
unsigned int m_length
 
Kwave::Handle m_storage
 

Private Attributes

QMutex m_lock
 
int m_map_count
 
sample_tm_mapped_storage
 

Detailed Description

Definition at line 308 of file Stripe.h.

Constructor & Destructor Documentation

◆ StripeStorage() [1/2]

Kwave::Stripe::StripeStorage::StripeStorage ( )

default constructor

Definition at line 94 of file Stripe.cpp.

95  :QSharedData(), m_start(0), m_length(0), m_storage(0), m_lock(),
96  m_map_count(0), m_mapped_storage(Q_NULLPTR)
97 {
98 }
sample_t * m_mapped_storage
Definition: Stripe.h:349
Kwave::Handle m_storage
Definition: Stripe.h:338
sample_index_t m_start
Definition: Stripe.h:332

◆ StripeStorage() [2/2]

Kwave::Stripe::StripeStorage::StripeStorage ( const StripeStorage other)

copy constructor

Definition at line 101 of file Stripe.cpp.

References Kwave::MemoryManager::allocate(), Kwave::MemoryManager::instance(), m_length, m_storage, Kwave::MemoryManager::map(), Kwave::Stripe::read(), Kwave::MemoryManager::readFrom(), Kwave::toUint(), Kwave::MemoryManager::unmap(), and Kwave::MemoryManager::writeTo().

102  :QSharedData(other), m_start(other.m_start), m_length(other.m_length),
103  m_storage(0), m_lock(), m_map_count(0), m_mapped_storage(Q_NULLPTR)
104 {
105 // qDebug("StripeStorage(%p) - DEEP COPY %u,%u from %p",
106 // static_cast<void *>(this),
107 // m_start, m_length,
108 // static_cast<const void *>(&other)
109 // );
110 
111  if (other.m_storage) {
112  // allocate memory for the copy
114  m_storage = mem.allocate(m_length * sizeof(sample_t));
115  if (!m_storage) {
116  // allocation failed
117  qWarning("StripeStorage: DEEP COPY (%u) FAILED - OOM!", m_length);
118  m_length = 0;
119  return;
120  }
121 
122  // copy the data from the original
123  Q_ASSERT(m_storage);
124  void *original = mem.map(other.m_storage);
125  if (original) {
126  mem.writeTo(m_storage, 0, original, m_length * sizeof(sample_t));
127  mem.unmap(other.m_storage);
128  } else {
129  qWarning("StripeStorage: DEEP COPY (%u) MMAP FAILED - "
130  "FALLING BACK TO SLOW COPY!", m_length);
131  // fall back to slow copy algorithm
132  char buf[256]; // use a small buffer on the stack
133  unsigned int remaining = m_length;
134  unsigned int ofs = 0;
135 
136  while (remaining) {
137  unsigned int len = qMin(remaining, Kwave::toUint(sizeof(buf)));
138  unsigned int read = mem.readFrom(other.m_storage, ofs,
139  &buf[0], len);
140  Q_ASSERT(read == len);
141  if (read != len) break;
142  unsigned int written = mem.writeTo(m_storage, ofs,
143  &buf[0], len);
144  Q_ASSERT(written == len);
145  if (written != len) break;
146  remaining -= len;
147  ofs += len;
148  }
149  if (remaining) {
150  qWarning("StripeStorage: DEEP COPY (%u) FAILED - DATA LOST!",
151  m_length);
152  }
153  }
154  }
155 }
int readFrom(Kwave::Handle handle, unsigned int offset, void *buffer, unsigned int length) Q_DECL_EXPORT
unsigned int read(Kwave::SampleArray &buffer, unsigned int dstoff, unsigned int offset, unsigned int length)
Definition: Stripe.cpp:502
static MemoryManager & instance() Q_DECL_EXPORT
sample_t * m_mapped_storage
Definition: Stripe.h:349
Kwave::Handle m_storage
Definition: Stripe.h:338
void unmap(Kwave::Handle handle) Q_DECL_EXPORT
void * map(Kwave::Handle handle) Q_DECL_EXPORT
int writeTo(Kwave::Handle handle, unsigned int offset, const void *buffer, unsigned int length) Q_DECL_EXPORT
Kwave::Handle allocate(size_t size) Q_DECL_EXPORT
unsigned int toUint(T x)
Definition: Utils.h:109
sample_index_t m_start
Definition: Stripe.h:332
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:

◆ ~StripeStorage()

Kwave::Stripe::StripeStorage::~StripeStorage ( )
virtual

destructor

Definition at line 192 of file Stripe.cpp.

References Kwave::MemoryManager::free(), Kwave::MemoryManager::instance(), m_map_count, m_mapped_storage, and m_storage.

193 {
194  Q_ASSERT(!m_map_count);
195  Q_ASSERT(!m_mapped_storage);
196  if (m_storage) {
198  mem.free(m_storage);
199  }
200 }
static MemoryManager & instance() Q_DECL_EXPORT
sample_t * m_mapped_storage
Definition: Stripe.h:349
Kwave::Handle m_storage
Definition: Stripe.h:338
void free(Kwave::Handle &handle) Q_DECL_EXPORT
Here is the call graph for this function:

Member Function Documentation

◆ map()

sample_t * Kwave::Stripe::StripeStorage::map ( )

maps the storage into memory

Definition at line 158 of file Stripe.cpp.

References Kwave::MemoryManager::instance(), m_lock, m_map_count, m_mapped_storage, m_storage, and Kwave::MemoryManager::map().

159 {
160  QMutexLocker lock(&m_lock);
161 
162  if (!m_storage) return Q_NULLPTR;
163 
164  if (!m_map_count) {
166  m_mapped_storage = reinterpret_cast<sample_t *>(
167  mem.map(m_storage));
168  }
169 
171 
172  return m_mapped_storage;
173 }
static MemoryManager & instance() Q_DECL_EXPORT
sample_t * m_mapped_storage
Definition: Stripe.h:349
Kwave::Handle m_storage
Definition: Stripe.h:338
void * map(Kwave::Handle handle) Q_DECL_EXPORT
qint32 sample_t
Definition: Sample.h:37
Here is the call graph for this function:

◆ mapCount()

int Kwave::Stripe::StripeStorage::mapCount ( ) const
inline

returns the map count

Definition at line 327 of file Stripe.h.

327 { return m_map_count; }

◆ unmap()

void Kwave::Stripe::StripeStorage::unmap ( )

unmaps the storage from memory

Definition at line 176 of file Stripe.cpp.

References Kwave::MemoryManager::instance(), m_lock, m_map_count, m_mapped_storage, m_storage, and Kwave::MemoryManager::unmap().

177 {
178  QMutexLocker lock(&m_lock);
179 
180  Q_ASSERT(m_map_count);
181  if (!m_map_count) return;
182 
183  m_map_count--;
184  if (!m_map_count) {
186  mem.unmap(m_storage);
187  m_mapped_storage = Q_NULLPTR;
188  }
189 }
static MemoryManager & instance() Q_DECL_EXPORT
sample_t * m_mapped_storage
Definition: Stripe.h:349
Kwave::Handle m_storage
Definition: Stripe.h:338
void unmap(Kwave::Handle handle) Q_DECL_EXPORT
Here is the call graph for this function:

Member Data Documentation

◆ m_length

unsigned int Kwave::Stripe::StripeStorage::m_length

number of samples

Definition at line 335 of file Stripe.h.

Referenced by StripeStorage().

◆ m_lock

QMutex Kwave::Stripe::StripeStorage::m_lock
private

mutex for locking map/unmap

Definition at line 343 of file Stripe.h.

Referenced by map(), and unmap().

◆ m_map_count

int Kwave::Stripe::StripeStorage::m_map_count
private

usage count of mapped storage

Definition at line 346 of file Stripe.h.

Referenced by map(), unmap(), and ~StripeStorage().

◆ m_mapped_storage

sample_t* Kwave::Stripe::StripeStorage::m_mapped_storage
private

mapped storage

Definition at line 349 of file Stripe.h.

Referenced by map(), unmap(), and ~StripeStorage().

◆ m_start

sample_index_t Kwave::Stripe::StripeStorage::m_start

start position within the track

Definition at line 332 of file Stripe.h.

◆ m_storage

Kwave::Handle Kwave::Stripe::StripeStorage::m_storage

pointer/handle to a storage object

Definition at line 338 of file Stripe.h.

Referenced by map(), StripeStorage(), unmap(), and ~StripeStorage().


The documentation for this class was generated from the following files: