ftrylockfile.c\stdio\src - musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/stdio/ftrylockfile.c
blob: 56cccafdc19fc3d7f60d8ae123aa479d3905d6e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "stdio_impl.h"
#include "pthread_impl.h"
#include <limits.h>
int ftrylockfile(FILE *f)
{
	int tid = __pthread_self()->tid;
	if (f->lock == tid) {
		if (f->lockcount == LONG_MAX)
			return -1;
		f->lockcount++;
		return 0;
	}
	if (f->lock < 0) f->lock = 0;
	if (f->lock || a_cas(&f->lock, 0, tid))
		return -1;
	f->lockcount = 1;
	return 0;
}
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月14日 00:53:31 +0000

AltStyle によって変換されたページ (->オリジナル) /