Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Ice Swift src to use async/await #2534

Merged
merged 39 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3a30439
Port Ice Swift src to use async/await
externl Jul 19, 2024
8e6f19f
format
externl Jul 19, 2024
3b634d7
lots of test updates
externl Jul 22, 2024
8bc0462
Ice/exceptions
externl Jul 22, 2024
bd4f8d9
Ice/hold and Ice/location
externl Jul 22, 2024
8847cfe
Enable more
externl Jul 22, 2024
e81af2e
More
externl Jul 22, 2024
f48aaef
More
externl Jul 22, 2024
8c7076f
more
externl Jul 22, 2024
1dc72ea
checkpoint
externl Jul 22, 2024
a4c267b
checkpoint
externl Jul 22, 2024
46fb4e3
checkpoint
externl Jul 23, 2024
73b88c8
checkpoint
externl Jul 23, 2024
6aec363
checkpoint
externl Jul 23, 2024
6924c3c
checkpoint
externl Jul 25, 2024
c607d49
checkpoint
externl Jul 25, 2024
79689f3
checkpoint
externl Jul 25, 2024
63958fe
checkpoint
externl Jul 25, 2024
8957fb5
checkpoint
externl Jul 26, 2024
dca5f38
Merge remote-tracking branch 'origin/main' into swift-async-await
externl Jul 26, 2024
8575bb9
Use std::function
externl Jul 26, 2024
3184865
Merge remote-tracking branch 'origin/main' into swift-async-await
externl Jul 26, 2024
3354349
review fixes
externl Jul 26, 2024
42ca952
cleanup
externl Jul 26, 2024
a474387
var -> let
externl Jul 26, 2024
70640e8
checkpoint
externl Jul 29, 2024
d315547
Merge remote-tracking branch 'origin/main' into swift-async-await
externl Jul 29, 2024
02d2868
checkpoint
externl Jul 29, 2024
c5a7391
checkpoint
externl Jul 29, 2024
7570071
Merge remote-tracking branch 'origin/main' into swift-async-await
externl Jul 29, 2024
a828851
Update swift/src/IceImpl/DispatchAdapter.mm
externl Jul 30, 2024
949b6dc
review fixes
externl Jul 30, 2024
cf58a18
fixes
externl Jul 30, 2024
7fde880
Merge remote-tracking branch 'origin/main' into swift-async-await
externl Jul 30, 2024
c0c02ed
cleanup
externl Jul 31, 2024
978d3e3
fix
externl Jul 31, 2024
bfc2566
Merge remote-tracking branch 'origin/main' into swift-async-await
externl Jul 31, 2024
ba1d11d
Disable assert
externl Jul 31, 2024
ed0885b
Merge branch 'main' into swift-async-await
externl Aug 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
"location" : "https://github.com/zeroc-ice/mcpp.git",
"state" : {
"branch" : "master",
"revision" : "bfd4b159d9428c983e2abb48c8d344003a019caf"
}
},
{
"identity" : "promisekit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mxcl/PromiseKit.git",
"state" : {
"revision" : "6fcc08077124e9747f1ec7bd8bb78f5caffe5a79",
"version" : "8.1.2"
"revision" : "406c5e05578438c5df4c62cb9f33038f093c700f"
}
},
{
Expand Down
9 changes: 4 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,34 @@ let package = Package(
.plugin(name: "CompileSlice", targets: ["CompileSlice"]),
],
dependencies: [
.package(url: "https://github.com/mxcl/PromiseKit.git", from: "8.1.2"),
.package(url: "https://github.com/zeroc-ice/mcpp.git", branch: "master"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.1.0"),
],
targets: [
.target(
name: "Ice",
dependencies: ["IceImpl", "PromiseKit"],
dependencies: ["IceImpl"],
path: "swift/src/Ice",
resources: [.process("slice-plugin.json")],
plugins: [.plugin(name: "CompileSlice")]
),
.target(
name: "Glacier2",
dependencies: ["Ice", "PromiseKit"],
dependencies: ["Ice"],
path: "swift/src/Glacier2",
resources: [.process("slice-plugin.json")],
plugins: [.plugin(name: "CompileSlice")]
),
.target(
name: "IceGrid",
dependencies: ["Ice", "Glacier2", "PromiseKit"],
dependencies: ["Ice", "Glacier2"],
path: "swift/src/IceGrid",
resources: [.process("slice-plugin.json")],
plugins: [.plugin(name: "CompileSlice")]
),
.target(
name: "IceStorm",
dependencies: ["Ice", "PromiseKit"],
dependencies: ["Ice"],
path: "swift/src/IceStorm",
resources: [.process("slice-plugin.json")],
plugins: [.plugin(name: "CompileSlice")]
Expand Down
22 changes: 0 additions & 22 deletions cpp/include/Ice/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include "Proxy.h"
#include "SSL/ServerAuthenticationOptions.h"

#ifdef __APPLE__
# include <dispatch/dispatch.h>
#endif

namespace Ice
{
class LocatorPrx;
Expand Down Expand Up @@ -382,24 +378,6 @@ namespace Ice
*/
FacetMap findAllAdminFacets();

#ifdef __APPLE__
/**
* Returns the client dispatch queue, if any.
* @return The dispatch queue associated wih this Communicator's
* client thread pool, or nullptr if none is configured.
* @remarks This operation is only available on Apple platforms.
*/
dispatch_queue_t getClientDispatchQueue() const;

/**
* Returns the server dispatch queue
* @return The dispatch queue associated wih the Communicator's
* server thread pool, or nullptr if none is configured.
* @remarks This operation is only available on Apple platforms.
*/
dispatch_queue_t getServerDispatchQueue() const;
#endif

void postToClientThreadPool(std::function<void()> call);

private:
Expand Down
9 changes: 0 additions & 9 deletions cpp/include/Ice/Initialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,6 @@ namespace Ice
*/
std::function<void()> threadStop;

#ifdef __APPLE__
/**
* Whether or not to use a dispatch queue for ThreadPool execution. If true, each {@link ThreadPool} will
* create and use a dispatch queue for executing tasks. The default is false. Both this and {@link executor}
* cannot be set at the same time. Only available on Apple platforms.
*/
bool useDispatchQueueExecutor = false;
#endif

/**
* You can control which thread receives operation dispatches and async invocation
* callbacks by supplying an executor.
Expand Down
13 changes: 0 additions & 13 deletions cpp/include/Ice/ObjectAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
#include "ProxyFunctions.h"
#include "ServantLocator.h"

#ifdef __APPLE__
# include <dispatch/dispatch.h>
#endif

#include <memory>
#include <optional>

Expand Down Expand Up @@ -477,15 +473,6 @@ namespace Ice
*/
virtual void setPublishedEndpoints(const EndpointSeq& newEndpoints) = 0;

#ifdef __APPLE__
/**
* Get the dispatch queue used by this object adapter's thread pool, if any.
* @return The dispatch queue, or nullptr if none is configured.
* @remarks This operation is only available on Apple platforms.
*/
virtual dispatch_queue_t getDispatchQueue() const = 0;
#endif

protected:
virtual ObjectPrx _add(const ObjectPtr& servant, const Identity& id) = 0;
virtual ObjectPrx _addFacet(const ObjectPtr& servant, const Identity& id, const std::string& facet) = 0;
Expand Down
18 changes: 4 additions & 14 deletions cpp/src/Ice/CollocatedRequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,15 @@ namespace
copy(p, p + sizeof(std::int32_t), os->b.begin() + pos);
}
}

bool initHasExecutor(const InitializationData& initData)
{
#ifdef __APPLE__
if (initData.useDispatchQueueExecutor)
{
return true;
}
#endif
return initData.executor != nullptr;
}
}

CollocatedRequestHandler::CollocatedRequestHandler(const ReferencePtr& ref, const ObjectAdapterPtr& adapter)
: RequestHandler(ref),
_adapter(dynamic_pointer_cast<ObjectAdapterI>(adapter)),
_hasExecutor(initHasExecutor(_reference->getInstance()->initializationData())),
_logger(_reference->getInstance()->initializationData().logger), // Cached for better performance.
_traceLevels(_reference->getInstance()->traceLevels()), // Cached for better performance.
_hasExecutor(
_reference->getInstance()->initializationData().executor != nullptr), // Cached for better performance.
_logger(_reference->getInstance()->initializationData().logger), // Cached for better performance.
_traceLevels(_reference->getInstance()->traceLevels()), // Cached for better performance.
_requestId(0)
{
}
Expand Down
1 change: 0 additions & 1 deletion cpp/src/Ice/CollocatedRequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ namespace IceInternal
void dispatchException(std::int32_t, std::exception_ptr);

const std::shared_ptr<Ice::ObjectAdapterI> _adapter;
// The application configured a custom executor or a dispatch queue executor in InitializationData
const bool _hasExecutor;
const Ice::LoggerPtr _logger;
const TraceLevelsPtr _traceLevels;
Expand Down
15 changes: 0 additions & 15 deletions cpp/src/Ice/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,6 @@ Ice::Communicator::getValueFactoryManager() const noexcept
return _instance->initializationData().valueFactoryManager;
}

#ifdef __APPLE__
dispatch_queue_t
Ice::Communicator::getClientDispatchQueue() const
{
return _instance->clientThreadPool()->getDispatchQueue();
}

dispatch_queue_t
Ice::Communicator::getServerDispatchQueue() const
{
return _instance->serverThreadPool()->getDispatchQueue();
}

#endif

void
Ice::Communicator::postToClientThreadPool(function<void()> call)
{
Expand Down
19 changes: 4 additions & 15 deletions cpp/src/Ice/ConnectionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,6 @@ namespace
}
return os.str();
}

