Fix device emulation crash due to contention
Device emulation packets are received and processed in a different thread compared to the main RPC processing thread where the emulated devices are created/deleted. No packets should be processed while the latter is in progress otherwise the former may access devices that have been deleted.
This commit is contained in:
parent
d2ae04c488
commit
f0dd0c307b
@ -222,6 +222,7 @@ void DeviceManager::getDeviceList(
|
|||||||
|
|
||||||
void DeviceManager::receivePacket(PacketBuffer *pktBuf)
|
void DeviceManager::receivePacket(PacketBuffer *pktBuf)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&listLock_);
|
||||||
uchar *pktData = pktBuf->data();
|
uchar *pktData = pktBuf->data();
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
EmulDevice dk(this);
|
EmulDevice dk(this);
|
||||||
@ -401,6 +402,7 @@ void DeviceManager::enumerateDevices(
|
|||||||
const OstProto::DeviceGroup *deviceGroup,
|
const OstProto::DeviceGroup *deviceGroup,
|
||||||
Operation oper)
|
Operation oper)
|
||||||
{
|
{
|
||||||
|
QMutexLocker locker(&listLock_);
|
||||||
EmulDevice dk(this);
|
EmulDevice dk(this);
|
||||||
OstEmul::VlanEmulation pbVlan = deviceGroup->encap()
|
OstEmul::VlanEmulation pbVlan = deviceGroup->encap()
|
||||||
.GetExtension(OstEmul::vlan);
|
.GetExtension(OstEmul::vlan);
|
||||||
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QMultiHash>
|
#include <QMultiHash>
|
||||||
|
#include <QMutex>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
class AbstractPort;
|
class AbstractPort;
|
||||||
@ -76,6 +77,7 @@ private:
|
|||||||
|
|
||||||
AbstractPort *port_;
|
AbstractPort *port_;
|
||||||
|
|
||||||
|
QMutex listLock_; // protects all the lists
|
||||||
QHash<uint, OstProto::DeviceGroup*> deviceGroupList_;
|
QHash<uint, OstProto::DeviceGroup*> deviceGroupList_;
|
||||||
QHash<DeviceKey, Device*> deviceList_; // fast access to devices
|
QHash<DeviceKey, Device*> deviceList_; // fast access to devices
|
||||||
QMap<DeviceKey, Device*> sortedDeviceList_; // sorted access to devices
|
QMap<DeviceKey, Device*> sortedDeviceList_; // sorted access to devices
|
||||||
|
Loading…
Reference in New Issue
Block a user