Android源代碼中的很多函數都有以LI,LPw,LPr結尾的特殊名稱。有沒有人知道這些縮寫詞的意思,因爲它會更有助於理解函數名稱和目的。Android源代碼函數特有名稱
實施例:
PackageManagerService.installPackageLI()
PackageManagerService.updatePermissionsLPw()
Settings.peekPackageLPr()
感謝。
Android源代碼中的很多函數都有以LI,LPw,LPr結尾的特殊名稱。有沒有人知道這些縮寫詞的意思,因爲它會更有助於理解函數名稱和目的。Android源代碼函數特有名稱
實施例:
PackageManagerService.installPackageLI()
PackageManagerService.updatePermissionsLPw()
Settings.peekPackageLPr()
感謝。
看行234:
234 // Lock for state used when installing and doing other long running
235 // operations. Methods that must be called with this lock held have
236 // the prefix "LI".
237 final Object mInstallLock = new Object();
這是第一次發生LI ... – Snicolas 2012-03-19 19:38:38
的LPr意味着讀取訪問mPackages
LPW指寫訪問mPackages
// Keys are String (package name), values are Package. This also serves
// as the lock for the global state. Methods that must be called with
// this lock held have the prefix "LP".
final HashMap<String, PackageParser.Package> mPackages =
new HashMap<String, PackageParser.Package>();
已經有一個公認的答案,但我假設以下信息將對其他用戶有所幫助。只是想了解:LPR,LPW,李和LIF後綴,發現以下文件:
內部有兩個重要的鎖:
1) **mPackages** is used to guard all in-memory parsed package details
and other related state. It is a fine-grained lock that should only be
held momentarily, as it's one of the most contended locks in the system.
2) **mInstallLock** is used to guard all installd access, whose
operations typically involve heavy lifting of application data on disk.
Since installd is single-threaded, and it's operations can often be slow,
this lock should never be acquired while already holding mPackages .
Conversely, it's safe to acquire mPackages momentarily while already
holding mInstallLock.
Many internal methods rely on the caller to hold the appropriate locks, and
this contract is expressed through method name suffixes:
fooLI(): the caller must hold mInstallLock
fooLIF(): the caller must hold mInstallLock and the package being modified
must be frozen
fooLPr(): the caller must hold mPackages for reading
fooLPw(): the caller must hold mPackages for writing
你有什麼具體的例子嗎? – 2012-03-19 19:29:00
@TylerTreat請參閱編輯問題 – Jake 2012-03-19 19:34:51