lwpa  0.1.0
LightWeight Platform Abstraction (lwpa)
View other versions:
lwpa_lock.h
1 /******************************************************************************
2  * Copyright 2018 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************
16  * This file is a part of lwpa. For more information, go to:
17  * https://github.com/ETCLabs/lwpa
18  ******************************************************************************/
19 
20 #ifndef _LWPA_LOCK_H_
21 #define _LWPA_LOCK_H_
22 
23 #include "FreeRTOS.h"
24 #include "semphr.h"
25 #include "lwpa_common.h"
26 #include "lwpa_bool.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef SemaphoreHandle_t lwpa_mutex_t;
33 
35 bool lwpa_mutex_take(lwpa_mutex_t *id, int wait_ms);
38 
39 typedef SemaphoreHandle_t lwpa_signal_t;
40 
42 bool lwpa_signal_wait(lwpa_signal_t *id, int wait_ms);
45 
46 typedef struct
47 {
48  SemaphoreHandle_t sem;
49  unsigned int reader_count;
51 
53 bool lwpa_rwlock_readlock(lwpa_rwlock_t *id, int wait_ms);
55 bool lwpa_rwlock_writelock(lwpa_rwlock_t *id, int wait_ms);
58 
59 #ifdef __cplusplus
60 }
61 #endif
62 
63 #endif /* _LWPA_LOCK_H_ */
void lwpa_mutex_give(lwpa_mutex_t *id)
Release a mutex.
Definition: lwpa_lock.c:41
bool lwpa_mutex_create(lwpa_mutex_t *id)
Create a new mutex.
Definition: lwpa_lock.c:26
bool lwpa_mutex_take(lwpa_mutex_t *id, int wait_ms)
Acquire a mutex.
Definition: lwpa_lock.c:31
void lwpa_mutex_destroy(lwpa_mutex_t *id)
Destroy a mutex object.
Definition: lwpa_lock.c:47
UNDEFINED lwpa_mutex_t
The mutex identifier.
Definition: lwpa_lock.dox:38
bool lwpa_rwlock_writelock(lwpa_rwlock_t *id, int wait_ms)
Access a read-write lock for writing.
Definition: lwpa_lock.c:127
void lwpa_rwlock_writeunlock(lwpa_rwlock_t *id)
Release a write lock on a read-write lock object.
Definition: lwpa_lock.c:165
void lwpa_rwlock_destroy(lwpa_rwlock_t *id)
Destroy a read-write lock object.
Definition: lwpa_lock.c:171
UNDEFINED lwpa_rwlock_t
The read-write lock identifier.
Definition: lwpa_lock.dox:147
bool lwpa_rwlock_create(lwpa_rwlock_t *id)
Create a new read-write lock.
Definition: lwpa_lock.c:95
void lwpa_rwlock_readunlock(lwpa_rwlock_t *id)
Release a read lock on a read-write lock object.
Definition: lwpa_lock.c:121
bool lwpa_rwlock_readlock(lwpa_rwlock_t *id, int wait_ms)
Access a read-write lock for reading.
Definition: lwpa_lock.c:105
void lwpa_signal_destroy(lwpa_signal_t *id)
Destroy a signal object.
Definition: lwpa_lock.c:72
bool lwpa_signal_wait(lwpa_signal_t *id, int wait_ms)
Wait for a signal.
Definition: lwpa_lock.c:61
bool lwpa_signal_create(lwpa_signal_t *id)
Create a new signal.
Definition: lwpa_lock.c:56
UNDEFINED lwpa_signal_t
The signal identifier.
Definition: lwpa_lock.dox:83
void lwpa_signal_post(lwpa_signal_t *id)
Post a signal.
Definition: lwpa_lock.c:66
Definition: lwpa_lock.h:35
Definition: lwpa_lock.h:47