Skip to content

Commit

Permalink
Rename dispatcher => executor in C# (#2165)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored May 14, 2024
1 parent fd47c71 commit 38742eb
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 62 deletions.
8 changes: 4 additions & 4 deletions csharp/msbuild/ice.test.sln
Original file line number Diff line number Diff line change
Expand Up @@ -440,21 +440,21 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "server", "server", "{83CEBF
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "server", "..\test\Ice\optional\msbuild\server\server.csproj", "{DBBC1CFA-36ED-46D6-8EBD-55D007DFE5F3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dispatcher", "dispatcher", "{736C1F0E-352B-4B30-9943-CA34989744FD}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "executor", "executor", "{736C1F0E-352B-4B30-9943-CA34989744FD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "msbuild", "msbuild", "{1723E29D-2FA2-4D3C-8062-E1003D23C8EA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "client", "client", "{5BDA9F9A-CBD1-4EAE-8580-676343FD311E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "client", "..\test\Ice\dispatcher\msbuild\client\client.csproj", "{2A6DE268-EFCB-4732-8E88-77E3FD76184A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "client", "..\test\Ice\executor\msbuild\client\client.csproj", "{2A6DE268-EFCB-4732-8E88-77E3FD76184A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "collocated", "collocated", "{F1CEDB16-77DB-43A9-907B-8D8222F226CA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "collocated", "..\test\Ice\dispatcher\msbuild\collocated\collocated.csproj", "{DF68EF4A-15EA-4D78-804A-5337E00D8EAB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "collocated", "..\test\Ice\executor\msbuild\collocated\collocated.csproj", "{DF68EF4A-15EA-4D78-804A-5337E00D8EAB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "server", "server", "{8AAB9F16-6325-4596-AA26-926D3F72F15A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "server", "..\test\Ice\dispatcher\msbuild\server\server.csproj", "{23F56DC6-F07E-45AC-A866-2DFAD3A1F202}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "server", "..\test\Ice\executor\msbuild\server\server.csproj", "{23F56DC6-F07E-45AC-A866-2DFAD3A1F202}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "acm", "acm", "{910705C7-7F2B-4D6D-B6CB-64C80E5624FE}"
EndProject
Expand Down
8 changes: 4 additions & 4 deletions csharp/src/Glacier2/SessionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ private void
private void
dispatchCallback(Action callback, Ice.Connection conn)
{
if (_initData.dispatcher != null)
if (_initData.executor != null)
{
_initData.dispatcher(callback, conn);
_initData.executor(callback, conn);
}
else
{
Expand All @@ -436,10 +436,10 @@ private void
private void
dispatchCallbackAndWait(Action callback)
{
if (_initData.dispatcher != null)
if (_initData.executor != null)
{
EventWaitHandle h = new ManualResetEvent(false);
_initData.dispatcher(() =>
_initData.executor(() =>
{
callback();
h.Set();
Expand Down
8 changes: 4 additions & 4 deletions csharp/src/Ice/ConnectionI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public void setCloseCallback(CloseCallback callback)
{
if (callback != null)
{
_threadPool.dispatch(() =>
_threadPool.execute(() =>
{
try
{
Expand Down Expand Up @@ -1306,7 +1306,7 @@ public override void message(ref ThreadPoolCurrent current)
}

ThreadPoolCurrent c = current;
_threadPool.dispatch(() =>
_threadPool.execute(() =>
{
upcall(startCB, sentCBs, info);
msg.destroy(ref c);
Expand Down Expand Up @@ -1435,7 +1435,7 @@ public override void finished(ref ThreadPoolCurrent current)
//
// If there are no callbacks to call, we don't call ioCompleted() since we're not going
// to call code that will potentially block (this avoids promoting a new leader and
// unecessary thread creation, especially if this is called on shutdown).
// unnecessary thread creation, especially if this is called on shutdown).
//
if (_startCallback == null && _sendStreams.Count == 0 && _asyncRequests.Count == 0 &&
_closeCallback == null && _heartbeatCallback == null)
Expand All @@ -1450,7 +1450,7 @@ public override void finished(ref ThreadPoolCurrent current)
// non-blocking activity of the connection from these threads, the dispatching
// of the message must be taken care of by the Ice thread pool.
//
_threadPool.dispatch(finish, this);
_threadPool.execute(finish, this);
}

private void finish()
Expand Down
12 changes: 6 additions & 6 deletions csharp/src/Ice/Internal/CollocatedRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private static void
CollocatedRequestHandler(Reference @ref, Ice.ObjectAdapter adapter)
{
_reference = @ref;
_dispatcher = _reference.getInstance().initializationData().dispatcher != null;
_executor = _reference.getInstance().initializationData().executor != null;
_response = _reference.getMode() == Reference.Mode.ModeTwoway;
_adapter = (Ice.ObjectAdapterI)adapter;

Expand Down Expand Up @@ -180,7 +180,7 @@ public int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestCount,
if (!synchronous || !_response || _reference.getInvocationTimeout() > 0)
{
// Don't invoke from the user thread if async or invocation timeout is set
_adapter.getThreadPool().dispatch(
_adapter.getThreadPool().execute(
() =>
{
if (sentAsync(outAsync))
Expand All @@ -189,9 +189,9 @@ public int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestCount,
}
}, null);
}
else if (_dispatcher)
else if (_executor)
{
_adapter.getThreadPool().dispatchFromThisThread(
_adapter.getThreadPool().executeFromThisThread(
() =>
{
if (sentAsync(outAsync))
Expand All @@ -200,7 +200,7 @@ public int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestCount,
}
}, null);
}
else // Optimization: directly call invokeAll if there's no dispatcher.
else // Optimization: directly call invokeAll if there's no executor.
{
if (sentAsync(outAsync))
{
Expand Down Expand Up @@ -331,7 +331,7 @@ private void
}

private readonly Reference _reference;
private readonly bool _dispatcher;
private readonly bool _executor;
private readonly bool _response;
private readonly Ice.ObjectAdapterI _adapter;
private readonly Ice.Logger _logger;
Expand Down
6 changes: 3 additions & 3 deletions csharp/src/Ice/Internal/OutgoingAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void invokeSentAsync()
//
try
{
instance_.clientThreadPool().dispatch(invokeSent, cachedConnection_);
instance_.clientThreadPool().execute(invokeSent, cachedConnection_);
}
catch (Ice.CommunicatorDestroyedException)
{
Expand All @@ -57,7 +57,7 @@ public void invokeExceptionAsync()
// CommunicatorDestroyedCompleted is the only exception that can propagate directly
// from this method.
//
instance_.clientThreadPool().dispatch(invokeException, cachedConnection_);
instance_.clientThreadPool().execute(invokeException, cachedConnection_);
}

public void invokeResponseAsync()
Expand All @@ -66,7 +66,7 @@ public void invokeResponseAsync()
// CommunicatorDestroyedCompleted is the only exception that can propagate directly
// from this method.
//
instance_.clientThreadPool().dispatch(invokeResponse, cachedConnection_);
instance_.clientThreadPool().execute(invokeResponse, cachedConnection_);
}

public void invokeSent()
Expand Down
30 changes: 15 additions & 15 deletions csharp/src/Ice/Internal/ThreadPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public ThreadPoolSynchronizationContext(ThreadPool threadPool)
public override void Post(SendOrPostCallback d, object state)
{
//
// Dispatch the continuation on the thread pool if this isn't called
// already from a thread pool thread. We don't use the dispatcher
// for the continuations, the dispatcher is only used when the
// Execute the continuation on the thread pool if this isn't called
// already from a thread pool thread. We don't use the executor
// for the continuations, the executor is only used when the
// call is initially invoked (e.g.: a servant dispatch after being
// received is dispatched using the dispatcher which might dispatch
// received is dispatched using the executor which might execute
// the call on the UI thread which will then use its own synchronization
// context to execute continuations).
//
var ctx = Current as ThreadPoolSynchronizationContext;
if (ctx != this)
{
_threadPool.dispatch(() => { d(state); }, null, false);
_threadPool.execute(() => { d(state); }, null, false);
}
else
{
Expand Down Expand Up @@ -152,7 +152,7 @@ public ThreadPool(Instance instance, string prefix, int timeout)
Ice.Properties properties = instance.initializationData().properties;

_instance = instance;
_dispatcher = instance.initializationData().dispatcher;
_executor = instance.initializationData().executor;
_destroyed = false;
_prefix = prefix;
_threadIndex = 0;
Expand Down Expand Up @@ -371,13 +371,13 @@ public void finish(EventHandler handler)
}
}

public void dispatchFromThisThread(System.Action call, Ice.Connection con)
public void executeFromThisThread(System.Action call, Ice.Connection con)
{
if (_dispatcher != null)
if (_executor != null)
{
try
{
_dispatcher(call, con);
_executor(call, con);
}
catch (System.Exception ex)
{
Expand All @@ -394,7 +394,7 @@ public void dispatchFromThisThread(System.Action call, Ice.Connection con)
}
}

public void dispatch(System.Action call, Ice.Connection con, bool useDispatcher = true)
public void execute(System.Action call, Ice.Connection con, bool useExecutor = true)
{
lock (this)
{
Expand All @@ -403,9 +403,9 @@ public void dispatch(System.Action call, Ice.Connection con, bool useDispatcher
throw new Ice.CommunicatorDestroyedException();
}

if (useDispatcher)
if (useExecutor)
{
_workItems.Enqueue(() => { dispatchFromThisThread(call, con); });
_workItems.Enqueue(() => { executeFromThisThread(call, con); });
}
else
{
Expand Down Expand Up @@ -479,14 +479,14 @@ public bool serialize()

protected sealed override void QueueTask(System.Threading.Tasks.Task task)
{
dispatch(() => { TryExecuteTask(task); }, null, _dispatcher != null);
execute(() => { TryExecuteTask(task); }, null, _executor != null);
}

protected sealed override bool TryExecuteTaskInline(System.Threading.Tasks.Task task, bool taskWasPreviouslyQueued)
{
if (!taskWasPreviouslyQueued)
{
dispatchFromThisThread(() => { TryExecuteTask(task); }, null);
executeFromThisThread(() => { TryExecuteTask(task); }, null);
return true;
}
return false;
Expand Down Expand Up @@ -757,7 +757,7 @@ private AsyncCallback getCallback(int operation)
}

private Instance _instance;
private Action<Action, Ice.Connection> _dispatcher;
private Action<Action, Ice.Connection> _executor;
private bool _destroyed;
private readonly string _prefix;
private readonly string _threadPrefix;
Expand Down
4 changes: 2 additions & 2 deletions csharp/src/Ice/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public class InitializationData
public System.Action threadStop;

/// <summary>
/// The dispatcher for the communicator.
/// The executor for the communicator.
/// </summary>
public System.Action<System.Action, Connection> dispatcher;
public System.Action<System.Action, Connection> executor;

/// <summary>
/// The batch request interceptor.
Expand Down
2 changes: 1 addition & 1 deletion csharp/test/Glacier2/sessionHelper/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public override void run(string[] args)
initData.properties.setProperty("Ice.Warn.Connections", "0");
initData.properties.setProperty("Ice.Default.Router",
"Glacier2/router:" + getTestEndpoint(initData.properties, 50));
initData.dispatcher = delegate (Action action, Ice.Connection connection)
initData.executor = delegate (Action action, Ice.Connection connection)
{
action();
};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void allTests(TestHelper helper)

Test.TestIntfControllerPrx testController = Test.TestIntfControllerPrxHelper.uncheckedCast(obj);

output.Write("testing dispatcher with async/await... ");
output.Write("testing executor with async/await... ");
output.Flush();
{
TaskCompletionSource<object> t = new TaskCompletionSource<object>();
Expand All @@ -48,7 +48,7 @@ public static void allTests(TestHelper helper)
try
{
await p.opAsync();
test(Dispatcher.isDispatcherThread());
test(Executor.isExecutorThread());

try
{
Expand All @@ -58,7 +58,7 @@ public static void allTests(TestHelper helper)
}
catch (Exception)
{
test(Dispatcher.isDispatcherThread());
test(Executor.isExecutorThread());
}

Test.TestIntfPrx to = Test.TestIntfPrxHelper.uncheckedCast(p.ice_invocationTimeout(10));
Expand All @@ -69,7 +69,7 @@ public static void allTests(TestHelper helper)
}
catch (Ice.InvocationTimeoutException)
{
test(Dispatcher.isDispatcherThread());
test(Executor.isExecutorThread());
}
t.SetResult(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public override void run(string[] args)
// send() blocking after sending a given amount of data.
//
initData.properties.setProperty("Ice.TCP.SndSize", "50000");
initData.dispatcher = new Dispatcher().dispatch;
initData.executor = new Executor().execute;
using (var communicator = initialize(initData))
{
AllTests.allTests(this);
}
}
finally
{
Dispatcher.terminate();
Executor.terminate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void run(string[] args)
Ice.InitializationData initData = new Ice.InitializationData();
initData.properties = createTestProperties(ref args);
initData.properties.setProperty("Ice.Warn.AMICallback", "0");
initData.dispatcher = new Dispatcher().dispatch;
initData.executor = new Executor().execute;

using (var communicator = initialize(initData))
{
Expand All @@ -38,7 +38,7 @@ public override void run(string[] args)
}
finally
{
Dispatcher.terminate();
Executor.terminate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using System.Diagnostics;

public class Dispatcher
public class Executor
{
private static void test(bool b)
{
Expand All @@ -12,7 +12,7 @@ private static void test(bool b)
}
}

public Dispatcher()
public Executor()
{
Debug.Assert(_instance == null);
_instance = this;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void run()
}
}

public void dispatch(System.Action call, Ice.Connection con)
public void execute(System.Action call, Ice.Connection con)
{
lock (_m)
{
Expand All @@ -81,12 +81,12 @@ static public void terminate()
_instance._thread.Join();
}

static public bool isDispatcherThread()
static public bool isExecutorThread()
{
return Thread.CurrentThread == _instance._thread;
}

private static Dispatcher _instance;
private static Executor _instance;

private Queue<System.Action> _calls = new Queue<System.Action>();
private Thread _thread;
Expand Down
Loading

0 comments on commit 38742eb

Please sign in to comment.