diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-01-05 23:05:29 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-01-05 23:05:29 +0000 |
| commit | 038ae17545335e5d1b33746b0193e85ee9f584fe (patch) | |
| tree | 1aceda1d202a2e991d8384136f38d246439d2edb /src | |
| parent | c2018e0dae9ed2503b6244a47524a7ce16eedb0b (diff) | |
Thought-necessary protection of TransferFunction::lut() for access from multiple threads.
Diffstat (limited to 'src')
| -rw-r--r-- | src/transfer_function.cc | 4 | ||||
| -rw-r--r-- | src/transfer_function.h | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/transfer_function.cc b/src/transfer_function.cc index d889cbbc..8a844d9b 100644 --- a/src/transfer_function.cc +++ b/src/transfer_function.cc @@ -33,6 +33,8 @@ TransferFunction::TransferFunction (bool inverse) TransferFunction::~TransferFunction () { + boost::mutex::scoped_lock lm (_mutex); + for (map<int, double*>::const_iterator i = _luts.begin(); i != _luts.end(); ++i) { delete[] i->second; } @@ -43,6 +45,8 @@ TransferFunction::~TransferFunction () double const * TransferFunction::lut (int bit_depth) const { + boost::mutex::scoped_lock lm (_mutex); + map<int, double*>::const_iterator i = _luts.find (bit_depth); if (i != _luts.end ()) { return i->second; diff --git a/src/transfer_function.h b/src/transfer_function.h index 16d00c1a..4105f3d4 100644 --- a/src/transfer_function.h +++ b/src/transfer_function.h @@ -22,6 +22,7 @@ #include <boost/noncopyable.hpp> #include <boost/shared_ptr.hpp> +#include <boost/thread/mutex.hpp> #include <map> namespace dcp { @@ -43,8 +44,10 @@ protected: bool _inverse; -private: +private: mutable std::map<int, double*> _luts; + /** mutex to protect _luts */ + mutable boost::mutex _mutex; }; } |
