pthread_rwlock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 RenĂ© Kijewski <rene.kijewski@fu-berlin.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
17 #ifndef PTHREAD_RWLOCK_H
18 #define PTHREAD_RWLOCK_H
19 
20 #include "priority_queue.h"
21 #include "thread.h"
22 
23 #include <errno.h>
24 #include <stdbool.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
37 typedef struct
38 {
46  int readers;
47 
52 
58 
62 typedef struct {
63  bool is_writer;
66  bool continue_;
68 
78 
91 
100 
110 
119 int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
120 
129 
139 
148 int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
149 
160 
167 
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 #endif /* PTHREAD_RWLOCK_H */
180 
__pthread_rwlock_waiter_node_t::is_writer
bool is_writer
false: reader; true: writer
Definition: pthread_rwlock.h:63
__pthread_rwlock_waiter_node_t
Internal structure that stores one waiting thread.
Definition: pthread_rwlock.h:62
pthread_rwlock_tryrdlock
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
Try to lock a reader/writer lock for reader.
pthread_rwlock_unlock
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
Unlock the reader/writer lock.
pthread_rwlock_timedrdlock
int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime)
Try to acquire a read lock in a given timeframe.
priority_queue.h
A simple priority queue.
pthread_rwlock_rdlock
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
Lock a reader/writer lock for reading.
pthread_rwlock_t::queue
priority_queue_t queue
Queue of waiting threads.
Definition: pthread_rwlock.h:51
pthread_rwlock_t::mutex
mutex_t mutex
Provides mutual exclusion on reading and writing on the structure.
Definition: pthread_rwlock.h:56
pthread_rwlock_t::readers
int readers
The current amount of reader inside the critical section.
Definition: pthread_rwlock.h:46
__pthread_rwlock_waiter_node_t::thread
thread_t * thread
waiting thread
Definition: pthread_rwlock.h:64
pthread_rwlock_trywrlock
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
Try to lock a reader/writer lock for writing.
_thread
thread_t holds thread's context data.
Definition: thread.h:154
pthread_rwlock_t
A fair reader writer lock.
Definition: pthread_rwlock.h:37
pthread_rwlockattr_t
Attributes for a new reader/writer lock.
Definition: pthread_rwlock_attr.h:30
__pthread_rwlock_blocked_readingly
bool __pthread_rwlock_blocked_readingly(const pthread_rwlock_t *rwlock)
Internal function to determine of the lock can be acquired for reading.
pthread_rwlock_timedwrlock
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime)
Try to acquire a write lock in a given timeframe.
priority_queue_node
data type for priority queue nodes
Definition: priority_queue.h:32
pthread_rwlock_init
int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
Initialize a reader/writer lock.
__pthread_rwlock_waiter_node_t::continue_
bool continue_
This is not a spurious wakeup.
Definition: pthread_rwlock.h:66
pthread_rwlock_destroy
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
Destroy a reader/writer lock.
priority_queue_t
data type for priority queues
Definition: priority_queue.h:41
__pthread_rwlock_blocked_writingly
bool __pthread_rwlock_blocked_writingly(const pthread_rwlock_t *rwlock)
Internal function to determine of the lock can be acquired for writing.
__pthread_rwlock_waiter_node_t::qnode
priority_queue_node_t qnode
Node to store in pthread_rwlock_t::queue.
Definition: pthread_rwlock.h:65
errno.h
mutex_t
Mutex structure.
Definition: mutex.h:120
pthread_rwlock_wrlock
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
Lock a reader/writer lock for writing.