File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,10 @@ struct os_mutex_t;
27
27
28
28
typedef struct os_mutex_t os_mutex_t ;
29
29
30
+ size_t util_mutex_get_size (void );
31
+ os_mutex_t * util_mutex_init (void * ptr );
30
32
os_mutex_t * util_mutex_create (void );
33
+ void util_mutex_destroy_not_free (os_mutex_t * m );
31
34
void util_mutex_destroy (os_mutex_t * mutex );
32
35
int util_mutex_lock (os_mutex_t * mutex );
33
36
int util_mutex_unlock (os_mutex_t * mutex );
Original file line number Diff line number Diff line change 12
12
13
13
#include "utils_concurrency.h"
14
14
15
- os_mutex_t * util_mutex_create (void ) {
16
- pthread_mutex_t * mutex = (pthread_mutex_t * )malloc (sizeof (pthread_mutex_t ));
15
+ size_t util_mutex_get_size (void ) { return sizeof (pthread_mutex_t ); }
16
+
17
+ os_mutex_t * util_mutex_init (void * ptr ) {
18
+ pthread_mutex_t * mutex = (pthread_mutex_t * )ptr ;
17
19
int ret = pthread_mutex_init (mutex , NULL );
18
20
return ret == 0 ? ((os_mutex_t * )mutex ) : NULL ;
19
21
}
20
22
21
- void util_mutex_destroy (os_mutex_t * m ) {
23
+ os_mutex_t * util_mutex_create (void ) {
24
+ return util_mutex_init (malloc (util_mutex_get_size ()));
25
+ }
26
+
27
+ void util_mutex_destroy_not_free (os_mutex_t * m ) {
22
28
pthread_mutex_t * mutex = (pthread_mutex_t * )m ;
23
29
int ret = pthread_mutex_destroy (mutex );
24
30
(void )ret ; // TODO: add logging
31
+ }
32
+
33
+ void util_mutex_destroy (os_mutex_t * m ) {
34
+ util_mutex_destroy_not_free (m );
25
35
free (m );
26
36
}
27
37
Original file line number Diff line number Diff line change @@ -13,18 +13,27 @@ typedef struct {
13
13
CRITICAL_SECTION lock ;
14
14
} internal_os_mutex_t ;
15
15
16
- os_mutex_t * util_mutex_create (void ) {
17
- internal_os_mutex_t * mutex_internal =
18
- (internal_os_mutex_t * )calloc (1 , sizeof (internal_os_mutex_t ));
16
+ size_t util_mutex_get_size (void ) { return sizeof (internal_os_mutex_t ); }
17
+
18
+ os_mutex_t * util_mutex_init (void * ptr ) {
19
+ internal_os_mutex_t * mutex_internal = (internal_os_mutex_t * )ptr ;
19
20
InitializeCriticalSection (& mutex_internal -> lock );
20
21
return (os_mutex_t * )mutex_internal ;
21
22
}
22
23
23
- void util_mutex_destroy (os_mutex_t * mutex ) {
24
+ os_mutex_t * util_mutex_create (void ) {
25
+ return util_mutex_init (calloc (1 , util_mutex_get_size ()));
26
+ }
27
+
28
+ void util_mutex_destroy_not_free (os_mutex_t * mutex ) {
24
29
internal_os_mutex_t * mutex_internal = (internal_os_mutex_t * )mutex ;
25
30
DeleteCriticalSection (& mutex_internal -> lock );
26
31
}
27
32
33
+ void util_mutex_destroy (os_mutex_t * mutex ) {
34
+ util_mutex_destroy_not_free (mutex );
35
+ }
36
+
28
37
int util_mutex_lock (os_mutex_t * mutex ) {
29
38
internal_os_mutex_t * mutex_internal = (internal_os_mutex_t * )mutex ;
30
39
EnterCriticalSection (& mutex_internal -> lock );
You can’t perform that action at this time.
0 commit comments