last_error_ = "thread stopped";
}
-isc::util::thread::Mutex&
-Receiver::getLock() {
- return(lock_);
-}
-
void
Receiver::setError(const std::string& error_msg) {
last_error_ = error_msg;
}
// If we're here it should only be because there are DHCP packets waiting.
- // Protected packet queue access.
- Pkt4Ptr pkt;
- {
- Mutex::Locker lock(receiver_->getLock());
- pkt = getPacketQueue4()->dequeuePacket();
- if (!pkt) {
- receiver_->clearReady(Receiver::RCV_READY);
- }
+ Pkt4Ptr pkt = getPacketQueue4()->dequeuePacket();
+ if (!pkt) {
+ receiver_->clearReady(Receiver::RCV_READY);
}
return (pkt);
}
// If we're here it should only be because there are DHCP packets waiting.
- // Protected packet queue access.
- Pkt6Ptr pkt;
- {
- Mutex::Locker lock(receiver_->getLock());
- pkt = getPacketQueue6()->dequeuePacket();
- if (!pkt) {
- receiver_->clearReady(Receiver::RCV_READY);
- }
+ Pkt6Ptr pkt = getPacketQueue6()->dequeuePacket();
+ if (!pkt) {
+ receiver_->clearReady(Receiver::RCV_READY);
}
return (pkt);
}
if (pkt) {
- Mutex::Locker lock(receiver_->getLock());
getPacketQueue4()->enqueuePacket(pkt, socket_info);
receiver_->markReady(Receiver::RCV_READY);
}
}
if (pkt) {
- Mutex::Locker lock(receiver_->getLock());
getPacketQueue6()->enqueuePacket(pkt, socket_info);
receiver_->markReady(Receiver::RCV_READY);
}
#include <util/optional_value.h>
#include <util/watch_socket.h>
#include <util/threads/thread.h>
-#include <util/threads/sync.h>
#include <boost/function.hpp>
#include <boost/noncopyable.hpp>
/// not done in the destructor to avoid race conditions.
void stop();
- /// @brief Fetches the receiver's thread mutex.
- ///
- /// This is used for instantation mutex locks to protect code blocks.
- ///
- /// @return a reference to the mutex
- isc::util::thread::Mutex& getLock();
-
/// @brief Sets the receiver error state
///
/// This records the given error message and sets the error watch
/// Marked as ready when the DHCP packet receiver thread should terminate.
isc::util::WatchSocket sockets_[RCV_TERMINATE + 1];
- /// DHCP packet thread mutex.
- isc::util::thread::Mutex lock_;
-
/// DHCP packet receiver thread.
isc::util::thread::ThreadPtr thread_ ;
};
#include <dhcp/socket_info.h>
#include <dhcp/pkt4.h>
#include <dhcp/pkt6.h>
+#include <util/threads/sync.h>
#include <boost/function.hpp>
#include <boost/circular_buffer.hpp>
/// This class serves as the abstract interface for packet queue
/// implementations which may be used by @c IfaceMgr to store
/// inbound packets until they are a dequeued for processing.
+/// @note Derivations of this class MUST BE thread-safe.
+/// @endnote
///
template<typename PacketTypePtr>
class PacketQueue {
/// @brief Pushes a packet onto the queue
///
- /// Adds a packet onto the end of queue specified.
+ /// Adds a packet onto the end of queue specified. Note that this
+ /// function is protected by a Mutex.
///
/// @param packet packet to add to the queue
/// @param to specifies the end of the queue to which the packet
/// should be added.
virtual void pushPacket(PacketTypePtr& packet, const QueueEnd& to=QueueEnd::BACK) {
+ isc::util::thread::Mutex::Locker lock(mutex_);
if (to == QueueEnd::BACK) {
queue_.push_back(packet);
} else {
/// @brief Pops a packet from the queue
///
- /// Removes a packet from the end of the queue specified and returns it.
+ /// Removes a packet from the end of the queue specified and returns it. Note
+ /// that this function is protected by a Mutex.
///
/// @param from specifies the end of the queue from which the packet
/// should be taken.
/// @return A pointer to dequeued packet, or an empty pointer
/// if the queue is empty.
virtual PacketTypePtr popPacket(const QueueEnd& from = QueueEnd::FRONT) {
+ isc::util::thread::Mutex::Locker lock(mutex_);
PacketTypePtr packet;
if (queue_.empty()) {
return (packet);
/// @brief Packet queue
boost::circular_buffer<PacketTypePtr> queue_;
+
+ /// @brief Mutex for protecting queue accesses.
+ isc::util::thread::Mutex mutex_;
};