Open Bug 1323482 Opened 8 years ago Updated 2 years ago

NewRunnableMethod with nsMainThreadPtrHandle

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

Tracking Status
firefox53 --- affected

People

(Reporter: catalinb, Unassigned)

References

Details

This is useful when the main thread posts a runnable to a worker thread and expects a callback. We use nsMainThreadPtrHandle to store the callback, but using NewRunnableMethod(mainThreadHandle, &Foo::Bar) on the worker thread will fail because nsRunnableMethodReceiver will try to addRef the object on the wrong thread. code example: class WorkerRunnable { nsMainThreadPtrHandle<Foo> mCallback; nsresult WorkerRun() { // Worker Thread nsCOMPtr<nsIRunnable> r = NewRunnableMethod(mCallback, &Foo::Bar); DispatchToMainThread(r); }
Oh, sorry, I think I misunderstood in our IRC conversation! Does: nsCOMPtr<nsIRunnable> r = NewNonOwningRunnableMethod(mCallback, &Foo::Bar); work? You'll have to make sure that mCallback outlives the runnable, of course.
Flags: needinfo?(catalin.badea392)
(In reply to Nathan Froyd [:froydnj] from comment #1) > Oh, sorry, I think I misunderstood in our IRC conversation! Does: > > nsCOMPtr<nsIRunnable> r = NewNonOwningRunnableMethod(mCallback, &Foo::Bar); > > work? You'll have to make sure that mCallback outlives the runnable, of > course. No, I want to pass the ownership of mCallback to the runnable created by NewRunnableMethod. As far as I can tell, the current code extracts the type of the object, then passes a ClassType* pointer to a nsRunnableMethodReceiver which stores it either as a raw pointer or a RefPtr. I need a version that stores it in a nsMainThreadPtrHandle (or some equivalent wrapper that guarantees release on the correct thread).
Flags: needinfo?(catalin.badea392)
Oh, oh, I see what you mean. OK, so nsRunnableMethodTraits would have to be extended to consider the type of the object we're passing in, not just the method type. You said you tried that already, do you have the patch available for examination? Might be simpler to start from what you have and go from there.
Component: IPC → XPCOM
Flags: needinfo?(catalin.badea392)
Assignee: nobody → catalin.badea392
Flags: needinfo?(catalin.badea392)
Depends on: 1329319
Priority: -- → P3
Assignee: catalin.badea392 → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.