bool initHasExecutor(const InitializationData& initData)
{
#ifdef __APPLE__
if (initData.useDispatchQueueExecutor)
{
return true;
}
#endif
return initData.executor != nullptr;
}
}

ConnectionFlushBatchAsync::ConnectionFlushBatchAsync(const ConnectionIPtr& connection, const InstancePtr& instance)
Expand Down Expand Up @@ -1792,10 +1781,10 @@ Ice::ConnectionI::ConnectionI(
_connector(connector),
_endpoint(endpoint),
_adapter(adapter),
_hasExecutor(initHasExecutor(_instance->initializationData())), // Cached for better performance.
_logger(_instance->initializationData().logger), // Cached for better performance.
_traceLevels(_instance->traceLevels()), // Cached for better performance.
_timer(_instance->timer()), // Cached for better performance.
_hasExecutor(_instance->initializationData().executor != nullptr), // Cached for better performance.
_logger(_instance->initializationData().logger), // Cached for better performance.
_traceLevels(_instance->traceLevels()), // Cached for better performance.
_timer(_instance->timer()), // Cached for better performance.
_connectTimeout(options.connectTimeout),
_closeTimeout(options.closeTimeout), // not used for datagram connections
// suppress inactivity timeout for datagram connections
Expand Down
1 change: 0 additions & 1 deletion cpp/src/Ice/ConnectionI.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ namespace Ice

ObjectAdapterIPtr _adapter;

// The application configured a custom executor or a dispatch queue executor in InitializationData
const bool _hasExecutor;

const LoggerPtr _logger;
Expand Down
12 changes: 0 additions & 12 deletions cpp/src/Ice/ObjectAdapterI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,18 +686,6 @@ Ice::ObjectAdapterI::setPublishedEndpoints(const EndpointSeq& newEndpoints)
}
}

