8 #include <TCondition.h>
10 class CommandQueue : public TObject
13 class Command : public TObject
17 TCondition *fAwakeCond; // awake thread after command executed
19 Command(const TString& cmd, TCondition* cond) : fCommand(cmd), fAwakeCond(cond) {}
21 ClassDef(Command, 0); // An entry in the command-queue.
27 Bool_t fQueueTimerSet;
31 fQueueTimer.Connect("Timeout()", "CommandQueue", this, "ProcessQueue()");
32 fQueueTimerSet = kFALSE;
35 // Destructor, cleanup missing.
37 //--------------------------------
39 void RegisterCommand(const TString& cmd, TCondition* cond=0)
42 fQueue.Add(new Command(cmd, cond));
43 if (!fQueueTimerSet) {
44 // Force execution in main thread when it is free.
45 fQueueTimer.Start(0, kTRUE);
46 fQueueTimerSet = kTRUE;
51 virtual void ProcessQueue()
53 Int_t n_proccessed = 0;
57 Command* c = (Command*) fQueue.First();
61 { // Put this into virtual void ProcessComand(Command*);
62 // Need also exception handling.
63 gROOT->ProcessLineFast(c->fCommand);
65 if (c->fAwakeCond != 0) {
66 c->fAwakeCond->GetMutex()->Lock();
67 c->fAwakeCond->Signal();
68 c->fAwakeCond->GetMutex()->UnLock();
74 if (fQueue.IsEmpty()) {
75 fQueueTimerSet = kFALSE;
82 printf("CommandQueue::ProcessQueue() processed %d commands.\n", n_proccessed);
85 ClassDef(CommandQueue,0); // Command queue for exection in global CINT context.
88 //=============================================================================
90 //=============================================================================
92 CommandQueue* g_cmd_queue = 0;
96 g_cmd_queue = new CommandQueue;
97 printf("Starting command-queue ...\n");
100 // ============================================================================
102 // ============================================================================
104 #include <Reve/Reve.h>
105 #include <Reve/ReveManager.h>
106 #include <Reve/PointSet.h>
110 void make_crap(void* arg)
115 Reve::PointSet* ps = new Reve::PointSet("Testus", num);
116 for (Int_t i=0; i<num; ++i) {
117 ps->SetNextPoint(rnd.Uniform(-100, 100),
118 rnd.Uniform(-100, 100),
119 rnd.Uniform(-100, 100));
121 ps->SetMainColor((Color_t)kRed);
122 printf("make_crap() -> produced Reve::PointSet* %p)\n", ps);
124 ((CommandQueue*)arg)->RegisterCommand
125 (Form("register_crap((Reve::RenderElement*)0x%lx)", ps));
128 void register_crap(Reve::RenderElement* el)
130 printf("register_crap(Reve::RenderElement* %p)\n", el);
131 gReve->AddRenderElement(el);
137 TThread* thr = new TThread(make_crap, g_cmd_queue);