A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/classCSyncQueue.html below:

NCBI C++ ToolKit: CSyncQueue< Type, Container, Traits

Search Toolkit Book for CSyncQueue

Thread-safe queue object with a blocking mechanism. More...

#include <util/sync_queue.hpp>

  CSyncQueue (const TThisType &)   TThisTypeoperator= (const TThisType &)   bool  x_Lock (const CTimeSpan *timeout=NULL) const   Lock access to the queue. More...
  void  x_Unlock (void) const   Unlock access to queue. More...
  void  x_DoubleLock (TAutoLock *my_lock, TAutoLock *other_lock, const TThisType &other_obj) const   Lock two queues simultaneously to guard against otherwise possible inter-thread dead-lock. More...
  void  x_LockAndWait (TAutoLock *lock, const CTimeSpan *full_tmo, const CTimeSpan *service_tmo, TCheckFunc func_to_check, CSemaphore *trigger, CAtomicCounter *counter, TErrorThrower throw_error) const   Lock the queue and wait until the condition function returns FALSE. More...
  void  x_LockAndWaitWhileFull (TAutoLock *lock, const CTimeSpan *full_tmo, const CTimeSpan *service_tmo) const   Lock the queue and wait until it has room for more elements. More...
  void  x_LockAndWaitWhileEmpty (TAutoLock *lock, const CTimeSpan *full_tmo, const CTimeSpan *service_tmo) const   Lock the queue and wait until it has at least one element. More...
  void  x_GuardedLock (const CTimeSpan *timeout=NULL) const   Lock the queue by an access guard. More...
  void  x_GuardedUnlock (void) const   Unlock the queue by an access guard. More...
  bool  x_IsGuarded (void) const   Check if this queue is locked by some access guard in current thread. More...
  void  x_Push_NonBlocking (const TValue &elem)   Add new element to the end of queue – without locking and blocking. More...
  TValue  x_Pop_NonBlocking (void)   Get first element from the queue – without locking and blocking. More...
  void  x_Clear_NonBlocking (void)   Clear the queue – without locking and blocking. More...
  TNativeIter  x_Begin (void)   Get iterator pointing to the start of underlying container. More...
  TNativeConstIter  x_Begin (void) const   Get constant iterator pointing to the start of underlying container. More...
  TNativeIter  x_End (void)   Get iterator pointing to the end of underlying container. More...
  TNativeConstIter  x_End (void) const   Get constant iterator pointing to the end of underlying container. More...
  TNativeIter  x_Erase (TNativeIter iter)   Erase one element from the underlying container. More...
  TNativeIter  x_Erase (TNativeIter from_iter, TNativeIter to_iter)   Erase several elements from the underlying container. More...
  class  CSyncQueue_ConstAccessGuard< Type, Container, Traits >   class  CSyncQueue_AccessGuard< Type, Container, Traits >   class  CSyncQueue_InternalAutoLock< Type, Container, Traits >   class  CSyncQueue_I< Type, Container, TNativeIter, Traits >   class  CSyncQueue_I< Type, Container, TNativeConstIter, Traits >   template<class Type, class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>
class CSyncQueue< Type, Container, Traits >

Thread-safe queue object with a blocking mechanism.

An attempt to pop from empty queue or push to full queue function call waits for normal operation finishing. Queue can also be locked for a long time for some bulk operations. This can be achieved by CSyncQueue::T*AccessGuard classes.

CSyncQueue can be used in single threaded applications or multithreaded applications with C++ Toolkit threads as well as with any kind of native threads. In case of multithreaded applications a CSyncQueue object could be used only from one thread or from many threads. To distinguish how the object is accessed the template supports the 'Traits' parameter. The traits in particular report if the the queue is accessed from many threads (see the CSyncQueue_DefaultTraits::IsUsedConcurrently() description for the details of what could happen if the IsUsedConcurrently() is not implemented properly). The default traits suppose that the C++ Toolkit CThread class is used to create threads.

