ObjFW  Diff

Differences From Artifact [aa1078d8fa]:

To Artifact [a1aae6b58b]:


391
392
393
394
395
396
397

398
399
400
401
402
403
404
	if (pthread_mutexattr_destroy(&attr))
		return NO;

	return YES;
}

# define of_rmutex_lock of_mutex_lock

# define of_rmutex_unlock of_mutex_unlock
# define of_rmutex_free of_mutex_free
#else
static OF_INLINE BOOL
of_rmutex_new(of_rmutex_t *rmutex)
{
	if (!of_mutex_new(&rmutex->mutex))







>







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
	if (pthread_mutexattr_destroy(&attr))
		return NO;

	return YES;
}

# define of_rmutex_lock of_mutex_lock
# define of_rmutex_trylock of_mutex_trylock
# define of_rmutex_unlock of_mutex_unlock
# define of_rmutex_free of_mutex_free
#else
static OF_INLINE BOOL
of_rmutex_new(of_rmutex_t *rmutex)
{
	if (!of_mutex_new(&rmutex->mutex))
419
420
421
422
423
424
425






















426
427
428
429
430
431
432
		if (!of_tlskey_set(rmutex->count, (void*)(count + 1)))
			return NO;
		return YES;
	}

	if (!of_mutex_lock(&rmutex->mutex))
		return NO;























	if (!of_tlskey_set(rmutex->count, (void*)1)) {
		of_mutex_unlock(&rmutex->mutex);
		return NO;
	}

	return YES;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
		if (!of_tlskey_set(rmutex->count, (void*)(count + 1)))
			return NO;
		return YES;
	}

	if (!of_mutex_lock(&rmutex->mutex))
		return NO;

	if (!of_tlskey_set(rmutex->count, (void*)1)) {
		of_mutex_unlock(&rmutex->mutex);
		return NO;
	}

	return YES;
}

static OF_INLINE BOOL
of_rmutex_trylock(of_rmutex_t *rmutex)
{
	uintptr_t count = (uintptr_t)of_tlskey_get(rmutex->count);

	if (count > 0) {
		if (!of_tlskey_set(rmutex->count, (void*)(count + 1)))
			return NO;
		return YES;
	}

	if (!of_mutex_trylock(&rmutex->mutex))
		return NO;

	if (!of_tlskey_set(rmutex->count, (void*)1)) {
		of_mutex_unlock(&rmutex->mutex);
		return NO;
	}

	return YES;