# ipc::Queue

<a id="queue-6"></a>

# Queue

```cpp
#include <icy/ipc.h>

template<typename TAction = ipc::Action>
class Queue
```

[Defined in src/base/include/icy/ipc.h:57](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L57)

> **Subclassed by:** [`SyncQueue< TAction >`](https://auscaster.com/icey/docs/api-reference/icy-ipc-SyncQueue.md#syncqueue-3)

IPC queue is for safely passing templated actions between threads and processes.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Queue`](#queue-7) `inline` |  |
|  | [`~Queue`](#queue-8) `virtual` `inline` |  |
| `void` | [`push`](#push-5) `virtual` `inline` | Pushes an action onto the queue and triggers a post notification. Takes ownership of action; the queue deletes it after execution. Thread-safe. |
| `TAction *` | [`pop`](#pop-1) `virtual` `inline` | Removes and returns the next action from the front of the queue. The caller takes ownership of the returned pointer. Thread-safe. |
| `void` | [`runSync`](#runsync) `virtual` `inline` | Drains the queue by invoking and deleting every pending action in order. Must be called from the thread that owns the event loop. |
| `void` | [`close`](#close-24) `virtual` `inline` | Closes the underlying notification handle. No-op in the base implementation. |
| `void` | [`post`](#post-1) `virtual` `inline` | Signals the event loop that new actions are available. No-op in the base implementation. |
| `void` | [`waitForSync`](#waitforsync) `inline` | Blocks the calling thread until the queue is empty or the timeout elapses. Polls every 10 ms. Logs a warning if the timeout is reached. |

---

<a id="queue-7"></a>

### Queue

`inline`

```cpp
inline Queue()
```

[Defined in src/base/include/icy/ipc.h:60](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L60)

---

<a id="queue-8"></a>

### ~Queue

`virtual` `inline`

```cpp
virtual inline ~Queue()
```

[Defined in src/base/include/icy/ipc.h:62](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L62)

---

<a id="push-5"></a>

### push

`virtual` `inline`

```cpp
virtual inline void push(TAction * action)
```

[Defined in src/base/include/icy/ipc.h:68](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L68)

Pushes an action onto the queue and triggers a post notification. Takes ownership of action; the queue deletes it after execution. Thread-safe.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `action` | `TAction *` | Heap-allocated action to enqueue. |

---

<a id="pop-1"></a>

### pop

`virtual` `inline`

```cpp
virtual inline TAction * pop()
```

[Defined in src/base/include/icy/ipc.h:81](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L81)

Removes and returns the next action from the front of the queue. The caller takes ownership of the returned pointer. Thread-safe. 
#### Returns
Pointer to the next action, or nullptr if the queue is empty.

---

<a id="runsync"></a>

### runSync

`virtual` `inline`

```cpp
virtual inline void runSync()
```

[Defined in src/base/include/icy/ipc.h:93](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L93)

Drains the queue by invoking and deleting every pending action in order. Must be called from the thread that owns the event loop.

---

<a id="close-24"></a>

### close

`virtual` `inline`

```cpp
virtual inline void close()
```

[Defined in src/base/include/icy/ipc.h:103](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L103)

Closes the underlying notification handle. No-op in the base implementation.

#### Reimplemented by

- [`SyncQueue::close`](https://auscaster.com/icey/docs/api-reference/icy-ipc-SyncQueue.md#close-25)

---

<a id="post-1"></a>

### post

`virtual` `inline`

```cpp
virtual inline void post()
```

[Defined in src/base/include/icy/ipc.h:106](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L106)

Signals the event loop that new actions are available. No-op in the base implementation.

#### Reimplemented by

- [`SyncQueue::post`](https://auscaster.com/icey/docs/api-reference/icy-ipc-SyncQueue.md#post-2)

---

<a id="waitforsync"></a>

### waitForSync

`inline`

```cpp
inline void waitForSync(std::chrono::milliseconds timeout = std::chrono::milliseconds(5000))
```

[Defined in src/base/include/icy/ipc.h:111](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L111)

Blocks the calling thread until the queue is empty or the timeout elapses. Polls every 10 ms. Logs a warning if the timeout is reached.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `timeout` | `std::chrono::milliseconds` | Maximum time to wait (default: 5000 ms). |

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::mutex` | [`_mutex`](#_mutex-14)  |  |
| `std::deque< TAction * >` | [`_actions`](#_actions)  |  |

---

<a id="_mutex-14"></a>

### _mutex

```cpp
std::mutex _mutex
```

[Defined in src/base/include/icy/ipc.h:127](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L127)

---

<a id="_actions"></a>

### _actions

```cpp
std::deque< TAction * > _actions
```

[Defined in src/base/include/icy/ipc.h:128](https://github.com/auscaster/icey/blob/main/src/base/include/icy/ipc.h#L128)
