Commit 81f24aa9e43ac03831a89ef92361ea4e3217a44f
1 parent
a9e0fa4f
threading fix
Showing
1 changed file
with
6 additions
and
7 deletions
openbr/core/resource.h
| ... | ... | @@ -71,14 +71,13 @@ public: |
| 71 | 71 | { |
| 72 | 72 | totalResources->acquire(); |
| 73 | 73 | |
| 74 | - T* resource; | |
| 75 | - if (availableResources->isEmpty()) { | |
| 76 | - resource = resourceMaker->make(); | |
| 77 | - } else { | |
| 78 | - lock->lock(); | |
| 74 | + T *resource = NULL; | |
| 75 | + lock->lock(); | |
| 76 | + if (!availableResources->isEmpty()) | |
| 79 | 77 | resource = availableResources->takeFirst(); |
| 80 | - lock->unlock(); | |
| 81 | - } | |
| 78 | + lock->unlock(); | |
| 79 | + if (!resource) | |
| 80 | + resource = resourceMaker->make(); | |
| 82 | 81 | |
| 83 | 82 | return resource; |
| 84 | 83 | } | ... | ... |