mbed TLS v2.6.0
threading.h
Go to the documentation of this file.
1 
25 #ifndef MBEDTLS_THREADING_H
26 #define MBEDTLS_THREADING_H
27 
28 #if !defined(MBEDTLS_CONFIG_FILE)
29 #include "config.h"
30 #else
31 #include MBEDTLS_CONFIG_FILE
32 #endif
33 
34 #include <stdlib.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #define MBEDTLS_ERR_THREADING_FEATURE_UNAVAILABLE -0x001A
41 #define MBEDTLS_ERR_THREADING_BAD_INPUT_DATA -0x001C
42 #define MBEDTLS_ERR_THREADING_MUTEX_ERROR -0x001E
44 #if defined(MBEDTLS_THREADING_PTHREAD)
45 #include <pthread.h>
46 typedef struct
47 {
48  pthread_mutex_t mutex;
49  char is_valid;
50 } mbedtls_threading_mutex_t;
51 #endif
52 
53 #if defined(MBEDTLS_THREADING_ALT)
54 /* You should define the mbedtls_threading_mutex_t type in your header */
55 #include "threading_alt.h"
56 
75 void mbedtls_threading_set_alt( void (*mutex_init)( mbedtls_threading_mutex_t * ),
76  void (*mutex_free)( mbedtls_threading_mutex_t * ),
77  int (*mutex_lock)( mbedtls_threading_mutex_t * ),
78  int (*mutex_unlock)( mbedtls_threading_mutex_t * ) );
79 
83 void mbedtls_threading_free_alt( void );
84 #endif /* MBEDTLS_THREADING_ALT */
85 
86 #if defined(MBEDTLS_THREADING_C)
87 /*
88  * The function pointers for mutex_init, mutex_free, mutex_ and mutex_unlock
89  *
90  * All these functions are expected to work or the result will be undefined.
91  */
92 extern void (*mbedtls_mutex_init)( mbedtls_threading_mutex_t *mutex );
93 extern void (*mbedtls_mutex_free)( mbedtls_threading_mutex_t *mutex );
94 extern int (*mbedtls_mutex_lock)( mbedtls_threading_mutex_t *mutex );
95 extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
96 
97 /*
98  * Global mutexes
99  */
100 extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
101 extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
102 #endif /* MBEDTLS_THREADING_C */
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* threading.h */
Configuration options (set of defines)