---
name: "rte_spinlock.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_spinlock.h"
---

# rte\_spinlock.h(3)

## NAME

rte\_spinlock.h

## SYNOPSIS

`#include <rte_lcore.h>`\
 `#include <rte_lock_annotations.h>`\
 `#include <rte_pause.h>`\
 `#include <rte_stdatomic.h>`\

### Data Structures

struct **rte\_spinlock\_t**\
 struct **rte\_spinlock\_recursive\_t**\

### Macros

\#define **RTE\_SPINLOCK\_INITIALIZER**   { 0 }\
 \#define **RTE\_SPINLOCK\_RECURSIVE\_INITIALIZER**   {**RTE\_SPINLOCK\_INITIALIZER**, -1, 0}\

### Functions

static void **rte\_spinlock\_init** (**rte\_spinlock\_t** \*sl)\
 static void **rte\_spinlock\_lock** (**rte\_spinlock\_t** \*sl)\
 static void **rte\_spinlock\_unlock** (**rte\_spinlock\_t** \*sl)\
 static **\_\_rte\_warn\_unused\_result** int **rte\_spinlock\_trylock** (**rte\_spinlock\_t** \*sl) sl)\
 static int **rte\_spinlock\_is\_locked** (**rte\_spinlock\_t** \*sl)\
 static int **rte\_tm\_supported** (void)\
 static void **rte\_spinlock\_lock\_tm** (**rte\_spinlock\_t** \*sl)\
 static void **rte\_spinlock\_unlock\_tm** (**rte\_spinlock\_t** \*sl)\
 static **\_\_rte\_warn\_unused\_result** int **rte\_spinlock\_trylock\_tm** (**rte\_spinlock\_t** \*sl) sl)\
 static void **rte\_spinlock\_recursive\_init** (**rte\_spinlock\_recursive\_t** \*slr)\
 static void **rte\_spinlock\_recursive\_lock** (**rte\_spinlock\_recursive\_t** \*slr) \_\_rte\_no\_thread\_safety\_analysis\
 static void **rte\_spinlock\_recursive\_unlock** (**rte\_spinlock\_recursive\_t** \*slr) \_\_rte\_no\_thread\_safety\_analysis\
 static **\_\_rte\_warn\_unused\_result** int **rte\_spinlock\_recursive\_trylock** (**rte\_spinlock\_recursive\_t** \*slr) \_\_rte\_no\_thread\_safety\_analysis\
 static void **rte\_spinlock\_recursive\_lock\_tm** (**rte\_spinlock\_recursive\_t** \*slr)\
 static void **rte\_spinlock\_recursive\_unlock\_tm** (**rte\_spinlock\_recursive\_t** \*slr)\
 static **\_\_rte\_warn\_unused\_result** int **rte\_spinlock\_recursive\_trylock\_tm** (**rte\_spinlock\_recursive\_t** \*slr)\

## Detailed Description

RTE Spinlocks

This file defines an API for read-write locks, which are implemented in an architecture-specific way. This kind of lock simply waits in a loop repeatedly checking until the lock becomes available.

All locks must be initialised before use, and only initialised once.

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

## Macro Definition Documentation

### #define RTE\_SPINLOCK\_INITIALIZER { 0 }

A static spinlock initializer.

Definition at line **42** of file **rte\_spinlock.h**.

### #define RTE\_SPINLOCK\_RECURSIVE\_INITIALIZER {RTE\_SPINLOCK\_INITIALIZER, -1, 0}

A static recursive spinlock initializer.

Definition at line **207** of file **rte\_spinlock.h**.

## Function Documentation

### static void rte\_spinlock\_init (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Initialize the spinlock to an unlocked state.

**Parameters**

*sl* A pointer to the spinlock.

Definition at line **51** of file **rte\_spinlock.h**.

### static void rte\_spinlock\_lock (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Take the spinlock.

**Parameters**

*sl* A pointer to the spinlock.

### static void rte\_spinlock\_unlock (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Release the spinlock.

**Parameters**

*sl* A pointer to the spinlock.

### static \_\_rte\_warn\_unused\_result int rte\_spinlock\_trylock (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Try to take the lock.

**Parameters**

*sl* A pointer to the spinlock.

**Returns**

1 if the lock is successfully taken; 0 otherwise.

### static int rte\_spinlock\_is\_locked (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Test if the lock is taken.

**Parameters**

*sl* A pointer to the spinlock.

**Returns**

1 if the lock is currently taken; 0 otherwise.

Definition at line **133** of file **rte\_spinlock.h**.

### static int rte\_tm\_supported (void)` [inline]`, ` [static]`

