MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

FCam::TSQueue< T > Class Template Reference

Basic thread-safe consumer/producer queue. More...

List of all members.

Public Member Functions

void  push (const T &val)
  Add a copy of item to the back of the queue.
void  pop ()
  Remove the frontmost element from the queue.
void  pushFront (const T &val)
  Add a copy of item to the front of the queue.
void  popBack ()
  Remove the backmost element from the queue.
T &  front ()
  Return a reference to the frontmost element of the queue.
T &  back ()
  Return a reference to the backmost element of the queue.
bool  empty () const
  Returns true if empty, false otherwise.
size_t  size () const
  Returns the number of items in the queue.
bool  wait (unsigned int timeout=0)
  Waits until there are entries in the queue.
pull ()
  Waits for the queue not to be empty, and then copies the frontmost item, then pops it from the queue and returns the element copy.
pullBack ()
  Pulls the backmost element off the queue.
bool  tryPull (T *)
  Atomically either dequeue an item, or fail to do so.
locking_iterator  begin ()
  Create an iterator referring to the front of the queue and locks the queue.
locking_iterator  end ()
  Create an iterator referring to the end of the queue and locks the queue.
bool  erase (TSQueue< T >::locking_iterator)
  Deletes an entry referred to by a locking_iterator.

Detailed Description

template<typename T>
class FCam::TSQueue< T >

Basic thread-safe consumer/producer queue.

Safe for multiple producers, but not for multiple consumers. The consumer will typically call wait(), pop(), front(), and pull, while producers mostly uses push().


Member Function Documentation

template<typename T >
void FCam::TSQueue< T >::push ( const T &  val  ) 

Add a copy of item to the back of the queue.

template<typename T >
void FCam::TSQueue< T >::pop (  ) 

Remove the frontmost element from the queue.

template<typename T >
void FCam::TSQueue< T >::pushFront ( const T &  val  ) 

Add a copy of item to the front of the queue.

template<typename T >
void FCam::TSQueue< T >::popBack (  ) 

Remove the backmost element from the queue.

template<typename T >
T & FCam::TSQueue< T >::front (  ) 

Return a reference to the frontmost element of the queue.

Behavior not defined if size() == 0

template<typename T >
T & FCam::TSQueue< T >::back (  ) 

Return a reference to the backmost element of the queue.

Behavior not defined if size() == 0

template<typename T >
bool FCam::TSQueue< T >::empty (  )  const

Returns true if empty, false otherwise.

template<typename T >
bool FCam::TSQueue< T >::wait ( unsigned int  timeout = 0  ) 

Waits until there are entries in the queue.

The optional timeout is in microseconds, zero means no timeout.

template<typename T >
T FCam::TSQueue< T >::pull (  ) 

Waits for the queue not to be empty, and then copies the frontmost item, then pops it from the queue and returns the element copy.

A convenience function, which is somewhat inefficient if T is a large class (so use it on pointer-containing queues, mostly). This is the only safe way for multiple consumers to use the queue.

template<typename T >
T FCam::TSQueue< T >::pullBack (  ) 

Pulls the backmost element off the queue.

template<typename T >
bool FCam::TSQueue< T >::tryPull ( T *  ptr  ) 

Atomically either dequeue an item, or fail to do so.

Does not block. Returns whether it succeeded.

template<typename T >
TSQueue< T >::locking_iterator FCam::TSQueue< T >::begin (  ) 

Create an iterator referring to the front of the queue and locks the queue.

Queue will remain locked until all the locked_iterators referring to it are destroyed.

template<typename T >
TSQueue< T >::locking_iterator FCam::TSQueue< T >::end (  ) 

Create an iterator referring to the end of the queue and locks the queue.

Queue will remain locked until all the iterators referring to it are destroyed.

template<typename T >
bool FCam::TSQueue< T >::erase ( TSQueue< T >::locking_iterator  li  ) 

Deletes an entry referred to by a locking_iterator.

Like a standard deque, if the entry erased is at the start or end of the queue, other iterators remain valid. Otherwise, all iterators and references are invalidated. Returns true if entry is successfully deleted. Failure can occur if some other thread(s) successfully reserved a queue entry/entries before the locking iterator claimed the queue.


Copyright (c) 2012, Nokia Corporation and/or its subsidiary(-ies). All rights reserved. See Copyright.
MeeGo 1.2 Harmattan API