libzypp: zyppng::AsyncQueue< Message > Class Template Reference

libzypp 17.38.6

zyppng::AsyncQueue< Message > Class Template Reference

`#include <zypp-core/ng/thread/asyncqueue.h>`

Inheritance diagram for zyppng::AsyncQueue< Message >:

## Public Types
using | Ptr = std::shared_ptr<AsyncQueue>

## Public Member Functions
| AsyncQueue (const AsyncQueue &)=delete
AsyncQueue & | operator= (const AsyncQueue &)=delete
template<typename T = Message>
void | pushUnlocked (T &&value)
template<typename T = Message>
void | push (T &&value)
Message | pop ()
std::optional< Message > | tryPop ()
std::optional< Message > | tryPopUnlocked ()
void | lock ()
void | unlock ()
void | notify ()
Public Member Functions inherited from zyppng::AsyncQueueBase
virtual | ~AsyncQueueBase ()
void | addWatch (AsyncQueueWatch &watch)
void | removeWatch (AsyncQueueWatch &watch)
void | notifyWatches ()

## Static Public Member Functions
static Ptr | create ()

## Private Member Functions
| AsyncQueue ()=default

## Private Attributes
std::queue< Message > | _messages
std::mutex | _mut
std::condition_variable | _cv

## Detailed Description

template<class Message>
class zyppng::AsyncQueue< Message >

AsyncQueue provides a thread safe way to send messages between threads. Using this class makes only sense for multithreaded applications.

Definition at line 43 of file asyncqueue.h.

## Member Typedef Documentation

## ◆ Ptr

template<class Message>

using zyppng::AsyncQueue< Message >::Ptr = std::shared_ptr<AsyncQueue>

Definition at line 47 of file asyncqueue.h.

## Constructor & Destructor Documentation

## ◆ AsyncQueue() [1/2]

template<class Message>

zyppng::AsyncQueue< Message >::AsyncQueue | ( | const AsyncQueue< Message > & |  | ) |
| delete

## ◆ AsyncQueue() [2/2]

template<class Message>

zyppng::AsyncQueue< Message >::AsyncQueue | ( |  | ) |
| privatedefault

## Member Function Documentation

## ◆ create()

template<class Message>

Ptr zyppng::AsyncQueue< Message >::create | ( |  | ) |
| inlinestatic

Definition at line 49 of file asyncqueue.h.

## ◆ operator=()

template<class Message>

AsyncQueue & zyppng::AsyncQueue< Message >::operator= | ( | const AsyncQueue< Message > & |  | ) |
| delete

## ◆ pushUnlocked()

template<class Message>
template<typename T = Message>

void zyppng::AsyncQueue< Message >::pushUnlocked | ( | T && | value | ) |
| inline

Pushes a new message into the queue, make sure to manually acqiure the lock before calling this function and notify after unlocking it again. This function should be used when multiple messages should be pushed into the queue before notifying the threads.

See also
  push

Definition at line 64 of file asyncqueue.h.

## ◆ push()

template<class Message>
template<typename T = Message>

void zyppng::AsyncQueue< Message >::push | ( | T && | value | ) |
| inline

Pushes a new message into the queue and notify all waiting threads that there is new data available.

Definition at line 73 of file asyncqueue.h.

## ◆ pop()

template<class Message>

Message zyppng::AsyncQueue< Message >::pop | ( |  | ) |
| inline

Pops the first message from the queue, blocking until there is data available.

Definition at line 84 of file asyncqueue.h.

## ◆ tryPop()

template<class Message>

std::optional< Message > zyppng::AsyncQueue< Message >::tryPop | ( |  | ) |
| inline

Tries to pop the first element from the queue, if no data is available returns a empty std::optional instead of blocking.

Definition at line 96 of file asyncqueue.h.

## ◆ tryPopUnlocked()

template<class Message>

std::optional< Message > zyppng::AsyncQueue< Message >::tryPopUnlocked | ( |  | ) |
| inline

Same as tryPop but does not lock the mutex, make sure to acquire the lock before calling this function.

Definition at line 105 of file asyncqueue.h.

## ◆ lock()

template<class Message>

void zyppng::AsyncQueue< Message >::lock | ( |  | ) |
| inline

Locks the internal mutex, use std::lock_guard instead of manually calling lock and unlock.

Definition at line 118 of file asyncqueue.h.

## ◆ unlock()

template<class Message>

void zyppng::AsyncQueue< Message >::unlock | ( |  | ) |
| inline

Unlocks the internal mutex, use std::lock_guard instead of manually calling lock and unlock.

Definition at line 126 of file asyncqueue.h.

## ◆ notify()

template<class Message>

void zyppng::AsyncQueue< Message >::notify | ( |  | ) |
| inline

Notifies all waiting threads and registered AsyncQueueWatch instances that new data is available.

Definition at line 134 of file asyncqueue.h.

## Member Data Documentation

## ◆ _messages

template<class Message>

std::queue<Message> zyppng::AsyncQueue< Message >::_messages
| private

Definition at line 141 of file asyncqueue.h.

## ◆ _mut

template<class Message>

std::mutex zyppng::AsyncQueue< Message >::_mut
| private

Definition at line 142 of file asyncqueue.h.

## ◆ _cv

template<class Message>

std::condition_variable zyppng::AsyncQueue< Message >::_cv
| private

Definition at line 143 of file asyncqueue.h.

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

- zypp-core/ng/thread/asyncqueue.h