From 3c6db00323eeaa3d38d8cfd9ac5c2d4c1a8abb2b Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 09:54:00 +0000 Subject: Utilisateur : Fcolin Date : 17/06/03 Heure : 18:52 Archivé dans $/EScribe/Ivy Commentaire: (vss 2) --- CSharp/Ivy/IvyPPC/Ivy.cs | 52 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'CSharp/Ivy') diff --git a/CSharp/Ivy/IvyPPC/Ivy.cs b/CSharp/Ivy/IvyPPC/Ivy.cs index c681585..2ef37ae 100644 --- a/CSharp/Ivy/IvyPPC/Ivy.cs +++ b/CSharp/Ivy/IvyPPC/Ivy.cs @@ -59,9 +59,12 @@ namespace IvyBus get { String s = appName + " clients are: "; - foreach (IvyClient client in clients.Values ) + lock( clients.SyncRoot ) { - s += client.ApplicationName + " "; + foreach (IvyClient client in clients.Values ) + { + s += client.ApplicationName + " "; + } } return s; } @@ -125,7 +128,7 @@ namespace IvyBus public Ivy(String name, String message) { callbacks = new Hashtable(); - clients = new Hashtable(); + clients = Hashtable.Synchronized( new Hashtable() ); regexp_out = new Hashtable(); appName = name; ready_message = message; @@ -222,7 +225,7 @@ namespace IvyBus ((IvyWatcher) watchers[i]).stop(); } // stopping the remaining IvyClients - lock(clients) + lock(clients.SyncRoot) { foreach (IvyClient c in clients.Values ) { @@ -256,9 +259,12 @@ namespace IvyBus int count = 0; // an alternate implementation would one sender thread per client // instead of one for all the clients. It might be a performance issue - foreach (IvyClient client in clients.Values ) + lock ( clients.SyncRoot ) { - count += client.sendMsg(message); + foreach (IvyClient client in clients.Values ) + { + count += client.sendMsg(message); + } } return count; } @@ -286,12 +292,15 @@ namespace IvyBus { // creates a new binding (regexp,callback) Int32 key = serial++; - regexp_out.Add( key, regexp); - callbacks.Add( key, callback); + lock (regexp_out) regexp_out.Add( key, regexp); + lock (callback) callbacks.Add( key, callback); // notifies the other clients this new regexp - foreach (IvyClient c in clients.Values ) + lock ( clients.SyncRoot ) { - c.sendRegexp(key, regexp); + foreach (IvyClient c in clients.Values ) + { + c.sendRegexp(key, regexp); + } } return key; } @@ -308,9 +317,12 @@ namespace IvyBus { throw new IvyException("client wants to remove an unexistant regexp " + id); } - foreach (IvyClient c in clients.Values ) + lock( clients.SyncRoot ) { - c.delRegexp(id); + foreach (IvyClient c in clients.Values ) + { + c.delRegexp(id); + } } } @@ -370,7 +382,7 @@ namespace IvyBus */ internal void removeClient(IvyClient c) { - lock(clients) + lock( clients.SyncRoot ) { clients.Remove(c.ClientKey); } @@ -411,7 +423,10 @@ namespace IvyBus if (stopped) return ; IvyClient client = new IvyClient(this,socket); - clients.Add( client.ClientKey, client); + lock ( clients.SyncRoot ) + { + clients.Add( client.ClientKey, client); + } traceDebug(ClientNames); } } @@ -496,10 +511,13 @@ namespace IvyBus { if (clnt.AppPort == 0) return false; - foreach (IvyClient client in clients.Values ) + lock( clients.SyncRoot ) { - if (clnt != client && client.sameClient(clnt)) - return true; + foreach (IvyClient client in clients.Values ) + { + if (clnt != client && client.sameClient(clnt)) + return true; + } } return false; } -- cgit v1.1