---
name: "rte_seqcount.h"
section: "3"
platform: "linux"
package: "dpdk-doc"
version: "24.11.4-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rte_seqcount.h"
---

# rte\_seqcount.h(3)

## NAME

rte\_seqcount.h

## SYNOPSIS

`#include <stdbool.h>`\
 `#include <stdint.h>`\
 `#include <rte_atomic.h>`\
 `#include <rte_branch_prediction.h>`\
 `#include <rte_stdatomic.h>`\

### Data Structures

struct **rte\_seqcount\_t**\

### Macros

\#define **RTE\_SEQCOUNT\_INITIALIZER**   { .sn = 0 }\

### Functions

static void **rte\_seqcount\_init** (**rte\_seqcount\_t** \*seqcount)\
 static uint32\_t **rte\_seqcount\_read\_begin** (const **rte\_seqcount\_t** \*seqcount)\
 static bool **rte\_seqcount\_read\_retry** (const **rte\_seqcount\_t** \*seqcount, uint32\_t begin\_sn)\
 static void **rte\_seqcount\_write\_begin** (**rte\_seqcount\_t** \*seqcount)\
 static void **rte\_seqcount\_write\_end** (**rte\_seqcount\_t** \*seqcount)\

## Detailed Description

RTE Seqcount

The sequence counter synchronizes a single writer with multiple, parallel readers. It is used as the basis for the RTE sequence lock.

**See also**

**rte\_seqlock.h**

Definition in file **rte\_seqcount.h**.

## Macro Definition Documentation

### #define RTE\_SEQCOUNT\_INITIALIZER { .sn = 0 }

A static seqcount initializer.

Definition at line **40** of file **rte\_seqcount.h**.

## Function Documentation

### static void rte\_seqcount\_init (rte\_seqcount\_t \* seqcount)` [inline]`, ` [static]`

Initialize the sequence counter.

**Parameters**

*seqcount* A pointer to the sequence counter.

Definition at line **49** of file **rte\_seqcount.h**.

### static uint32\_t rte\_seqcount\_read\_begin (const rte\_seqcount\_t \* seqcount)` [inline]`, ` [static]`

Begin a read-side critical section.

A call to this function marks the beginning of a read-side critical section, for `seqcount`.

**rte\_seqcount\_read\_begin()** returns a sequence number, which is later used in **rte\_seqcount\_read\_retry()** to check if the protected data underwent any modifications during the read transaction.

After (in program order) **rte\_seqcount\_read\_begin()** has been called, the calling thread reads the protected data, for later use. The protected data read *must* be copied (either in pristine form, or in the form of some derivative), since the caller may only read the data from within the read-side critical section (i.e., after **rte\_seqcount\_read\_begin()** and before **rte\_seqcount\_read\_retry()**), but must not act upon the retrieved data while in the critical section, since it does not yet know if it is consistent.

The protected data may be read using atomic and/or non-atomic operations.

After (in program order) all required data loads have been performed, **rte\_seqcount\_read\_retry()** should be called, marking the end of the read-side critical section.

If **rte\_seqcount\_read\_retry()** returns true, the just-read data is inconsistent and should be discarded. The caller has the option to either restart the whole procedure right away (i.e., calling **rte\_seqcount\_read\_begin()** again), or do the same at some later time.

If **rte\_seqcount\_read\_retry()** returns false, the data was read atomically and the copied data is consistent.

**Parameters**

*seqcount* A pointer to the sequence counter.

**Returns**

The seqcount sequence number for this critical section, to later be passed to **rte\_seqcount\_read\_retry()**.

**See also**

**rte\_seqcount\_read\_retry()**

Definition at line **97** of file **rte\_seqcount.h**.

### static bool rte\_seqcount\_read\_retry (const rte\_seqcount\_t \* seqcount, uint32\_t begin\_sn)` [inline]`, ` [static]`

End a read-side critical section.

A call to this function marks the end of a read-side critical section, for `seqcount`. The application must supply the sequence number produced by the corresponding **rte\_seqcount\_read\_begin()** call.

After this function has been called, the caller should not access the protected data.

In case **rte\_seqcount\_read\_retry()** returns true, the just-read data was modified as it was being read and may be inconsistent, and thus should be discarded.

In case this function returns false, the data is consistent and the set of atomic and non-atomic load operations performed between **rte\_seqcount\_read\_begin()** and **rte\_seqcount\_read\_retry()** were atomic, as a whole.

**Parameters**

*seqcount* A pointer to the sequence counter. \
 *begin\_sn* The sequence number returned by **rte\_seqcount\_read\_begin()**.

**Returns**

true or false, if the just-read seqcount-protected data was inconsistent or consistent, respectively, at the time it was read.

**See also**

**rte\_seqcount\_read\_begin()**

Definition at line **137** of file **rte\_seqcount.h**.

### static void rte\_seqcount\_write\_begin (rte\_seqcount\_t \* seqcount)` [inline]`, ` [static]`

Begin a write-side critical section.

A call to this function marks the beginning of a write-side critical section, after which the caller may go on to modify (both read and write) the protected data, in an atomic or non-atomic manner.

After the necessary updates have been performed, the application calls **rte\_seqcount\_write\_end()**.

Multiple, parallel writers must use some external serialization.

This function is not preemption-safe in the sense that preemption of the calling thread may block reader progress until the writer thread is rescheduled.

**Parameters**

*seqcount* A pointer to the sequence counter.

**See also**

**rte\_seqcount\_write\_end()**

Definition at line **182** of file **rte\_seqcount.h**.

### static void rte\_seqcount\_write\_end (rte\_seqcount\_t \* seqcount)` [inline]`, ` [static]`

End a write-side critical section.

A call to this function marks the end of the write-side critical section, for `seqcount`. After this call has been made, the protected data may no longer be modified.

**Parameters**

*seqcount* A pointer to the sequence counter.

**See also**

**rte\_seqcount\_write\_begin()**

Definition at line **209** of file **rte\_seqcount.h**.

## Author

Generated automatically by Doxygen for DPDK from the source code.
