Lines Matching +full:sync +full:- +full:write

1 //===-- tsan_fd.cpp -------------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
31 FdSync *sync; member
32 // This is used to establish write -> epoll_wait synchronization
33 // where epoll_wait receives notification about the write.
59 atomic_store(&s->rc, 1, memory_order_relaxed); in allocsync()
64 if (s && atomic_load(&s->rc, memory_order_relaxed) != (u64)-1) in ref()
65 atomic_fetch_add(&s->rc, 1, memory_order_relaxed); in ref()
70 if (s && atomic_load(&s->rc, memory_order_relaxed) != (u64)-1) { in unref()
71 if (atomic_fetch_sub(&s->rc, 1, memory_order_acq_rel) == 1) { in unref()
102 bool write = true) { in init() argument
106 if (d->sync) { in init()
107 unref(thr, pc, d->sync); in init()
108 d->sync = 0; in init()
112 atomic_load(&d->aux_sync, memory_order_relaxed))); in init()
113 atomic_store(&d->aux_sync, 0, memory_order_relaxed); in init()
114 if (flags()->io_sync == 0) { in init()
116 } else if (flags()->io_sync == 1) { in init()
117 d->sync = s; in init()
118 } else if (flags()->io_sync == 2) { in init()
120 d->sync = &fdctx.globsync; in init()
122 d->creation_tid = thr->tid; in init()
123 d->creation_stack = CurrentStackId(thr, pc); in init()
124 d->closed = false; in init()
130 if (write) { in init()
134 // See the dup-related comment in FdClose. in init()
140 atomic_store(&fdctx.globsync.rc, (u64)-1, memory_order_relaxed); in FdInit()
141 atomic_store(&fdctx.filesync.rc, (u64)-1, memory_order_relaxed); in FdInit()
142 atomic_store(&fdctx.socksync.rc, (u64)-1, memory_order_relaxed); in FdInit()
147 // close all them, and that will cause races between previous read/write in FdOnFork()
166 int l2 = (addr - (uptr)tab) / sizeof(FdDesc); in FdLocation()
169 *tid = d->creation_tid; in FdLocation()
170 *stack = d->creation_stack; in FdLocation()
171 *closed = d->closed; in FdLocation()
182 FdSync *s = d->sync; in FdAcquire()
183 DPrintf("#%d: FdAcquire(%d) -> %p\n", thr->tid, fd, s); in FdAcquire()
193 FdSync *s = d->sync; in FdRelease()
194 DPrintf("#%d: FdRelease(%d) -> %p\n", thr->tid, fd, s); in FdRelease()
198 if (uptr aux_sync = atomic_load(&d->aux_sync, memory_order_acquire)) in FdRelease()
203 DPrintf("#%d: FdAccess(%d)\n", thr->tid, fd); in FdAccess()
210 void FdClose(ThreadState *thr, uptr pc, int fd, bool write) { in FdClose() argument
211 DPrintf("#%d: FdClose(%d)\n", thr->tid, fd); in FdClose()
220 if (write) { in FdClose()
226 // We do read instead of write because there is a number of legitimate in FdClose()
227 // cases where write would lead to false positives: in FdClose()
232 // On the other hand we have not seen cases when write here catches real in FdClose()
242 unref(thr, pc, d->sync); in FdClose()
243 d->sync = 0; in FdClose()
246 atomic_load(&d->aux_sync, memory_order_relaxed))); in FdClose()
247 atomic_store(&d->aux_sync, 0, memory_order_relaxed); in FdClose()
248 d->closed = true; in FdClose()
249 d->creation_tid = thr->tid; in FdClose()
250 d->creation_stack = CurrentStackId(thr, pc); in FdClose()
254 DPrintf("#%d: FdFileCreate(%d)\n", thr->tid, fd); in FdFileCreate()
260 void FdDup(ThreadState *thr, uptr pc, int oldfd, int newfd, bool write) { in FdDup() argument
261 DPrintf("#%d: FdDup(%d, %d)\n", thr->tid, oldfd, newfd); in FdDup()
267 FdClose(thr, pc, newfd, write); in FdDup()
268 init(thr, pc, newfd, ref(od->sync), write); in FdDup()
272 DPrintf("#%d: FdCreatePipe(%d, %d)\n", thr->tid, rfd, wfd); in FdPipeCreate()
280 DPrintf("#%d: FdEventCreate(%d)\n", thr->tid, fd); in FdEventCreate()
287 DPrintf("#%d: FdSignalCreate(%d)\n", thr->tid, fd); in FdSignalCreate()
294 DPrintf("#%d: FdInotifyCreate(%d)\n", thr->tid, fd); in FdInotifyCreate()
301 DPrintf("#%d: FdPollCreate(%d)\n", thr->tid, fd); in FdPollCreate()
308 DPrintf("#%d: FdPollAdd(%d, %d)\n", thr->tid, epfd, fd); in FdPollAdd()
319 if (atomic_load(&d->aux_sync, memory_order_relaxed)) in FdPollAdd()
322 FdSync *s = epd->sync; in FdPollAdd()
327 &d->aux_sync, &cmp, reinterpret_cast<uptr>(s), memory_order_release)) in FdPollAdd()
332 DPrintf("#%d: FdSocketCreate(%d)\n", thr->tid, fd); in FdSocketCreate()
340 DPrintf("#%d: FdSocketAccept(%d, %d)\n", thr->tid, fd, newfd); in FdSocketAccept()
343 // Synchronize connect->accept. in FdSocketAccept()
349 DPrintf("#%d: FdSocketConnecting(%d)\n", thr->tid, fd); in FdSocketConnecting()
352 // Synchronize connect->accept. in FdSocketConnecting()
357 DPrintf("#%d: FdSocketConnect(%d)\n", thr->tid, fd); in FdSocketConnect()