This patch is part of the lw_rwlock patchset, it removes the
net_family_{read,write}_{lock,unlock} functions which have been moved
to linux/lw_rwlock.h and made more generic.
Signed-off-by: Frederik Deweerdt <[email protected]>
--- v2.6.18-rc2-mm1~ori/net/socket.c 2006-07-27 11:46:12.000000000 +0200
+++ v2.6.18-rc2-mm1/net/socket.c 2006-07-28 15:50:06.000000000 +0200
@@ -85,6 +85,7 @@
#include <linux/kmod.h>
#include <linux/audit.h>
#include <linux/wireless.h>
+#include <linux/lw_rwlock.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
@@ -143,50 +144,7 @@ static struct file_operations socket_fil
static struct net_proto_family *net_families[NPROTO];
-#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
-static atomic_t net_family_lockct = ATOMIC_INIT(0);
-static DEFINE_SPINLOCK(net_family_lock);
-
-/* The strategy is: modifications net_family vector are short, do not
- sleep and veeery rare, but read access should be free of any exclusive
- locks.
- */
-
-static void net_family_write_lock(void)
-{
- spin_lock(&net_family_lock);
- while (atomic_read(&net_family_lockct) != 0) {
- spin_unlock(&net_family_lock);
-
- yield();
-
- spin_lock(&net_family_lock);
- }
-}
-
-static __inline__ void net_family_write_unlock(void)
-{
- spin_unlock(&net_family_lock);
-}
-
-static __inline__ void net_family_read_lock(void)
-{
- atomic_inc(&net_family_lockct);
- spin_unlock_wait(&net_family_lock);
-}
-
-static __inline__ void net_family_read_unlock(void)
-{
- atomic_dec(&net_family_lockct);
-}
-
-#else
-#define net_family_write_lock() do { } while(0)
-#define net_family_write_unlock() do { } while(0)
-#define net_family_read_lock() do { } while(0)
-#define net_family_read_unlock() do { } while(0)
-#endif
-
+static DEFINE_LW_RWLOCK(net_family_lock);
/*
* Statistics counters of the socket lists
@@ -1125,7 +1083,7 @@ static int __sock_create(int family, int
}
#endif
- net_family_read_lock();
+ lw_read_lock(&net_family_lock);
if (net_families[family] == NULL) {
err = -EAFNOSUPPORT;
goto out;
@@ -1176,7 +1134,7 @@ static int __sock_create(int family, int
security_socket_post_create(sock, family, type, protocol, kern);
out:
- net_family_read_unlock();
+ lw_read_unlock(&net_family_lock);
return err;
out_module_put:
module_put(net_families[family]->owner);
@@ -2025,13 +1983,13 @@ int sock_register(struct net_proto_famil
printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family, NPROTO);
return -ENOBUFS;
}
- net_family_write_lock();
+ lw_write_lock(&net_family_lock);
err = -EEXIST;
if (net_families[ops->family] == NULL) {
net_families[ops->family]=ops;
err = 0;
}
- net_family_write_unlock();
+ lw_write_unlock(&net_family_lock);
printk(KERN_INFO "NET: Registered protocol family %d\n",
ops->family);
return err;
@@ -2048,9 +2006,9 @@ int sock_unregister(int family)
if (family < 0 || family >= NPROTO)
return -1;
- net_family_write_lock();
+ lw_write_lock(&net_family_lock);
net_families[family]=NULL;
- net_family_write_unlock();
+ lw_write_unlock(&net_family_lock);
printk(KERN_INFO "NET: Unregistered protocol family %d\n",
family);
return 0;
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Stuff]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
[Linux Resources]