diff options
Diffstat (limited to 'toxcore/util.c')
-rw-r--r-- | toxcore/util.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/toxcore/util.c b/toxcore/util.c index 7b715990..efb35ef2 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -40,8 +40,9 @@ static uint64_t unix_base_time_value; | |||
40 | 40 | ||
41 | void unix_time_update() | 41 | void unix_time_update() |
42 | { | 42 | { |
43 | if (unix_base_time_value == 0) | 43 | if (unix_base_time_value == 0) { |
44 | unix_base_time_value = ((uint64_t)time(NULL) - (current_time_monotonic() / 1000ULL)); | 44 | unix_base_time_value = ((uint64_t)time(NULL) - (current_time_monotonic() / 1000ULL)); |
45 | } | ||
45 | 46 | ||
46 | unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value; | 47 | unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value; |
47 | } | 48 | } |
@@ -160,8 +161,9 @@ int load_state(load_state_callback_func load_state_callback, void *outer, | |||
160 | } | 161 | } |
161 | 162 | ||
162 | /* -2 means end of save. */ | 163 | /* -2 means end of save. */ |
163 | if (ret == -2) | 164 | if (ret == -2) { |
164 | return 0; | 165 | return 0; |
166 | } | ||
165 | 167 | ||
166 | data += length_sub; | 168 | data += length_sub; |
167 | length -= length_sub; | 169 | length -= length_sub; |
@@ -174,8 +176,9 @@ int create_recursive_mutex(pthread_mutex_t *mutex) | |||
174 | { | 176 | { |
175 | pthread_mutexattr_t attr; | 177 | pthread_mutexattr_t attr; |
176 | 178 | ||
177 | if (pthread_mutexattr_init(&attr) != 0) | 179 | if (pthread_mutexattr_init(&attr) != 0) { |
178 | return -1; | 180 | return -1; |
181 | } | ||
179 | 182 | ||
180 | if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) { | 183 | if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) { |
181 | pthread_mutexattr_destroy(&attr); | 184 | pthread_mutexattr_destroy(&attr); |
@@ -213,14 +216,16 @@ void *rb_write(RingBuffer *b, void *p) | |||
213 | { | 216 | { |
214 | void *rc = NULL; | 217 | void *rc = NULL; |
215 | 218 | ||
216 | if ((b->end + 1) % b->size == b->start) /* full */ | 219 | if ((b->end + 1) % b->size == b->start) { /* full */ |
217 | rc = b->data[b->start]; | 220 | rc = b->data[b->start]; |
221 | } | ||
218 | 222 | ||
219 | b->data[b->end] = p; | 223 | b->data[b->end] = p; |
220 | b->end = (b->end + 1) % b->size; | 224 | b->end = (b->end + 1) % b->size; |
221 | 225 | ||
222 | if (b->end == b->start) | 226 | if (b->end == b->start) { |
223 | b->start = (b->start + 1) % b->size; | 227 | b->start = (b->start + 1) % b->size; |
228 | } | ||
224 | 229 | ||
225 | return rc; | 230 | return rc; |
226 | } | 231 | } |
@@ -239,7 +244,9 @@ RingBuffer *rb_new(int size) | |||
239 | { | 244 | { |
240 | RingBuffer *buf = calloc(sizeof(RingBuffer), 1); | 245 | RingBuffer *buf = calloc(sizeof(RingBuffer), 1); |
241 | 246 | ||
242 | if (!buf) return NULL; | 247 | if (!buf) { |
248 | return NULL; | ||
249 | } | ||
243 | 250 | ||
244 | buf->size = size + 1; /* include empty elem */ | 251 | buf->size = size + 1; /* include empty elem */ |
245 | 252 | ||
@@ -259,8 +266,9 @@ void rb_kill(RingBuffer *b) | |||
259 | } | 266 | } |
260 | uint16_t rb_size(const RingBuffer *b) | 267 | uint16_t rb_size(const RingBuffer *b) |
261 | { | 268 | { |
262 | if (rb_empty(b)) | 269 | if (rb_empty(b)) { |
263 | return 0; | 270 | return 0; |
271 | } | ||
264 | 272 | ||
265 | return | 273 | return |
266 | b->end > b->start ? | 274 | b->end > b->start ? |
@@ -271,8 +279,9 @@ uint16_t rb_data(const RingBuffer *b, void **dest) | |||
271 | { | 279 | { |
272 | uint16_t i = 0; | 280 | uint16_t i = 0; |
273 | 281 | ||
274 | for (; i < rb_size(b); i++) | 282 | for (; i < rb_size(b); i++) { |
275 | dest[i] = b->data[(b->start + i) % b->size]; | 283 | dest[i] = b->data[(b->start + i) % b->size]; |
284 | } | ||
276 | 285 | ||
277 | return i; | 286 | return i; |
278 | } | 287 | } |