File tree Expand file tree Collapse file tree
fullstack/freertos-wolfip-wolfssl-https Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ set(FREERTOS_SOURCES
2626 ${CMAKE_CURRENT_SOURCE_DIR} /freertos/FreeRTOS-Kernel/stream_buffer.c
2727 ${FREERTOS_PORT_DIR} /port.c
2828 ${FREERTOS_HEAP_DIR} /heap_3.c
29+ ${CMAKE_CURRENT_SOURCE_DIR} /freertos/utils/utils.c
2930)
3031
3132# Add the main application
Original file line number Diff line number Diff line change 1+ #include <errno.h>
2+ #include <pthread.h>
3+ #include <signal.h>
4+ #include <stdio.h>
5+ #include <stdlib.h>
6+ #include <unistd.h>
7+
8+ typedef struct event_t {
9+ pthread_mutex_t mutex ;
10+ pthread_cond_t cond ;
11+ int value ;
12+ } event_t ;
13+
14+ event_t * event_create (void ) {
15+ event_t * event = malloc (sizeof (event_t ));
16+ if (event != NULL ) {
17+ pthread_mutex_init (& event -> mutex , NULL );
18+ pthread_cond_init (& event -> cond , NULL );
19+ event -> value = 0 ;
20+ }
21+ return event ;
22+ }
23+
24+ void event_delete (event_t * event ) {
25+ if (event != NULL ) {
26+ pthread_mutex_destroy (& event -> mutex );
27+ pthread_cond_destroy (& event -> cond );
28+ free (event );
29+ }
30+ }
31+
32+ void event_signal (event_t * event ) {
33+ if (event != NULL ) {
34+ pthread_mutex_lock (& event -> mutex );
35+ event -> value = 1 ;
36+ pthread_cond_signal (& event -> cond );
37+ pthread_mutex_unlock (& event -> mutex );
38+ }
39+ }
40+
41+ void event_wait (event_t * event ) {
42+ if (event != NULL ) {
43+ pthread_mutex_lock (& event -> mutex );
44+ while (event -> value == 0 ) {
45+ pthread_cond_wait (& event -> cond , & event -> mutex );
46+ }
47+ event -> value = 0 ;
48+ pthread_mutex_unlock (& event -> mutex );
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments