Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 void push_back(value_type&& value) | 51 void push_back(value_type&& value) |
52 { | 52 { |
53 { | 53 { |
54 std::lock_guard<std::mutex> lock(mutex); | 54 std::lock_guard<std::mutex> lock(mutex); |
55 collection.push_back(std::move(value)); | 55 collection.push_back(std::move(value)); |
56 } | 56 } |
57 conditionVar.notify_one(); | 57 conditionVar.notify_one(); |
58 } | 58 } |
59 | 59 |
60 /** | 60 /** |
61 * Extracts normally a firtst of currently stored elements and returns it. | 61 * Extracts the first stored element and returns it. |
hub
2018/02/23 22:59:35
I think the comment should read "Extracts the firs
sergei
2018/03/01 11:18:37
Yeah, perhaps it's better, done.
| |
62 * Pay attention that the call of this method blocks the execution until | 62 * Pay attention that the call of this method blocks the execution until |
63 * there is at least one element added to the collection. | 63 * there is at least one element added to the collection. |
64 */ | 64 */ |
65 value_type pop_front() | 65 value_type pop_front() |
66 { | 66 { |
67 std::unique_lock<std::mutex> lock(mutex); | 67 std::unique_lock<std::mutex> lock(mutex); |
68 conditionVar.wait(lock, [this]()->bool | 68 conditionVar.wait(lock, [this]()->bool |
69 { | 69 { |
70 return !collection.empty(); | 70 return !collection.empty(); |
71 }); | 71 }); |
72 value_type retValue = collection.front(); | 72 value_type retValue = collection.front(); |
73 collection.pop_front(); | 73 collection.pop_front(); |
74 return retValue; | 74 return retValue; |
75 } | 75 } |
76 protected: | 76 protected: |
77 Container collection; | 77 Container collection; |
78 std::mutex mutex; | 78 std::mutex mutex; |
79 std::condition_variable conditionVar; | 79 std::condition_variable conditionVar; |
80 }; | 80 }; |
81 } | 81 } |
LEFT | RIGHT |