There is a difference as well of how the timeouts are handled depending on what threads are used in the application if so: the C++ Toolkit threads or some other threads. The only difference between these cases is passing NULL as timeout in methods Push(), Pop() and Clear(). When C++ Toolkit CThread class is used to create application's threads then NULL value will mean indefinite timeout (as stated in comments to those methods). But if all threads in the application (if any) were created by some native function without using CThread class then NULL value will mean 0 timeout and it's impossible to set indefinite timeout in this case.

Full description and examples of using look here: Using CSyncQueue class.

Parameters
Type Type of elements saved in queue Container Type of underlying container used in queue. To be applicable for using in CSyncQueue container must have methods push_back(), front() and pop_front(). For other containers you need to implement an adaptor to use it in CSyncQueue. For STL set, multiset and priority_queue classes adaptors implemented further in this file. Traits Traits which are used to alter internal behavior. Currently it only affects the way how the number of running threads is detected.
See also
CSyncQueue_DefaultTraits

Definition at line 216 of file sync_queue.hpp.

◆ TAccessGuard

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Type of access guardian for non-constant queue.

Definition at line 331 of file sync_queue.hpp.

◆ TAutoLock

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Short name of auto-lock for this queue type.

For internal use only.

Definition at line 353 of file sync_queue.hpp.

◆ TCheckFunc

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ TConstAccessGuard

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Type of access guardian for constant queue.

Definition at line 329 of file sync_queue.hpp.

◆ TConstIterator

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ TErrorThrower

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

typedef void(* CSyncQueue< Type, Container, Traits >::TErrorThrower) (void) private ◆ TIterator

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ TNativeConstIter

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ TNativeIter

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ TSize

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ TThisType

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ TValue

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ anonymous enum

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Enumerator kThreadSystemID_None 

Value of thread system id that cannot be equal to any thread's id.

Definition at line 504 of file sync_queue.hpp.

◆ CSyncQueue() [1/2]

template<class Type , class Container , class Traits >

Construct queue.

Parameters
max_size Maximum size of the queue. Must be greater than zero.

Definition at line 1228 of file sync_queue.hpp.

References NCBI_THROW.

◆ CSyncQueue() [2/2]

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ Clear()

template<class Type , class Container , class Traits >

◆ CopyTo()

template<class Type , class Container , class Traits >

Copy (add) all queue elements to another queue.

Note
This method will not copy to queue blocked by some access guardian because this pattern can lead to a deadlock in some situations.
Exceptions
CSyncQueueException Does nothing and throws with "eNoRoom" err.code if there is not enough room in the destination queue. Throws with "eGuardedCopy" if other queue is guarded in the running thread with some access guardian.
Parameters
other Another queue to which all elements will be copied

Definition at line 1613 of file sync_queue.hpp.

References copy(), CSyncQueue_InternalAutoLock< Type, Container, Traits >::Lock(), CSyncQueue< Type, Container, Traits >::m_MaxSize, CSyncQueue< Type, Container, Traits >::m_Size, CSyncQueue< Type, Container, Traits >::m_Store, NCBI_THROW, ThrowSyncQueueTimeout(), and CSyncQueue< Type, Container, Traits >::x_IsGuarded().

◆ GetMaxSize()

template<class Type , class Container , class Traits >

Get the maximum # of elements allowed to be kept in the queue.

Note
This call always returns immediately, without any blocking

Definition at line 1264 of file sync_queue.hpp.

◆ GetSize()

template<class Type , class Container , class Traits >

◆ IsEmpty()

template<class Type , class Container , class Traits >

◆ IsFull()

template<class Type , class Container , class Traits >

Check if the queue is full (has maxSize elements)

Note
This call always returns immediately, without any blocking

Definition at line 1280 of file sync_queue.hpp.

◆ operator=()

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ Pop() [1/2]

template<class Type , class Container , class Traits >

Retrieve an element from the queue.

Note
This call will block if the queue is empty or if there are competing operations by other threads
Parameters
full_tmo Maximum time period to wait on this call (including waiting for other threads to unlock the queue and waiting until there is any element in the queue to retrieve); NULL to wait infinitely. If the timeout is exceeded, then throw CSyncQueueException. service_tmo Maximum time period to wait for other threads to unlock the queue; NULL to wait infinitely. If the timeout is exceeded, then throw CSyncQueueException.

