2012-03-19 35 views
1

Android源代码中的很多函数都有以LI,LPw,LPr结尾的特殊名称。有没有人知道这些缩写词的意思,因为它会更有助于理解函数名称和目的。Android源代码函数特有名称

实施例:

PackageManagerService.installPackageLI()
PackageManagerService.updatePermissionsLPw()
Settings.peekPackageLPr()

感谢。

+0

你有什么具体的例子吗? – 2012-03-19 19:29:00

+0

@TylerTreat请参阅编辑问题 – Jake 2012-03-19 19:34:51

回答

1

看行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(); 
+0

这是第一次发生LI ... – Snicolas 2012-03-19 19:38:38

1

看起来你正在看一些奇怪的源代码。你知道吗grepcode

+0

作为@Tyler的示例Treat Treat – Snicolas 2012-03-19 19:35:09

0

的LPr意味着读取访问mPackages
LPW指写访问mPackages

http://androidxref.com/4.0.3_r1/xref/frameworks/base/services/java/com/android/server/pm/PackageManagerService.java#293

// 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>(); 
0

已经有一个公认的答案,但我假设以下信息将对其他用户有所帮助。只是想了解: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