描述:linux源码spi.c中有这样的一个函数spi_register_master,其中定义了一个原子量dyn_bus_id(如下面代码的蓝色字体)。
源码如下:
int spi_register_master(struct spi_master *master)
{ static atomic_t dyn_bus_id = ATOMIC_INIT((1<<15) - 1); struct device *dev = master->dev.parent;
int status = -ENODEV;
int dynamic = 0;
if (!dev) return -ENODEV;
/* even if it's just one always-selected device, there must * be at least one chipselect */ if (master->num_chipselect == 0) return -EINVAL;
/* convention: dynamically assigned bus IDs count down from the max */ if (master->bus_num < 0) { /* FIXME switch to an IDR based scheme, something like * I2C now uses, so we can't run out of "dynamic" IDs */
master->bus_num = atomic_dec_return(&dyn_bus_id);
dynamic = 1;
}
/* register the device, then userspace will see it. * registration fails if the bus ID is in use. */
dev_set_name(&master->dev, "spi%u", master->bus_num);
status = device_add(&master->dev); if (status < 0) goto done;
dev_dbg(dev, "registered master %s%s\n", dev_name(&master->dev),
dynamic ? " (dynamic)" : "");
/* populate children from any spi device tables */
scan_boardinfo(master);
status = 0;
done: return status;
}
EXPORT_SYMBOL_GPL(spi_register_master);
问题:为什么要定义原子量,其是防止怎样的情况发生,举个例子?
说明:1.原子量的作用我是知道的,我想知道的是这里利用原子量想防止什么情况发生,举个例子。
2.源码中这样的注释也不了解 /* FIXME switch to an IDR based scheme, something like * I2C now uses, so we can't run out of "dynamic" IDs */