Remove some more unsafe calls to gettimeofday

It isn't even rt-safe, prefer clock_gettime whenever possible.
This commit is contained in:
Robin Gareus 2024-12-03 00:30:07 +01:00
parent ecaeea94e5
commit 057b84dd77
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
3 changed files with 10 additions and 23 deletions

View file

@ -1777,8 +1777,8 @@ private:
void mmc_shuttle (MIDI::MachineControl &mmc, float speed, bool forw);
void mmc_record_enable (MIDI::MachineControl &mmc, size_t track, bool enabled);
struct timeval last_mmc_step;
double step_speed;
int64_t _last_mmc_step;
double step_speed;
typedef std::function<bool()> MidiTimeoutCallback;
typedef std::list<MidiTimeoutCallback> MidiTimeoutList;

View file

@ -207,21 +207,14 @@ Session::mmc_step (MIDI::MachineControl &/*mmc*/, int steps)
return;
}
struct timeval now;
struct timeval diff = { 0, 0 };
int64_t now = g_get_monotonic_time ();
int64_t diff = now - _last_mmc_step;
gettimeofday (&now, 0);
timersub (&now, &last_mmc_step, &diff);
gettimeofday (&now, 0);
timersub (&now, &last_mmc_step, &diff);
if (last_mmc_step.tv_sec != 0 && (diff.tv_usec + (diff.tv_sec * 1000000)) < _engine.usecs_per_cycle()) {
if (_last_mmc_step != 0 && diff < _engine.usecs_per_cycle()) {
return;
}
double diff_secs = diff.tv_sec + (diff.tv_usec / 1000000.0);
double diff_secs = diff * 1e-6;
double cur_speed = (((steps * 0.5) * timecode_frames_per_second()) / diff_secs) / timecode_frames_per_second();
if (_transport_fsm->transport_speed() == 0 || cur_speed * _transport_fsm->transport_speed() < 0) {
@ -243,7 +236,7 @@ Session::mmc_step (MIDI::MachineControl &/*mmc*/, int steps)
#endif
request_transport_speed_nonzero (step_speed);
last_mmc_step = now;
_last_mmc_step = now;
if (!step_queued) {
if (midi_control_ui) {
@ -654,15 +647,9 @@ Session::send_immediate_mmc (MachineControlCommand c)
bool
Session::mmc_step_timeout ()
{
struct timeval now;
struct timeval diff;
double diff_usecs;
gettimeofday (&now, 0);
int64_t diff_usecs = g_get_monotonic_time () - _last_mmc_step;
timersub (&now, &last_mmc_step, &diff);
diff_usecs = diff.tv_sec * 1000000 + diff.tv_usec;
if (diff_usecs > 1000000.0 || fabs (_transport_fsm->transport_speed()) < 0.0000001) {
if (diff_usecs > 1000000 || fabs (_transport_fsm->transport_speed()) < 0.0000001) {
/* too long or too slow, stop transport */
request_stop ();
step_queued = false;

View file

@ -179,7 +179,7 @@ Session::pre_engine_init (string fullpath)
definition.
*/
timerclear (&last_mmc_step);
_last_mmc_step = 0;
_processing_prohibited.store (0);
_record_status.store (Disabled);
_playback_load.store (100);