Replaced master's reserved flag by atomic_t available.
--- a/master/master.c Tue Sep 26 16:16:13 2006 +0000
+++ b/master/master.c Tue Sep 26 16:34:24 2006 +0000
@@ -109,7 +109,7 @@
master->index = index;
master->device = NULL;
- master->reserved = 0;
+ atomic_set(&master->available, 1);
INIT_LIST_HEAD(&master->slaves);
INIT_LIST_HEAD(&master->datagram_queue);
INIT_LIST_HEAD(&master->domains);
--- a/master/master.h Tue Sep 26 16:16:13 2006 +0000
+++ b/master/master.h Tue Sep 26 16:34:24 2006 +0000
@@ -44,6 +44,7 @@
#include <linux/list.h>
#include <linux/sysfs.h>
#include <linux/timer.h>
+#include <asm/atomic.h>
#include "device.h"
#include "domain.h"
@@ -92,7 +93,7 @@
struct ec_master
{
struct list_head list; /**< list item for module's master list */
- unsigned int reserved; /**< non-zero, if the master is reserved for RT */
+ atomic_t available; /**< zero, if the master is reserved for RT */
unsigned int index; /**< master index */
struct kobject kobj; /**< kobject */
--- a/master/module.c Tue Sep 26 16:16:13 2006 +0000
+++ b/master/module.c Tue Sep 26 16:34:24 2006 +0000
@@ -409,11 +409,11 @@
if (!(master = ec_find_master(master_index))) goto out_return;
- if (master->reserved) {
+ if (!atomic_dec_and_test(&master->available)) {
+ atomic_inc(&master->available);
EC_ERR("Master %i is already in use!\n", master_index);
goto out_return;
}
- master->reserved = 1;
if (!master->device) {
EC_ERR("Master %i has no assigned device!\n", master_index);
@@ -452,7 +452,7 @@
out_module_put:
module_put(master->device->module);
out_release:
- master->reserved = 0;
+ atomic_inc(&master->available);
out_return:
EC_ERR("Failed to request master %i.\n", master_index);
return NULL;
@@ -469,7 +469,7 @@
{
EC_INFO("Releasing master %i...\n", master->index);
- if (!master->reserved) {
+ if (atomic_read(&master->available)) {
EC_ERR("Master %i was never requested!\n", master->index);
return;
}
@@ -478,7 +478,7 @@
ec_master_idle_start(master);
module_put(master->device->module);
- master->reserved = 0;
+ atomic_inc(&master->available);
EC_INFO("Successfully released master %i.\n", master->index);
return;