agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
task_mutex.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 ykat UG (haftungsbeschraenkt) - All Rights Reserved
3  *
4  * Permission for non-commercial use is hereby granted,
5  * free of charge, without warranty of any kind.
6  */
7 #ifndef ZRTOS_TASK_MUTEX_H
8 #define ZRTOS_TASK_MUTEX_H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 
14 #include <zrtos/zrtos.h>
15 #include <zrtos/error.h>
16 
17 
18 typedef struct _zrtos_task_mutex_t{
19  bool is_locked;
21 
22 #define ZRTOS_TASK_MUTEX__INITIALIZER {.is_locked = 0}
23 
25  thiz->is_locked = false;
26  return true;
27 }
28 
30 
31 }
32 
34  int ret = ZRTOS_ERROR__BUSY;
36  if(thiz->is_locked == false){
37  thiz->is_locked = true;
38  ret = 0;
39  }
40  });
41  return ret;
42 }
43 
45  bool ret = true;
46  bool is_locked;
47  uint8_t limit = 0xFF;
48  do{
50  if(thiz->is_locked == false){
51  thiz->is_locked = true;
52  ret = false;
53  }
54  });
55  if(ret){
57  }
58  }while(ret && !is_locked && limit--);
59  return ret;
60 }
61 
64  thiz->is_locked = false;
65  });
66  return 0;
67 }
68 
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 #endif
#define ZRTOS_TASK_SCHEDULER__DO_NOT_DISTURB(code)
int zrtos_task_mutex__try_lock(zrtos_task_mutex_t *thiz)
Definition: task_mutex.h:33
#define ZRTOS_TASK_SCHEDULER__DO_NOT_DISTURB_EX(is_locked, code)
void zrtos_task_mutex__deinit(zrtos_task_mutex_t *thiz)
Definition: task_mutex.h:29
int zrtos_task_mutex__unlock(zrtos_task_mutex_t *thiz)
Definition: task_mutex.h:62
int zrtos_task_mutex__lock(zrtos_task_mutex_t *thiz)
Definition: task_mutex.h:44
bool zrtos_task_mutex__init(zrtos_task_mutex_t *thiz)
Definition: task_mutex.h:24
Device or resource busy.
Definition: error.h:40
void zrtos_task_scheduler__delay_ms(zrtos_task_tick_t ms)
static uint8_t
Definition: mcp2515.h:159
struct _zrtos_task_mutex_t zrtos_task_mutex_t