Page MenuHomePhabricator

Implement flock for Windows in compiler-rt

Authored by marco-c on Oct 13 2017, 9:27 AM.


Diff Detail

Event Timeline

marco-c created this revision.Oct 13 2017, 9:27 AM
zturner edited subscribers, added: llvm-commits, zturner; removed: dberris.Oct 13 2017, 9:43 AM
zturner added inline comments.

There is a subtle incompatibility here. If fd was originally opened for asynchronous IO, then this function will return immediately. This is basically the same as if you had called flock with LOCK_NB, but the difference is that with flock, the caller has to opt into it, where as with LockFileEx, it's an inherent property of the file descriptor.

Actually, it's a bit more than just a semantic difference. Since the function will return immediately, the OS will be holding onto destroyed stack memory (i.e. the OVERLAPPED structure).

I don't know if you want to handle this, but you should at least be aware, and perhaps leave a comment.


I know you're only implementing part of the functionality, but why not all? Seems easy enough to handle LOCK_SH, just change LOCKFILE_EXCLUSIVE_LOCK to LOCKFILE_SHARED_LOCK and the code is the same.

rnk added a subscriber: rnk.Oct 13 2017, 9:47 AM
marco-c updated this revision to Diff 119229.Oct 16 2017, 4:39 PM
marco-c retitled this revision from Implement part of the flock functionality for Windows in compiler-rt to Implement flock for Windows in compiler-rt.
marco-c edited the summary of this revision. (Show Details)
marco-c edited reviewers, added: zturner; removed: slingn.

Updated patch to handle asynchronous I/O case and to implement all flock functionality as suggested.

It's better to implement it in its entirety and correctly handling all cases, otherwise problems in the future could be hard to debug, especially since we are talking about locking.

zturner accepted this revision.Nov 8 2017, 9:18 AM
This revision is now accepted and ready to land.Nov 8 2017, 9:18 AM
marco-c closed this revision.Nov 8 2017, 11:12 AM
marco-c marked 2 inline comments as done.