summaryrefslogtreecommitdiff
path: root/CSharp/Ivy/IvyPPC/Ivy.cs
diff options
context:
space:
mode:
Diffstat (limited to 'CSharp/Ivy/IvyPPC/Ivy.cs')
-rw-r--r--CSharp/Ivy/IvyPPC/Ivy.cs52
1 files changed, 35 insertions, 17 deletions
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;
}