* may throw any other exception thrown by the MessageT move/copy
* constructor.
*/
- void tryPutMessage(MessageT&& message) {
- putMessageImpl(std::move(message), advisoryMaxQueueSize_);
- }
- void tryPutMessage(const MessageT& message) {
- putMessageImpl(message, advisoryMaxQueueSize_);
+ template <typename MessageTT>
+ void tryPutMessage(MessageTT&& message) {
+ putMessageImpl(std::forward<MessageTT>(message), advisoryMaxQueueSize_);
}
/**
* (which indicates that the queue is being drained) are prevented from being
* thrown. User code must still catch std::bad_alloc errors.
*/
- bool tryPutMessageNoThrow(MessageT&& message) {
- return putMessageImpl(std::move(message), advisoryMaxQueueSize_, false);
- }
- bool tryPutMessageNoThrow(const MessageT& message) {
- return putMessageImpl(message, advisoryMaxQueueSize_, false);
+ template <typename MessageTT>
+ bool tryPutMessageNoThrow(MessageTT&& message) {
+ return putMessageImpl(
+ std::forward<MessageTT>(message), advisoryMaxQueueSize_, false);
}
/**
* - std::runtime_error if the queue is currently draining
* - any other exception thrown by the MessageT move/copy constructor.
*/
- void putMessage(MessageT&& message) {
- putMessageImpl(std::move(message), 0);
- }
- void putMessage(const MessageT& message) {
- putMessageImpl(message, 0);
+ template <typename MessageTT>
+ void putMessage(MessageTT&& message) {
+ putMessageImpl(std::forward<MessageTT>(message), 0);
}
/**
}
}
- bool putMessageImpl(MessageT&& message, size_t maxSize, bool throws=true) {
+ template <typename MessageTT>
+ bool putMessageImpl(MessageTT&& message, size_t maxSize, bool throws = true) {
checkPid();
bool signal = false;
{
if (numActiveConsumers_ < numConsumers_) {
signal = true;
}
- queue_.emplace_back(std::move(message), RequestContext::saveContext());
- if (signal) {
- ensureSignalLocked();
- }
- }
- return true;
- }
-
- bool putMessageImpl(
- const MessageT& message, size_t maxSize, bool throws=true) {
- checkPid();
- bool signal = false;
- {
- folly::SpinLockGuard g(spinlock_);
- if (checkDraining(throws) || !checkQueueSize(maxSize, throws)) {
- return false;
- }
- if (numActiveConsumers_ < numConsumers_) {
- signal = true;
- }
- queue_.emplace_back(message, RequestContext::saveContext());
+ queue_.emplace_back(
+ std::forward<MessageTT>(message), RequestContext::saveContext());
if (signal) {
ensureSignalLocked();
}