Definition at line 1573 of file sync_queue.hpp.

◆ Pop() [2/2]

template<class Type , class Container , class Traits >

◆ Push() [1/2]

template<class Type , class Container , class Traits >

Add new element to the end of queue.

Note
This call will block if the queue is full or if there are competing operations by other threads
Parameters
elem Element to push full_tmo Maximum time period to wait on this call (including waiting for other threads to unlock the queue and waiting until there is space in the queue to add element to); NULL to wait infinitely. If the timeout is exceeded, then throw CSyncQueueException. service_tmo Maximum time period to wait for other threads to unlock the queue; NULL to wait infinitely. If the timeout is exceeded, then throw CSyncQueueException.

Definition at line 1547 of file sync_queue.hpp.

◆ Push() [2/2]

template<class Type , class Container , class Traits >

Add new element to the end of queue.

Note
This call will block if the queue is full or if there are competing operations by other threads
Parameters
elem Element to push timeout Maximum time period to wait on this call; NULL to wait infinitely. If the timeout is exceeded, then throw CSyncQueueException.

Definition at line 1563 of file sync_queue.hpp.

Referenced by CPrefetchThreadOld::AddRequest(), CThreadPool_Impl::AddTask(), CAppTaskService::AddTask(), CMergeTreeThread::Main(), CThreadPool_Impl::RequestExclusiveExecution(), CMergeyApp::Run(), CSQLITE3_Cache::CWriterThread::Stop(), CSQLITE3_Cache::Store(), CPrefetchThreadOld::Terminate(), and CAppTaskService::x_OnWakeUpSignal().

◆ x_Begin() [1/2]

template<class Type , class Container , class Traits >

◆ x_Begin() [2/2]

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Get constant iterator pointing to the start of underlying container.

◆ x_Clear_NonBlocking()

template<class Type , class Container , class Traits >

void CSyncQueue< Type, Container, Traits >::x_Clear_NonBlocking ( void  ) inlineprivate

Clear the queue – without locking and blocking.

Definition at line 1538 of file sync_queue.hpp.

◆ x_DoubleLock()

template<class Type , class Container , class Traits >

◆ x_End() [1/2]

template<class Type , class Container , class Traits >

◆ x_End() [2/2]

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Get constant iterator pointing to the end of underlying container.

◆ x_Erase() [1/2]

template<class Type , class Container , class Traits >

Erase several elements from the underlying container.

Parameters
from_iter Iterator pointing to the start of elements block to be deleted to_iter Iterator pointing to the end of the block of elements to be deleted (one element after the last element to delete)
Returns
Iterator pointing to the first element after the deleted ones.

Definition at line 1699 of file sync_queue.hpp.

References delta(), and NCBI_THROW.

◆ x_Erase() [2/2]

template<class Type , class Container , class Traits >

Erase one element from the underlying container.

Parameters
iter Iterator pointing to the element to be deleted
Returns
Iterator pointing to the element next to the deleted one

Definition at line 1688 of file sync_queue.hpp.

◆ x_GuardedLock()

template<class Type , class Container , class Traits >

◆ x_GuardedUnlock()

template<class Type , class Container , class Traits >

void CSyncQueue< Type, Container, Traits >::x_GuardedUnlock ( void  ) const inlineprivate ◆ x_IsGuarded()

template<class Type , class Container , class Traits >

◆ x_Lock()

template<class Type , class Container , class Traits >

◆ x_LockAndWait()

template<class Type , class Container , class Traits >

Lock the queue and wait until the condition function returns FALSE.

Parameters
lock Auto-lock object to acquire the lock on the queue full_tmo Maximum time period to wait on this call (including waiting for other threads to unlock the queue and waiting for condition to return FALSE); NULL to wait infinitely. If the timeout is exceeded, then return (with or without locking). service_tmo Maximum time period to wait for other threads to unlock the queue; NULL to wait infinitely. If the timeout is exceeded, then return (without locking). func_to_check Function to check condition trigger Semaphore to wait for the condition counter Counter of threads waiting on this semaphore throw_error Function to throw exception when timeout is exceeded