Test if hardware transactional memory (lock elision) is supported

**Returns**

1 if the hardware transactional memory is supported; 0 otherwise.

### static void rte\_spinlock\_lock\_tm (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Try to execute critical section in a hardware memory transaction, if it fails or not available take the spinlock.

NOTE: An attempt to perform a HW I/O operation inside a hardware memory transaction always aborts the transaction since the CPU is not able to roll-back should the transaction fail. Therefore, hardware transactional locks are not advised to be used around **rte\_eth\_rx\_burst()** and **rte\_eth\_tx\_burst()** calls.

**Parameters**

*sl* A pointer to the spinlock.

### static void rte\_spinlock\_unlock\_tm (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Commit hardware memory transaction or release the spinlock if the spinlock is used as a fall-back

**Parameters**

*sl* A pointer to the spinlock.

### static \_\_rte\_warn\_unused\_result int rte\_spinlock\_trylock\_tm (rte\_spinlock\_t \* sl)` [inline]`, ` [static]`

Try to execute critical section in a hardware memory transaction, if it fails or not available try to take the lock.

NOTE: An attempt to perform a HW I/O operation inside a hardware memory transaction always aborts the transaction since the CPU is not able to roll-back should the transaction fail. Therefore, hardware transactional locks are not advised to be used around **rte\_eth\_rx\_burst()** and **rte\_eth\_tx\_burst()** calls.

**Parameters**

*sl* A pointer to the spinlock.

**Returns**

1 if the hardware memory transaction is successfully started or lock is successfully taken; 0 otherwise.

### static void rte\_spinlock\_recursive\_init (rte\_spinlock\_recursive\_t \* slr)` [inline]`, ` [static]`

Initialize the recursive spinlock to an unlocked state.

**Parameters**

*slr* A pointer to the recursive spinlock.

Definition at line **215** of file **rte\_spinlock.h**.

### static void rte\_spinlock\_recursive\_lock (rte\_spinlock\_recursive\_t \* slr)` [inline]`, ` [static]`

Take the recursive spinlock.

**Parameters**

*slr* A pointer to the recursive spinlock.

Definition at line **228** of file **rte\_spinlock.h**.

### static void rte\_spinlock\_recursive\_unlock (rte\_spinlock\_recursive\_t \* slr)` [inline]`, ` [static]`

Release the recursive spinlock.

**Parameters**

*slr* A pointer to the recursive spinlock.

Definition at line **245** of file **rte\_spinlock.h**.

### static \_\_rte\_warn\_unused\_result int rte\_spinlock\_recursive\_trylock (rte\_spinlock\_recursive\_t \* slr)` [inline]`, ` [static]`

Try to take the recursive lock.

**Parameters**

*slr* A pointer to the recursive spinlock.

**Returns**

1 if the lock is successfully taken; 0 otherwise.

Definition at line **264** of file **rte\_spinlock.h**.

### static void rte\_spinlock\_recursive\_lock\_tm (rte\_spinlock\_recursive\_t \* slr)` [inline]`, ` [static]`

Try to execute critical section in a hardware memory transaction, if it fails or not available take the recursive spinlocks

NOTE: An attempt to perform a HW I/O operation inside a hardware memory transaction always aborts the transaction since the CPU is not able to roll-back should the transaction fail. Therefore, hardware transactional locks are not advised to be used around **rte\_eth\_rx\_burst()** and **rte\_eth\_tx\_burst()** calls.

**Parameters**

*slr* A pointer to the recursive spinlock.

### static void rte\_spinlock\_recursive\_unlock\_tm (rte\_spinlock\_recursive\_t \* slr)` [inline]`, ` [static]`

Commit hardware memory transaction or release the recursive spinlock if the recursive spinlock is used as a fall-back

**Parameters**

*slr* A pointer to the recursive spinlock.

### static \_\_rte\_warn\_unused\_result int rte\_spinlock\_recursive\_trylock\_tm (rte\_spinlock\_recursive\_t \* slr)` [inline]`, ` [static]`

Try to execute critical section in a hardware memory transaction, if it fails or not available try to take the recursive lock

NOTE: An attempt to perform a HW I/O operation inside a hardware memory transaction always aborts the transaction since the CPU is not able to roll-back should the transaction fail. Therefore, hardware transactional locks are not advised to be used around **rte\_eth\_rx\_burst()** and **rte\_eth\_tx\_burst()** calls.

**Parameters**

*slr* A pointer to the recursive spinlock.

**Returns**

1 if the hardware memory transaction is successfully started or lock is successfully taken; 0 otherwise.

## Author

Generated automatically by Doxygen for DPDK from the source code.
