# litert::Event


`#include <litert_event.h>`

Defines the C++ wrapper for LiteRT events, used for synchronization.

## Summary

### Inheritance

Inherits from: internal::BaseHandle\< LiteRtEvent \>

| ### Public types ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a0327c262e4766bafb34d48ec656d1530` | enum |

| ### Public static functions ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a3bbf194279ce35000af6c07d75ec8eb6(const https://developers.google.com/edge/api/litert/c/classlitert/1-1-environment#classlitert_1_1_environment & env, LiteRtEglSyncKhr egl_sync)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event >` Creates an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event` object from an EGL sync fence. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a611e226e3663aee5fcf06ca219ea82bc(const https://developers.google.com/edge/api/litert/c/classlitert/1-1-environment#classlitert_1_1_environment & env, LiteRtClEvent cl_event)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event >` Creates an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event` object from an OpenCL event. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a7a22ec53aeb6e0c35bc2a2d7bf00a6ba(const https://developers.google.com/edge/api/litert/c/classlitert/1-1-environment#classlitert_1_1_environment & env, int sync_fence_fd, bool owns_fd)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event >` Creates an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event` object from a sync fence file descriptor. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a4d0b91e672652510ef67ce2767696462(const https://developers.google.com/edge/api/litert/c/classlitert/1-1-environment#classlitert_1_1_environment & env, Type type)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event >` Creates a managed event of a given type. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1ad99e943230b2f8c0a8e6708c24d7ab5f(const https://developers.google.com/edge/api/litert/c/structlitert/1-1internal-1-1-environment-holder#structlitert_1_1internal_1_1_environment_holder & env, LiteRtEvent event, OwnHandle owned)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event` |

| ### Public functions ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1aab3320b5da9df3140ed2c11504e2be85()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< int >` Returns a duplicate of the event's sync fence file descriptor. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1ae30b8e2d315ee56bb13e75f1f350bc6d()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void * >` |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a92685fe03b31e5049d9fd7fe003db068()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< LiteRtEglSyncKhr >` |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1aed646e4de945ff4749882282f5525254()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< LiteRtClEvent >` Returns the underlying OpenCL event if the event type is OpenCL. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1ad0c1a86531bfdaec59997215b908c9fe()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< int >` |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1afdeafccf650eaa5dfcefd8f84b050e43()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< bool >` Returns `true` if the event is signaled. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a5050f13a6f1661831287fbab5327a743()` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Signals the event. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1a80f536c2225edaaa5a57495a1c3f8503() const ` | `Type` Returns the underlying event type. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event_1ab5ec6fabd9acbac12e308d55298a56b0(int64_t timeout_in_ms)` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-expected#classlitert_1_1_expected< void >` Waits for the event to be signaled. |

## Public types

### Type

```
 Type
```

## Public static functions

### CreateFromEglSyncFence

```
Expected< Event > CreateFromEglSyncFence(
  const Environment & env,
  LiteRtEglSyncKhr egl_sync
)
```
Creates an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event` object from an EGL sync fence.


> [!NOTE]
> **Note:** This function assumes that all GL operations have already been added to the GPU command queue.

<br />

### CreateFromOpenClEvent

```
Expected< Event > CreateFromOpenClEvent(
  const Environment & env,
  LiteRtClEvent cl_event
)
```
Creates an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event` object from an OpenCL event.

### CreateFromSyncFenceFd

```
Expected< Event > CreateFromSyncFenceFd(
  const Environment & env,
  int sync_fence_fd,
  bool owns_fd
)
```
Creates an `https://developers.google.com/edge/api/litert/c/classlitert/1-1-event#classlitert_1_1_event` object from a sync fence file descriptor.

### CreateManaged

```
Expected< Event > CreateManaged(
  const Environment & env,
  Type type
)
```
Creates a managed event of a given type.

Currently, only `LiteRtEventTypeOpenCl` is supported.

### WrapCObject

```
Event WrapCObject(
  const internal::EnvironmentHolder & env,
  LiteRtEvent event,
  OwnHandle owned
)
```

## Public functions

### DupFd

```
Expected< int > DupFd()
```
Returns a duplicate of the event's sync fence file descriptor.


> [!NOTE]
> **Note:** This is only supported for sync fence events.

<br />

### GetCustomNativeEvent

```
Expected< void * > GetCustomNativeEvent()
```

### GetEglSync

```
Expected< LiteRtEglSyncKhr > GetEglSync()
```

### GetOpenClEvent

```
Expected< LiteRtClEvent > GetOpenClEvent()
```
Returns the underlying OpenCL event if the event type is OpenCL.

### GetSyncFenceFd

```
Expected< int > GetSyncFenceFd()
```

### IsSignaled

```
Expected< bool > IsSignaled()
```
Returns `true` if the event is signaled.


> [!NOTE]
> **Note:** This is only supported for sync fence events.

<br />

### Signal

```
Expected< void > Signal()
```
Signals the event.


> [!NOTE]
> **Note:** This is only supported for OpenCL events.

<br />

### Type

```
Type Type() const 
```
Returns the underlying event type.

### Wait

```
Expected< void > Wait(
  int64_t timeout_in_ms
)
```
Waits for the event to be signaled.

<br />

Details Parameters `timeout_in_ms` The timeout in milliseconds. A value of -1 indicates an indefinite wait.