Opened 19 years ago

Closed 19 years ago

#2019 closed patch (fixed)

Replace a tight loop with the use of a thread condition

Reported by: russell@… Owned by: Isaac Richards
Priority: minor Milestone: unknown
Component: mythtv Version: head
Severity: medium Keywords:
Cc: Ticket locked: no

Description

There are various places throughout the code that use a tight loop and a call to usleep() to wait for a certain condition. I have attached a patch that converts one of these cases to use a more efficient method, a thread condition.

In this case, the loop had two conditions it was waiting on. It was waiting on both the event thread to start and set the runMainLoop variable to true, and also that the errored variable was never set to true. However, there is no code path where errored could be set to true before runMainLoop is set to true, so the second part of that condition had no effect.

I am also available on IRC as "russellb".

Attachments (4)

eventloop_thread_condition.patch (1.3 KB) - added by russell@… 19 years ago.
thread_conditions.patch (4.0 KB) - added by russell@… 19 years ago.
thread_conditions_rev2.patch (6.2 KB) - added by russell@… 19 years ago.
thread_conditions_rev3.patch (7.9 KB) - added by russell@… 19 years ago.

Download all attachments as: .zip

Change History (8)

Changed 19 years ago by russell@…

Changed 19 years ago by russell@…

Attachment: thread_conditions.patch added

comment:1 Changed 19 years ago by russell@…

I have attached a new patch which includes the changes in tickets #2021 and #2022 as well as the original changes from this ticket. The new changes address the same issues described here in RingBuffer? and AnalogScan?, so I figured it made sense to merge them all into the same patch.

Changed 19 years ago by russell@…

comment:2 Changed 19 years ago by russell@…

I have attached an updated patch (thread_conditions_rev2.patch) that includes a few more thread synchronization related changes.

In libs/libmythtv/tv_play.cpp: I changed a check of locked() and then a call to lock() on a QMutex to the equivalent use of tryLock(). I also fixed the indentation of 4 lines to match the coding guidelines. They were indented by an extra space.

In programs/mythfrontend/networkcontrol: I have elimated the need for the variables runCommandThread and commandThreadRunning and the use of a tight loop. In fact, the loop that was checking commandThreadRunning wasn't needed in the first place, because the call to pthread_join would automatically block and do the same thing without a busy wait.

Changed 19 years ago by russell@…

comment:3 Changed 19 years ago by russell@…

Update patch attached that includes similar changes for jobqueue.cpp

comment:4 Changed 19 years ago by Isaac Richards

Resolution: fixed
Status: newclosed

(In [10540]) Various poll -> waitcondition patch.

Closes #2019.

Note: See TracTickets for help on using tickets.