5

I noticed that there are lots of use of the methods named '*Locked()' while I am looking through Android framework codes. I wonder what 'Locked' means and what features those methods are reflecting to.

For example, there are a number of methods named in such way in Activity related classes.

android/frameworks/base/services/java/com/android/server/am/ActivityStack.java

  • startActivityLocked()
  • ensureActivitiesVisibleLocked()
  • resumeTopActivityLocked()

Thank you for your help in advance! :)

CodePoetry
  • 61
  • 3

3 Answers3

2

That means the method is multithread-safe.

2

You can find code from ActivityManagerService.class like below:

synchronized (this) {
    dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, null);
}

or some code like that:

synchronized (this) {
    methodA();
}
methodA() {
    dumpActivitiesLocked(fd, pw, args, opti, true, dumpClient, null);
}

So the methods named *Locked means the method is not multithread-safe, in ActivityManagerService.class, you should use synchronized (this) make sure the multithread-safe.

DinoStray
  • 696
  • 1
  • 6
  • 20
0

Seems to me it means it requires being locked for MT-safe,

Here are some examples for both Java/C++ code,

http://androidxref.com/5.0.0_r2/xref/frameworks/base/core/java/android/app/ContextImpl.java#1007

http://androidxref.com/5.0.0_r2/xref/frameworks/minikin/libs/minikin/MinikinRefCounted.cpp#25

yongsun
  • 105
  • 7