2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
16 #include <TCondition.h>
18 class CommandQueue : public TObject
21 class Command : public TObject
25 TCondition *fAwakeCond; // awake thread after command executed
27 Command(const TString& cmd, TCondition* cond) : fCommand(cmd), fAwakeCond(cond) {}
29 ClassDef(Command, 0); // An entry in the command-queue.
35 Bool_t fQueueTimerSet;
39 fQueueTimer.Connect("Timeout()", "CommandQueue", this, "ProcessQueue()");
40 fQueueTimerSet = kFALSE;
43 // Destructor, cleanup missing.
45 //--------------------------------
47 void RegisterCommand(const TString& cmd, TCondition* cond=0)
50 fQueue.Add(new Command(cmd, cond));
51 if (!fQueueTimerSet) {
52 // Force execution in main thread when it is free.
53 fQueueTimer.Start(0, kTRUE);
54 fQueueTimerSet = kTRUE;
59 virtual void ProcessQueue()
61 Int_t n_proccessed = 0;
65 Command* c = (Command*) fQueue.First();
69 { // Put this into virtual void ProcessComand(Command*);
70 // Need also exception handling.
71 gROOT->ProcessLineFast(c->fCommand);
73 if (c->fAwakeCond != 0) {
74 c->fAwakeCond->GetMutex()->Lock();
75 c->fAwakeCond->Signal();
76 c->fAwakeCond->GetMutex()->UnLock();
82 if (fQueue.IsEmpty()) {
83 fQueueTimerSet = kFALSE;
90 printf("CommandQueue::ProcessQueue() processed %d commands.\n", n_proccessed);
93 ClassDef(CommandQueue,0); // Command queue for exection in global CINT context.
96 //=============================================================================
98 //=============================================================================
100 CommandQueue* g_cmd_queue = 0;
104 g_cmd_queue = new CommandQueue;
105 printf("Starting command-queue ...\n");
108 // ============================================================================
110 // ============================================================================
113 #include <TEveManager.h>
114 #include <TEvePointSet.h>
118 void make_crap(void* arg)
123 TEvePointSet* ps = new TEvePointSet("Testus", num);
124 for (Int_t i=0; i<num; ++i) {
125 ps->SetNextPoint(rnd.Uniform(-100, 100),
126 rnd.Uniform(-100, 100),
127 rnd.Uniform(-100, 100));
129 ps->SetMainColor(kRed);
130 printf("make_crap() -> produced TEvePointSet* %p)\n", ps);
132 ((CommandQueue*)arg)->RegisterCommand
133 (Form("register_crap((TEveElement*)0x%lx)", ps));
136 void register_crap(TEveElement* el)
138 printf("register_crap(TEveElement* %p)\n", el);
139 gEve->AddElement(el);
145 TThread* thr = new TThread(make_crap, g_cmd_queue);