d670be7a08cb85329ff3b5e9039cda9ffa4a35a1 |
|
05-Apr-2012 |
Zonr Chang <zonr.net@gmail.com> |
Introduce InputFile/OutputFile and FileMutex. FileHandle is replaced with InputFile/OutputFile and FileMutex. Use InputFile when you want to open a file in read-only. USe OutputFile when you open a file for writing. Both of them provide a reliable way to access the files and perform the I/O operations. Given a name "foo", FileMutex creates a file named "foo.lock" and tries to acquire an advisory lock (flock) on this file. FileHandle, which uses the file it's openning for locking, may corrupt the file contents when two or more processes are trying to gain the lock for reading/writing. For example: Process #2 creates foo Process #1 opens foo Process #2 opens foo Process #2 locks foo (exclusively) (success) Process #1 locks foo (failed, retry #1) Process #2 starts writing foo Process #1 opens and truncates foo (note there’s O_TRUNC in the flag) Process #2 writes foo continually (foo is corrupted from now on ...) Process #1 locks foo (failed, retry #2) ... Process #1 locks foo (reach the max retries and return) Process #2 gets done on writing foo (foo is corrupted ...) Process #2 unlocks and closes foo (foo is corrupted)
/frameworks/compile/libbcc/lib/ExecutionEngine/FileHandle.h
|