Closed Bug 18116 Opened 25 years ago Closed 18 years ago

xpcom/threads: need all-in-one create/push function

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

RESOLVED INVALID
Future

People

(Reporter: dougt, Unassigned)

Details

The eventQ service should provide a routine which will create an EventQ if one
does not exist, or Push a new Event Q on the existing.

Here is what I have to do to get equivelant functionality:

//---------------------
//This block of code should be a function of the EventQueueServices
    NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID,
&rv);
    if (NS_FAILED(rv))
        return rv;

    nsCOMPtr<nsIEventQueue> eventQ;
    rv = eventQService->GetThreadEventQueue(PR_CurrentThread(),
getter_AddRefs(eventQ));
    if (NS_FAILED(rv))
    {
        rv = eventQService->CreateThreadEventQueue();
        eventLoopCreated = PR_TRUE;
        if (NS_FAILED(rv))
            return rv;

        rv = eventQService->GetThreadEventQueue(PR_CurrentThread(),
getter_AddRefs(eventQ));
    }
    else
    {
        eventQ = 0;
        rv = eventQService->PushThreadEventQueue(getter_AddRefs(eventQ));
    }

    if (NS_FAILED(rv))
        return rv;



There should also be an entry point which will either pop the pushed queue, or
delete it, similar to:

if (eventLoopCreated)
    {
         eventQService->DestroyThreadEventQueue();
         eventQ = 0;
    }
    else
    {
        nsIEventQueue *dumbAddref = eventQ;
        NS_ADDREF(dumbAddref);  // PopThreadEventQueue released the nsCOMPtr,
                                // then we crash while leaving this functions.
        eventQService->PopThreadEventQueue(dumbAddref);  // this is totally
evil
    }
Assignee: dp → dougt
Doug yours ?
sure.
Target Milestone: M16
would be nice, but not needed.  m16-bound
not required, but nice. moving to m20
Target Milestone: M16 → M20
Target Milestone: M20 → Future
2 
Assignee: dougt → danm
  I'm not sure we can do this. Several places in the code go through a well-
defined dance just to ensure the current thread has an event queue on it -- that 
could stand to be a single call -- but there are also a couple of places where we 
specifically want to push/pop a queue; not work with an extant one. I don't think 
we can deduce the correct behaviour from a single entry point API.
  At best it would result in a thicker stack of event queues, and the current 
implementation makes that inefficient. At worst it could result in queues stacked 
at unexpected times, which could stifle event processing in older queues. And a 
stacked queue needs special treatment when you're done with it -- it needs to be 
popped. Though that's probably no worse than an addref/release sequence.
  Of those three objections, the second is the only really scary one. But it is 
that.
dp is no longer @netscape.com. changing qa contact to default for this product
QA Contact: dp → kandrot
Assignee: danm.moz → dougt
QA Contact: kandrot
Assignee: dougt → nobody
QA Contact: xpcom
Marking INVALID.  Bug 326273 added support for automatic creation of a nsIThread objects on a thread that does not have one when the coder requests the current thread's nsIThread, and nsIThread extends nsIEventTarget.
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.