Closed Bug 504006 Opened 17 years ago Closed 11 years ago

Remove PRMonitor* nsEventQueue::Monitor()

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1195767

People

(Reporter: mozilla+ben, Unassigned)

References

Details

Attachments

(1 obsolete file)

At least the comment makes no secret of this blatant encapsulation violation: // Expose the event queue's monitor for "power users" PRMonitor *Monitor() { return mMonitor; } nsThreadPool uses it, but only because it doesn't want to create a monitor of its own, as far as I can tell.
Attachment #388390 - Flags: superreview?(jst)
Attachment #388390 - Flags: review?(bent.mozilla)
Comment on attachment 388390 [details] [diff] [review] First stab at cleaning up this travesty This is more in bsmedberg's area than mine, moving sr request.
Attachment #388390 - Flags: superreview?(jst) → superreview?(benjamin)
Attachment #388390 - Attachment is obsolete: true
Attachment #388390 - Flags: superreview?(benjamin)
Attachment #388390 - Flags: review?(bent.mozilla)
Comment on attachment 388390 [details] [diff] [review] First stab at cleaning up this travesty I see now why the thread pool was sharing the event queue's monitor: it holds the monitor's lock when it calls GetEvent. If I give the thread pool its own lock, I have to avoid holding it while calling event queue methods. I think this can be done, but the current patch does it incorrectly. Marking obsolete for now; nevertheless, comments are welcome.
(In reply to comment #3) > (From update of attachment 388390 [details] [diff] [review]) > I see now why the thread pool was sharing the event queue's monitor: it holds > the monitor's lock when it calls GetEvent. OTOH, the nsThreadPool calls nsEventQueue::GetPendingEvent, which passes PR_FALSE for the mayWait parameter of nsEventQueue::GetEvent. Even if the locks nest, at least the event queue's monitor is never Wait()ed on while the thread pool is holding a lock. That might mitigate the concerns of comment #3.
My current thoughts: leave nsEventQueue::Monitor() but replace acquisitions of the monitor by nsEventQueue methods with assertions that the monitor is held by the current thread (mozilla::Monitor::AssertCurrentThreadIn). This pushes all responsibility for synchronization onto the client, but prevents the client from forgetting to take this responsibility. Benjamin S., I think I've heard you complain that "thread safe" data structures provide false guarantees. Inter-method synchronization invariants can only really be enforced by the client, so per-method locking is an invitation to misuse. Do you still feel this way? Do you think the above idea helps in this regard?
Assignee: mozilla+ben → nobody
Component: General → XPCOM
QA Contact: general → xpcom
Bug 1195767 tackled some refactoring of nsEventQueue, and it was easy enough to fix this bug over there.
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: