Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: vdr 1.3.18 cCondWait::SleepMs



Klaus Schmidinger wrote:
> Ludwig Nussel wrote:
> >Klaus Schmidinger wrote:
> >>Wherever it is feasible VDR does wait on conditions.
> >
> > [...]
> >-                 cCondWait::SleepMs(1); // this keeps the CPU load low
> >+                 playMode_condition.Wait(mutex);
> > [...]
> 
> Why so complicated?
> All that needs to be done is to wait a little while at this point,
> making sure the time slice will be given up. It doesn't really matter
> whether we wait 1, 2 or 3 milliseconds - even 10 would be ok here.

You said "Wherever it is feasible VDR does wait on conditions" which
obviously is not true in the above case. What has to be done here is
not to wait for time to pass but to wait for playmode to change. No
matter how long you make the sleep it will still be busy waiting. So
instead of causing useless context switches all the time (while
still holding the lock!) you can just suspend the execution of the
thread until Play() changes the playmode. A condition variable looks
exactly like the right tool for that job.

cu
Ludwig

-- 
(o_  Ludwig.Nussel@gmx.de
//\
V_/_ PGP Key ID: FF8135CE




Home | Main Index | Thread Index