XROAD
xroad_lock.h
Go to the documentation of this file.
1 #pragma once
7 #include <stdint.h>
8 #include <stdbool.h>
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
15 typedef union
16 {
17  uint64_t full;
18  uint16_t owner_state;
19  uint32_t state;
20  struct
21  {
22  uint8_t version;
23  uint8_t r_depth;
24  uint8_t users;
25  uint8_t pad;
26  union
27  {
28  int32_t pid;
29  uint32_t lid;
30  };
31  };
32 } xroad_lock_t;
33 
34 /*
35  * @brief agressively acuires lock
36  * @param[in] l - lock
37  */
38 void xroad_lock_lock(xroad_lock_t* l);
39 
44 void xroad_lock_lock_ex(xroad_lock_t* l, uint32_t locker_id);
45 
46 /*
47  * @brief releases lock
48  * @param[in] l - lock
49  * @return true - unlocked, else still locked
50  */
51 bool xroad_lock_unlock(xroad_lock_t* l);
53 bool xroad_lock_unlock_ex(xroad_lock_t* l, uint32_t locker_id);
54 
55 /*
56  * @brief resets lock
57  * @param[in] l - lock
58  */
59 void xroad_lock_reset(xroad_lock_t* l);
60 
61 /*
62  * @brief releases lock
63  * @param[in] l_ptr - pointer to lock
64  */
65 #define __xroad_lock_unlock_dtor__ __attribute__((__cleanup__(xroad_lock_unlock_dtor)))
66 void xroad_lock_unlock_dtor(xroad_lock_t** l_ptr);
67 
70 
72 int32_t xroad_lock_get_pid(const xroad_lock_t* l);
73 
76 
77 #ifdef __cplusplus
78 }
79 #endif
Definition: xroad_lock.h:16
void xroad_lock_lock_ex(xroad_lock_t *l, uint32_t locker_id)
bool xroad_lock_unlock_ex(xroad_lock_t *l, uint32_t locker_id)
Release lock assuming it belongs to locker_id.
int32_t xroad_lock_get_pid(const xroad_lock_t *l)
Get pid of the process holding the lock.
int32_t xroad_lock_number_lock(const xroad_lock_t *l)
Get the number (depth) of locks held by the owning process (recursive lock)
int32_t xroad_lock_get_version(const xroad_lock_t *l)
Get lock version (generation)