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: | 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)
Change History (8)
Changed 19 years ago by
Attachment: | eventloop_thread_condition.patch added |
---|
Changed 19 years ago by
Attachment: | thread_conditions.patch added |
---|
comment:1 Changed 19 years ago by
Changed 19 years ago by
Attachment: | thread_conditions_rev2.patch added |
---|
comment:2 Changed 19 years ago by
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
Attachment: | thread_conditions_rev3.patch added |
---|
comment:3 Changed 19 years ago by
Update patch attached that includes similar changes for jobqueue.cpp
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.