Skip to content

Commit

Permalink
Merge pull request #538 from myjimmy/bugfix/web-ui-freeze
Browse files Browse the repository at this point in the history
Fix - Web UI freezes under high CPU load
  • Loading branch information
curtishall authored Jun 1, 2022
2 parents b022c52 + a200464 commit d652bb9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 2 additions & 6 deletions server/bc-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,13 +587,11 @@ const char *select_best_path(void)

size_t bc_get_media_locations(bc_string_array &locations)
{
pthread_rwlock_rdlock(&media_lock);
struct bc_storage *p;

for (p = media_stor; p < media_stor+MAX_STOR_LOCS && p->max_thresh; p++)
locations.push_back(std::string(p->path));

pthread_rwlock_unlock(&media_lock);
return locations.size();
}

Expand Down Expand Up @@ -1094,8 +1092,6 @@ static int bc_cleanup_media()

static int bc_check_media(void)
{
pthread_rwlock_rdlock(&media_lock);

int ret = 0;
bool storage_overloaded = true;

Expand All @@ -1110,8 +1106,6 @@ static int bc_check_media(void)
if (storage_overloaded || is_media_max_age_exceeded())
ret = bc_cleanup_media();

pthread_rwlock_unlock(&media_lock);

return ret;
}

Expand Down Expand Up @@ -1727,5 +1721,7 @@ int main(int argc, char **argv)
bc_db_close();
bc_ffmpeg_teardown();

pthread_rwlock_destroy(&media_lock);

return 0;
}
18 changes: 16 additions & 2 deletions server/bc-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ void bc_record::notify_device_state(const char *state)
exit(1);
}

void msleep(int duration) {

/* Split milliseconds into equivalent seconds + nanoseconds */
struct timespec sleep_period = {
.tv_sec = duration / 1000,
.tv_nsec = (duration % 1000) * 1000000
};

/* Sleep for specified interval */
nanosleep(&sleep_period, NULL);

}

void bc_record::run()
{
stream_packet packet;
Expand All @@ -189,6 +202,7 @@ void bc_record::run()
pthread_mutex_unlock(&cfg_mutex);
if (local_thread_should_die)
break;

if (local_cfg_dirty) {
if (apply_device_cfg(this))
break;
Expand Down Expand Up @@ -410,6 +424,7 @@ void bc_record::run()
}
}

msleep(10);
continue;
}

Expand All @@ -429,6 +444,7 @@ void bc_record::run()
}
}

msleep(10);
continue;
error:
sleep(10);
Expand Down Expand Up @@ -529,7 +545,6 @@ bc_record *bc_record::create_from_db(int id, BC_DB_RES dbres)
bc_rec->update_motion_thresholds();
check_schedule(bc_rec);


/* The following operations are effective only for some V4L2 devices */
ret = bc->input->set_control(V4L2_CID_HUE, bc_rec->cfg.hue);
ret |= bc->input->set_control(V4L2_CID_CONTRAST, bc_rec->cfg.contrast);
Expand All @@ -543,7 +558,6 @@ bc_record *bc_record::create_from_db(int id, BC_DB_RES dbres)
if (ret)
bc_rec->log.log(Warning, "Failed to set H264 quantization, please update solo6x10 driver");


/* Start device processing thread */
if (pthread_create(&bc_rec->thread, NULL, bc_device_thread,
bc_rec) != 0) {
Expand Down

0 comments on commit d652bb9

Please sign in to comment.