Android源代码函数的特殊名称
Android源代码中的许多函数都有以LI、LPw、LPr结尾的特殊名称。有人知道这些首字母缩略词是什么意思吗?因为理解函数名及其用途会更有帮助 例如: PackageManagerService.installPackageLI()Android源代码函数的特殊名称,android,function,Android,Function,Android源代码中的许多函数都有以LI、LPw、LPr结尾的特殊名称。有人知道这些首字母缩略词是什么意思吗?因为理解函数名及其用途会更有帮助 例如: PackageManagerService.installPackageLI() PackageManagerService.updatePermissionsLPw() Settings.peek-packagelpr() 谢谢。看起来您正在查看一些奇怪的源代码。你知道吗?看第234行: 234 // Lock for state u
PackageManagerService.updatePermissionsLPw()
Settings.peek-packagelpr()
谢谢。看起来您正在查看一些奇怪的源代码。你知道吗?看第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();
LPr表示对mPackages的读取权限
LPw表示对MPackage的写访问
//键是字符串(包名),值是包。这也有好处
//作为全局状态的锁。必须使用调用的方法
//持有的此锁具有前缀“LP”。
最终HashMap mPackages=
新的HashMap();
已经有一个公认的答案,但我认为以下信息对其他用户会有所帮助。我只是想了解LPr、LPw、LI和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
你有什么具体的例子吗?@TylerTreat请看编辑后的问题,举一个@Tyler Treat所说的例子
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