Open
Bug 1323482
Opened 8 years ago
Updated 2 years ago
NewRunnableMethod with nsMainThreadPtrHandle
Categories
(Core :: XPCOM, defect, P3)
Core
XPCOM
Tracking
()
NEW
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);
}
Comment 1•8 years ago
|
||
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)
Reporter | ||
Comment 2•8 years ago
|
||
(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)
Comment 3•8 years ago
|
||
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)
Reporter | ||
Updated•8 years ago
|
Assignee: nobody → catalin.badea392
Flags: needinfo?(catalin.badea392)
Updated•7 years ago
|
Priority: -- → P3
Reporter | ||
Updated•7 years ago
|
Assignee: catalin.badea392 → nobody
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•