diff options
author | irungentoo <irungentoo@gmail.com> | 2014-11-29 16:09:24 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-11-29 16:09:24 -0500 |
commit | 8deb032b2d9a77465a3c2b65a409787098e387cd (patch) | |
tree | 785fc1b1b975b712bb9a375af386f4de18f89663 /toxcore/util.c | |
parent | eafe0e6b0b83b4db3d79a9416d8aa33318fb12a7 (diff) | |
parent | e62ded3a6dfc1203418e3d7a2c936794c4c9ec1c (diff) |
Merge branch 'mutex-1' of https://github.com/mannol/toxcore
Diffstat (limited to 'toxcore/util.c')
-rw-r--r-- | toxcore/util.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/toxcore/util.c b/toxcore/util.c index 3d444b07..93e63ac2 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -162,3 +162,22 @@ int load_state(load_state_callback_func load_state_callback, void *outer, | |||
162 | 162 | ||
163 | return length == 0 ? 0 : -1; | 163 | return length == 0 ? 0 : -1; |
164 | }; | 164 | }; |
165 | |||
166 | int create_recursive_mutex(pthread_mutex_t *mutex) | ||
167 | { | ||
168 | pthread_mutexattr_t attr; | ||
169 | |||
170 | if (pthread_mutexattr_init(&attr) != 0) | ||
171 | return -1; | ||
172 | |||
173 | if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) | ||
174 | return -1; | ||
175 | |||
176 | /* Create queue mutex */ | ||
177 | if (pthread_mutex_init(mutex, &attr) != 0) | ||
178 | return -1; | ||
179 | |||
180 | pthread_mutexattr_destroy(&attr); | ||
181 | |||
182 | return 0; | ||
183 | } | ||