Commit fe511d03 authored by Darek Stojaczyk's avatar Darek Stojaczyk Committed by Ben Walker
Browse files

env_dpdk/pci: reduce g_pci_mutex scope



The global pci tailq is no longer modified on the dpdk
thread, so on the spdk thread we can access it safely
without any lock. The code is slightly more readable
then.

This shows that cleanup_pci_devices() is always wrapped
with lock/unlock. We'll put the locks inside this
function in the next patch.

Change-Id: Ia4d386b78a87078761df0a3b953bfc4ff44102f8
Signed-off-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/458933


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent b941b298
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -358,6 +358,8 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver,

	pthread_mutex_lock(&g_pci_mutex);
	cleanup_pci_devices();
	pthread_mutex_unlock(&g_pci_mutex);

	TAILQ_FOREACH(dev, &g_pci_devices, internal.tailq) {
		if (spdk_pci_addr_compare(&dev->addr, pci_address) == 0) {
			break;
@@ -365,6 +367,7 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver,
	}

	if (dev != NULL && dev->internal.driver == driver) {
		pthread_mutex_lock(&g_pci_mutex);
		if (dev->internal.attached || dev->internal.pending_removal) {
			pthread_mutex_unlock(&g_pci_mutex);
			return -1;
@@ -377,7 +380,6 @@ spdk_pci_device_attach(struct spdk_pci_driver *driver,
		pthread_mutex_unlock(&g_pci_mutex);
		return rc;
	}
	pthread_mutex_unlock(&g_pci_mutex);

	if (!driver->is_registered) {
		driver->is_registered = true;