#ifdef __APPLE__
dispatch_queue_t
Ice::ObjectAdapterI::getDispatchQueue() const
{
lock_guard lock(_mutex);

checkForDeactivation();

return getThreadPool()->getDispatchQueue();
}
#endif

bool
Ice::ObjectAdapterI::isLocal(const ReferencePtr& ref) const
{
Expand Down
8 changes: 0 additions & 8 deletions cpp/src/Ice/ObjectAdapterI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
#include "ServantManagerF.h"
#include "ThreadPoolF.h"

#ifdef __APPLE__
# include <dispatch/dispatch.h>
#endif

#include <list>
#include <mutex>
#include <optional>
Expand Down Expand Up @@ -87,10 +83,6 @@ namespace Ice
EndpointSeq getPublishedEndpoints() const noexcept;
void setPublishedEndpoints(const EndpointSeq&) final;

#ifdef __APPLE__
dispatch_queue_t getDispatchQueue() const final;
#endif

bool isLocal(const IceInternal::ReferencePtr&) const;

void flushAsyncBatchRequests(const IceInternal::CommunicatorFlushBatchAsyncPtr&, CompressBatch);
Expand Down
72 changes: 1 addition & 71 deletions cpp/src/Ice/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,6 @@ namespace
class ThreadPoolDestroyedException
{
};

#ifdef __APPLE__
string prefixToDispatchQueueLabel(string_view prefix)
{
if (prefix == "Ice.ThreadPool.Client")
{
return "com.zeroc.ice.client";
}

if (prefix == "Ice.ThreadPool.Server")
{
return "com.zeroc.ice.server";
}

string::size_type end = prefix.find_last_of(".ThreadPool");
if (end == string::npos)
{
end = prefix.size();
}

return "com.zeroc.ice.oa." + string{prefix.substr(0, end)};
}

dispatch_queue_t initDispatchQueue(const InitializationData& initData, string_view prefix)
{
if (initData.useDispatchQueueExecutor)
{
return dispatch_queue_create(
prefixToDispatchQueueLabel(prefix).c_str(),
DISPATCH_QUEUE_CONCURRENT_WITH_AUTORELEASE_POOL);
}
return nullptr;
}
#endif
}

