Mike Habicher於 2013年10月23日星期三UTC+8上午4時14分07秒寫道:
> Ref. Hal.cpp[0]
> 
> 
> 
> Each b2g process (parent or app) has a Main Thread[1]. These processes 
> 
> will have other threads as well, but many operations (such as layout, 
> 
> JS, and DOM) must take place on the Main Thread because they are not 
> 
> threadsafe. To make functions robust against being called from the wrong 
> 
> thread, it's common to use the following:
> 
>      MOZ_ASSERT(NS_IsMainThread());
> 
> 
> 
> NS_IsMainThread()[2] returns true if the currently executing thread is 
> 
> the Main Thread; and in DEBUG builds, MOZ_ASSERT()[3] will cause the 
> 
> current process to crash if its condition is false.
> 
> 
> 
> In Hal.cpp, this assertion is just wrapped up into a simple function.
> 
> 
> 
> --m.
> 
> 
> 
> 
> 
> 0. http://mxr.mozilla.org/mozilla-central/source/hal/Hal.cpp#76
> 
> 1. 
> 
> https://developer.mozilla.org/en-US/docs/XPCOM/Making_cross-thread_calls_using_runnables
> 
> 2. 
> 
> http://mxr.mozilla.org/mozilla-central/source/xpcom/glue/MainThreadUtils.h#35
> 
> 3. http://mxr.mozilla.org/mozilla-central/source/mfbt/Assertions.h#318
> 
> 
> 
> On 13-10-22 03:47 PM, [email protected] wrote:
> 
> > I noticed that in the Hal.cpp (gecko/hal/), there is always a function 
> > named AssertMainThread(); got called in the first line of each function. 
> > Such as SetTimezone or EnableSensorNotification.
> 
> >
> 
> > Can anyone explain this a bit why this function always there and how it 
> > works?
> 
> >
> 
> > Thanks
> 
> > _______________________________________________
> 
> > dev-b2g mailing list
> 
> > [email protected]
> 
> > https://lists.mozilla.org/listinfo/dev-b2g

Thanks Mike. This is very clear.
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to