Definition at line 1343 of file sync_queue.hpp.

References CAtomicCounter::Add(), CStopWatch::Elapsed(), ePositive, CStopWatch::eStart, CTimeSpan::GetSign(), CSyncQueue_InternalAutoLock< Type, Container, Traits >::Lock(), CSemaphore::TryWait(), CSyncQueue_InternalAutoLock< Type, Container, Traits >::Unlock(), and CSemaphore::Wait().

◆ x_LockAndWaitWhileEmpty()

template<class Type , class Container , class Traits >

Lock the queue and wait until it has at least one element.

Parameters
lock Auto-lock object to acquire the lock on the queue full_tmo Maximum time period to wait on this call (including waiting for other threads to unlock the queue and waiting until there is any element in the queue to retrieve); NULL to wait infinitely. If the timeout is exceeded, then return (with or without locking). service_tmo Maximum time period to wait for other threads to unlock the queue; NULL to wait infinitely. If the timeout is exceeded, then return (without locking).

Definition at line 1445 of file sync_queue.hpp.

References ThrowSyncQueueEmpty().

◆ x_LockAndWaitWhileFull()

template<class Type , class Container , class Traits >

Lock the queue and wait until it has room for more elements.

Parameters
lock Auto-lock object to acquire the lock on the queue full_tmo Maximum time period to wait on this call (including waiting for other threads to unlock the queue and waiting until there is space in the queue to add element to); NULL to wait infinitely. If the timeout is exceeded, then return (with or without locking). service_tmo Maximum time period to wait for other threads to unlock the queue; NULL to wait infinitely. If the timeout is exceeded, then return (without locking).

Definition at line 1432 of file sync_queue.hpp.

References ThrowSyncQueueNoRoom().

◆ x_Pop_NonBlocking()

template<class Type , class Container , class Traits >

◆ x_Push_NonBlocking()

template<class Type , class Container , class Traits >

◆ x_Unlock()

template<class Type , class Container , class Traits >

◆ CSyncQueue_AccessGuard< Type, Container, Traits >

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Definition at line 540 of file sync_queue.hpp.

◆ CSyncQueue_ConstAccessGuard< Type, Container, Traits >

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Definition at line 540 of file sync_queue.hpp.

◆ CSyncQueue_I< Type, Container, TNativeConstIter, Traits >

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Definition at line 540 of file sync_queue.hpp.

◆ CSyncQueue_I< Type, Container, TNativeIter, Traits >

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Definition at line 540 of file sync_queue.hpp.

◆ CSyncQueue_InternalAutoLock< Type, Container, Traits >

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Definition at line 540 of file sync_queue.hpp.

◆ m_CntWaitNotEmpty

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Number of threads waiting for the queue to become non-empty.

Definition at line 528 of file sync_queue.hpp.

◆ m_CntWaitNotFull

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Number of threads waiting for the queue to become non-full.

Definition at line 534 of file sync_queue.hpp.

◆ m_CurGuardTID

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

ID of the thread in which the queue has been locked by a guardian.

Definition at line 537 of file sync_queue.hpp.

◆ m_LockCount

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Number of lockings of this queue with access guardians in one thread.

Definition at line 540 of file sync_queue.hpp.

◆ m_MaxSize

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ m_Size

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ m_Store

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

◆ m_TrigLock

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Semaphore to signal that the queue can be safely modified.

Definition at line 522 of file sync_queue.hpp.

◆ m_TrigNotEmpty

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Semaphore to signal that the queue has become not empty.

Definition at line 525 of file sync_queue.hpp.

◆ m_TrigNotFull

template<class Type , class Container = deque<Type>, class Traits = CSyncQueue_DefaultTraits>

Semaphore to signal that the queue has become not full.

Definition at line 531 of file sync_queue.hpp.

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4