Permalink
Browse files

o Don't do unprotected read on status information such as

  progress and max value seen.
o Update the max value seen before passing it over to stats server :)
  • Loading branch information...
1 parent 7689c9a commit f00e6a474b739ebd39195804656619e9b46986dd @hzeller committed Sep 22, 2012
Showing with 12 additions and 3 deletions.
  1. +11 −3 folve-filesystem.cc
  2. +1 −0 status-server.cc
View
@@ -33,6 +33,9 @@
#include <string>
#include <zita-convolver.h>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/mutex.hpp>
+
#include "conversion-buffer.h"
#include "file-handler-cache.h"
#include "file-handler.h"
@@ -199,15 +202,17 @@ class SndFileHandler :
}
virtual void GetHandlerStatus(struct HandlerStats *stats) {
+ boost::lock_guard<boost::mutex> l(stats_mutex_);
+ if (processor_ != NULL) {
+ base_stats_.max_output_value = processor_->max_output_value();
+ }
*stats = base_stats_;
const int frames_done = in_info_.frames - input_frames_left_;
if (frames_done == 0 || in_info_.frames == 0)
stats->progress = 0.0;
else
stats->progress = 1.0 * frames_done / in_info_.frames;
- if (processor_ != NULL) {
- base_stats_.max_output_value = processor_->max_output_value();
- }
+
if (base_stats_.max_output_value > 1.0) {
// TODO: the status server could inspect this value and make better
// rendering.
@@ -370,6 +375,8 @@ class SndFileHandler :
}
virtual bool AddMoreSoundData() {
+ // We're changing some stats here such as frames_left and max level.
+ boost::lock_guard<boost::mutex> l(stats_mutex_);
if (processor_ && processor_->pending_writes() > 0) {
processor_->WriteProcessed(snd_out_, processor_->pending_writes());
return input_frames_left_;
@@ -547,6 +554,7 @@ class SndFileHandler :
const SF_INFO in_info_;
const std::string config_path_;
+ boost::mutex stats_mutex_;
HandlerStats base_stats_; // UI information about current file.
struct stat file_stat_; // we dynamically report a changing size.
View
@@ -187,6 +187,7 @@ static void AppendFileInfo(std::string *result, const char *progress_style,
} else {
result->append("<td colspan='3'>-</td>");
}
+
if (stats.max_output_value > 1e-6) {
Appendf(result, sDecibelColumn,
stats.max_output_value > 1.0 ? "#FF0505" : "white",

0 comments on commit f00e6a4

Please sign in to comment.