IceInternal::ThreadPoolWorkQueue::ThreadPoolWorkQueue(ThreadPool& threadPool)
Expand Down Expand Up @@ -182,9 +148,6 @@ IceInternal::ThreadPool::create(const InstancePtr& instance, const string& prefi

IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& prefix, int timeout)
: _instance(instance),
#ifdef __APPLE__
_dispatchQueue(initDispatchQueue(instance->initializationData(), prefix)),
#endif
_executor(_instance->initializationData().executor),
_destroyed(false),
_prefix(prefix),
Expand All @@ -207,22 +170,6 @@ IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& p
#endif
_promote(true)
{
#ifdef __APPLE__
if (_dispatchQueue && _executor)
{
throw InitializationException{__FILE__, __LINE__, "cannot use both dispatch queues and custom executors"};
}

if (_dispatchQueue)
{
_executor = [dispatchQueue = _dispatchQueue](function<void()> call, const Ice::ConnectionPtr&)
{
dispatch_sync(dispatchQueue, ^{
call();
});
};
}
#endif
}

void
Expand Down Expand Up @@ -365,16 +312,7 @@ IceInternal::ThreadPool::initialize()
}
}

IceInternal::ThreadPool::~ThreadPool()
{
assert(_destroyed);
#ifdef __APPLE__
if (_dispatchQueue)
{
dispatch_release(_dispatchQueue);
}
#endif
}
IceInternal::ThreadPool::~ThreadPool() { assert(_destroyed); }

void
IceInternal::ThreadPool::destroy()
Expand Down Expand Up @@ -577,14 +515,6 @@ IceInternal::ThreadPool::prefix() const
return _prefix;
}

#ifdef __APPLE__
dispatch_queue_t
IceInternal::ThreadPool::getDispatchQueue() const noexcept
{
return _dispatchQueue;
}
#endif

void
IceInternal::ThreadPool::run(const EventHandlerThreadPtr& thread)
{
Expand Down
Loading
Loading