mirror of
https://github.com/fluencelabs/musl
synced 2025-04-27 00:02:12 +00:00
19 lines
342 B
C
19 lines
342 B
C
|
#include "stdio_impl.h"
|
||
|
#include "pthread_impl.h"
|
||
|
|
||
|
int ftrylockfile(FILE *f)
|
||
|
{
|
||
|
libc.lockfile = __lockfile;
|
||
|
if (f->owner && f->owner == pthread_self()->tid) {
|
||
|
if (f->lockcount == INT_MAX)
|
||
|
return -1;
|
||
|
f->lockcount++;
|
||
|
return 0;
|
||
|
}
|
||
|
if (a_swap(&f->lock, 1))
|
||
|
return -1;
|
||
|
f->owner = pthread_self()->tid;
|
||
|
f->lockcount = 1;
|
||
|
return 0;
|
||
|
}
|