Modular C
+ Collaboration diagram for C◼atomic◼rwlock:

Modules

 C◼atomic◼rwlock◼ato: symbols inserted from C◼atomic.
 
 Specific macros to deal with the structure of module C◼atomic◼rwlock.
 
 Symbols inserted from C◼bool.
 

Files

file  C-atomic-rwlock.c
 Implement a simple rw lock that can be used thread safe.
 

Data Structures

struct  C◼atomic◼rwlock
 

Macros

#define C◼atomic◼rwlock◼LOCK_FREE   C◼atomic◼INT_LOCK_FREE
 
#define C◼atomic◼rwlock◼HIGHBIT   ((-1U)/2U+1U)
 
#define C◼atomic◼rwlock◼HIGHBIT1   ((-1U)/2U)
 
#define C◼atomic◼rwlock◼INIT   { C◼atomic◼INIT(0), }
 

Functions

C◼atomic◼rwlock◼bool C◼atomic◼rwlock◼trywrlock (C◼atomic◼rwlock *lck)
 
void C◼atomic◼rwlock◼unwrlock (C◼atomic◼rwlock *lck)
 
void C◼atomic◼rwlock◼wrlock (C◼atomic◼rwlock *lck)
 
C◼atomic◼rwlock◼bool C◼atomic◼rwlock◼tryrdlock (C◼atomic◼rwlock *lck)
 
void C◼atomic◼rwlock◼unrdlock (C◼atomic◼rwlock *lck)
 
void C◼atomic◼rwlock◼rdlock (C◼atomic◼rwlock *lck)
 

Detailed Description


Data Structure Documentation

§ C◼atomic◼rwlock

struct C◼atomic◼rwlock

Definition at line 140 of file C-atomic-rwlock.c.

+ Collaboration diagram for C◼atomic◼rwlock:

Data Fields

unsigned volatile _Atomic lck
 

Field Documentation

§ lck

unsigned volatile _Atomic lck

Definition at line 142 of file C-atomic-rwlock.c.

Macro Definition Documentation

§ C◼atomic◼rwlock◼HIGHBIT

#define C◼atomic◼rwlock◼HIGHBIT   ((-1U)/2U+1U)

§ C◼atomic◼rwlock◼HIGHBIT1

#define C◼atomic◼rwlock◼HIGHBIT1   ((-1U)/2U)

Definition at line 138 of file C-atomic-rwlock.c.

Referenced by C◼atomic◼rwlock◼tryrdlock().

§ C◼atomic◼rwlock◼INIT

#define C◼atomic◼rwlock◼INIT   { C◼atomic◼INIT(0), }

Definition at line 145 of file C-atomic-rwlock.c.

§ C◼atomic◼rwlock◼LOCK_FREE

#define C◼atomic◼rwlock◼LOCK_FREE   C◼atomic◼INT_LOCK_FREE

Definition at line 134 of file C-atomic-rwlock.c.

Function Documentation

§ C◼atomic◼rwlock◼rdlock()

void C◼atomic◼rwlock◼rdlock ( C◼atomic◼rwlock lck)
inline

Definition at line 174 of file C-atomic-rwlock.c.

174  {
175 #line 92 "/home/gustedt/build/cmod/C/C-atomic-rwlock.X"
176  do { /* spin */ } while (¬C◼atomic◼rwlock◼tryrdlock(lck));
177 }

§ C◼atomic◼rwlock◼tryrdlock()

C◼atomic◼rwlock◼bool C◼atomic◼rwlock◼tryrdlock ( C◼atomic◼rwlock lck)
inline

Definition at line 163 of file C-atomic-rwlock.c.

References C◼atomic◼compare_exchange_weak, and C◼atomic◼rwlock◼HIGHBIT1.

163  {
164 #line 83 "/home/gustedt/build/cmod/C/C-atomic-rwlock.X"
165  unsigned used = lck→lck;
166  return (used < C◼atomic◼rwlock◼HIGHBIT1) ∧ C◼atomic◼compare_exchange_weak(&lck→lck, &used, used+1);
167 }
#define C◼atomic◼compare_exchange_weak(PTR, VAL, DES)
Definition: C-atomic.c:92
#define C◼atomic◼rwlock◼HIGHBIT1

§ C◼atomic◼rwlock◼trywrlock()

C◼atomic◼rwlock◼bool C◼atomic◼rwlock◼trywrlock ( C◼atomic◼rwlock lck)
inline

Definition at line 147 of file C-atomic-rwlock.c.

References C◼atomic◼compare_exchange_weak, and C◼atomic◼rwlock◼HIGHBIT.

147  {
148 #line 70 "/home/gustedt/build/cmod/C/C-atomic-rwlock.X"
149  signed used = 0;
151 }
#define C◼atomic◼compare_exchange_weak(PTR, VAL, DES)
Definition: C-atomic.c:92
#define C◼atomic◼rwlock◼HIGHBIT

§ C◼atomic◼rwlock◼unrdlock()

void C◼atomic◼rwlock◼unrdlock ( C◼atomic◼rwlock lck)
inline

Definition at line 169 of file C-atomic-rwlock.c.

Referenced by C◼mod◼demangle◼demangle—5().

169  {
170 #line 88 "/home/gustedt/build/cmod/C/C-atomic-rwlock.X"
171  lck→lck--;
172 }
+ Here is the caller graph for this function:

§ C◼atomic◼rwlock◼unwrlock()

void C◼atomic◼rwlock◼unwrlock ( C◼atomic◼rwlock lck)
inline

Definition at line 153 of file C-atomic-rwlock.c.

References C◼atomic◼rwlock◼HIGHBIT.

Referenced by C◼mod◼demangle◼atexit(), and C◼mod◼demangle◼set().

153  {
154 #line 75 "/home/gustedt/build/cmod/C/C-atomic-rwlock.X"
155  lck→lck ^= C◼atomic◼rwlock◼HIGHBIT;
156 }
#define C◼atomic◼rwlock◼HIGHBIT
+ Here is the caller graph for this function:

§ C◼atomic◼rwlock◼wrlock()

void C◼atomic◼rwlock◼wrlock ( C◼atomic◼rwlock lck)
inline

Definition at line 158 of file C-atomic-rwlock.c.

Referenced by C◼mod◼demangle◼atexit().

158  {
159 #line 79 "/home/gustedt/build/cmod/C/C-atomic-rwlock.X"
160  do { /* spin */ } while (¬C◼atomic◼rwlock◼trywrlock(lck));
161 }
+ Here is the caller graph for this function: