-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathseqlock.h
40 lines (31 loc) · 1.08 KB
/
seqlock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
typedef uint32_t seqlock_t;
/* Initialise a seqlock aka reader/writer synchronization */
void seqlock_init(seqlock_t *sync);
/* Acquire a seqlock for reading
* Block until no write is in progress
*/
seqlock_t seqlock_acquire_rd(const seqlock_t *sync);
/* Release a read seqlock
* Return false if a write has occurred or is in progress
* This means any read data may be inconsistent and the operation should be
* restarted
*/
bool seqlock_release_rd(const seqlock_t *sync, seqlock_t prv);
/* Acquire a seqlock for writing
* Block until earlier writes have completed
*/
void seqlock_acquire_wr(seqlock_t *sync);
/* Release a write seqlock */
void seqlock_release_wr(seqlock_t *sync);
/* Perform an atomic read of the associated data
* Will block for concurrent writes
*/
void seqlock_read(seqlock_t *sync, void *dst, const void *data, size_t len);
/* Perform an atomic write of the associated data
* Will block for concurrent writes
*/
void seqlock_write(seqlock_t *sync, const void *src, void *data, size_t len);