Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb11d17c

Browse files
committed
- ensure capacity atleast 1
- capacity setter notifies notFullCond to avoid deadlock on waiting for put- docstring
1 parent17ff3dc commitb11d17c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎include/mqtt/thread_queue.h‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,18 @@ class thread_queue
149149
return cap_;
150150
}
151151
/**
152-
* Sets the capacity of the queue.
153-
* Note that the capacity can be set to a value smaller than the current
154-
* size of the queue. In that event, all calls to put() will block until
155-
* a sufficient number
152+
* Sets the capacity of the queue.
153+
* Note that the capacity can be set to a value smaller than the current
154+
* size of the queue. In that event, all calls to put() will block until
155+
* a sufficient number of items are removed from the queue.
156156
*/
157157
voidcapacity(size_type cap) {
158-
guard g{lock_};
159-
cap_ = cap;
158+
unique_guardg(lock_);
159+
cap_ = std::max<size_type>(cap,1);
160+
if(cap_ > que_.size()) {
161+
g.unlock();
162+
notFullCond_.notify_all();
163+
}
160164
}
161165
/**
162166
* Gets the number of items in the queue.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp