Mercurial > hg > orthanc-webviewer
comparison Plugin/Cache/CacheScheduler.cpp @ 147:70d1fe6d6309
Avoid hard crash if not enough memory
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 12:43:58 +0100 |
parents | 3809121c3290 |
children | 5dc54316d68b |
comparison
equal
deleted
inserted
replaced
146:3cde3e806abe | 147:70d1fe6d6309 |
---|---|
110 { | 110 { |
111 while (!(that->done_)) | 111 while (!(that->done_)) |
112 { | 112 { |
113 std::auto_ptr<DynamicString> prefetch(that->queue_.Dequeue(500)); | 113 std::auto_ptr<DynamicString> prefetch(that->queue_.Dequeue(500)); |
114 | 114 |
115 if (prefetch.get() != NULL) | 115 try |
116 { | 116 { |
117 if (prefetch.get() != NULL) | |
117 { | 118 { |
118 boost::mutex::scoped_lock lock(that->invalidatedMutex_); | |
119 that->invalidated_ = false; | |
120 that->prefetching_ = prefetch->GetValue(); | |
121 } | |
122 | |
123 { | |
124 boost::mutex::scoped_lock lock(that->cacheMutex_); | |
125 if (that->cache_.IsCached(that->bundleIndex_, prefetch->GetValue())) | |
126 { | 119 { |
127 // This item is already cached | 120 boost::mutex::scoped_lock lock(that->invalidatedMutex_); |
121 that->invalidated_ = false; | |
122 that->prefetching_ = prefetch->GetValue(); | |
123 } | |
124 | |
125 { | |
126 boost::mutex::scoped_lock lock(that->cacheMutex_); | |
127 if (that->cache_.IsCached(that->bundleIndex_, prefetch->GetValue())) | |
128 { | |
129 // This item is already cached | |
130 continue; | |
131 } | |
132 } | |
133 | |
134 std::string content; | |
135 | |
136 try | |
137 { | |
138 if (!that->factory_.Create(content, prefetch->GetValue())) | |
139 { | |
140 // The factory cannot generate this item | |
141 continue; | |
142 } | |
143 } | |
144 catch (...) | |
145 { | |
146 // Exception | |
128 continue; | 147 continue; |
129 } | 148 } |
130 } | 149 |
131 | |
132 std::string content; | |
133 | |
134 try | |
135 { | |
136 if (!that->factory_.Create(content, prefetch->GetValue())) | |
137 { | 150 { |
138 // The factory cannot generate this item | 151 boost::mutex::scoped_lock lock(that->invalidatedMutex_); |
139 continue; | 152 if (that->invalidated_) |
153 { | |
154 // This item has been invalidated | |
155 continue; | |
156 } | |
157 | |
158 { | |
159 boost::mutex::scoped_lock lock2(that->cacheMutex_); | |
160 that->cache_.Store(that->bundleIndex_, prefetch->GetValue(), content); | |
161 } | |
140 } | 162 } |
141 } | 163 } |
142 catch (...) | 164 } |
143 { | 165 catch (std::bad_alloc&) |
144 // Exception | 166 { |
145 continue; | 167 OrthancPluginLogError(that->cache_.GetPluginContext(), |
146 } | 168 "Not enough memory for the prefetcher of the Web viewer to work"); |
147 | 169 } |
148 { | 170 catch (...) |
149 boost::mutex::scoped_lock lock(that->invalidatedMutex_); | 171 { |
150 if (that->invalidated_) | 172 OrthancPluginLogError(that->cache_.GetPluginContext(), |
151 { | 173 "Unhandled native exception inside the prefetcher of the Web viewer"); |
152 // This item has been invalidated | |
153 continue; | |
154 } | |
155 | |
156 { | |
157 boost::mutex::scoped_lock lock2(that->cacheMutex_); | |
158 that->cache_.Store(that->bundleIndex_, prefetch->GetValue(), content); | |
159 } | |
160 } | |
161 } | 174 } |
162 } | 175 } |
163 } | 176 } |
164 | 177 |
165 | 178 |