Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into common-object2
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Jan 17, 2024
2 parents f0ef4b4 + 3df69f4 commit 68d53bb
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 57 deletions.
16 changes: 13 additions & 3 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Build Ice
runs:
using: "composite"
steps:
# Linux / macOS
- name: Build C++ Dependencies
run: make -j3 V=1 -C cpp srcs
shell: bash
Expand All @@ -16,12 +17,21 @@ runs:
if: (runner.os == 'macOS' || runner.os == 'Linux') && (matrix.language == 'php' || matrix.language == 'js' || matrix.language == 'ruby')

- name: Build ${{ matrix.language }}
working-directory: ./${{ matrix.language }}
run: |
make -j3 V=1 LANGUAGES="${{ matrix.language }}"
make -j3 V=1
shell: bash
if: runner.os == 'macOS' || runner.os == 'Linux'

- name: Build
run: msbuild /m /p:Platform=x64 ice.proj
# Windows
- name: Build C++ Dependencies
run: msbuild /m /p:Platform=x64 msbuild/ice.proj
working-directory: ./cpp
shell: powershell
if: runner.os == 'Windows'

- name: Build ${{ matrix.language }}
run: msbuild /m /p:Platform=x64 msbuild/ice.proj
working-directory: ./${{ matrix.language }}
shell: powershell
if: runner.os == 'Windows'
29 changes: 10 additions & 19 deletions objective-c/src/Ice/Initialize.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@

namespace
{
typedef std::map<int, std::string> CompactIdMap;
using CompactIdMap = std::map<int, std::string>;

IceUtil::Mutex* _compactIdMapMutex = 0;
// The std::mutex consturctor is constexpr so this mutex is statically initialized
std::mutex _compactIdMapMutex;
CompactIdMap* _compactIdMap = 0;

class CompactIdResolverI : public Ice::CompactIdResolver
Expand All @@ -59,10 +60,9 @@
virtual ::std::string
resolve(::Ice::Int value) const
{
assert(_compactIdMapMutex);
assert(_compactIdMap);

IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_compactIdMapMutex);
std::lock_guard lock(_compactIdMapMutex);
CompactIdMap::iterator p = _compactIdMap->find(value);
if(p != _compactIdMap->end())
{
Expand All @@ -73,8 +73,7 @@
};

//
// We don't use the constructor to initialize the compactIdMap as
// static initializtion takes place after +load is called.
// We don't use the constructor to initialize the compactIdMap as the initializtion takes place after +load is called.
//
class Init
{
Expand All @@ -87,12 +86,6 @@
delete _compactIdMap;
_compactIdMap = 0;
}

if(_compactIdMapMutex)
{
delete _compactIdMapMutex;
_compactIdMapMutex = 0;
}
}
};
Init init;
Expand All @@ -102,18 +95,15 @@
@implementation CompactIdMapHelper
+(void) initialize
{
assert(!_compactIdMapMutex);
assert(!_compactIdMap);
_compactIdMapMutex = new ::IceUtil::Mutex;
_compactIdMap = new CompactIdMap;
}

+(void) registerClass:(NSString*)type value:(ICEInt)value
{
assert(_compactIdMapMutex);
assert(_compactIdMap);

IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_compactIdMapMutex);
std::lock_guard lock(_compactIdMapMutex);
CompactIdMap::iterator p = _compactIdMap->find(value);
if(p != _compactIdMap->end())
{
Expand All @@ -126,7 +116,7 @@ +(void) registerClass:(NSString*)type value:(ICEInt)value
namespace IceObjC
{

class ThreadNotification : public Ice::ThreadNotification, public IceUtil::Mutex
class ThreadNotification : public Ice::ThreadNotification
{
public:

Expand All @@ -136,13 +126,13 @@ +(void) registerClass:(NSString*)type value:(ICEInt)value

virtual void start()
{
Lock sync(*this);
std::lock_guard lock(_mutex);
_pools.insert(std::make_pair(IceUtil::ThreadControl().id(), [[NSAutoreleasePool alloc] init]));
}

virtual void stop()
{
Lock sync(*this);
std::lock_guard lock(_mutex);
std::map<IceUtil::ThreadControl::ID, NSAutoreleasePool*>::iterator p =
_pools.find(IceUtil::ThreadControl().id());
[p->second drain];
Expand All @@ -152,6 +142,7 @@ virtual void stop()
private:

std::map<IceUtil::ThreadControl::ID, NSAutoreleasePool*> _pools;
std::mutex _mutex;
};

};
Expand Down
2 changes: 1 addition & 1 deletion objective-c/src/Ice/PropertiesI.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@interface ICENativePropertiesAdmin : ICEServantWrapper<ICENativePropertiesAdmin>
{
IceUtil::Mutex mutex_;
std::mutex mutex_;
std::vector<std::pair<id, std::function<void()>>> callbacks_;
}
@end
4 changes: 2 additions & 2 deletions objective-c/src/Ice/PropertiesI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ -(void) load:(NSString*)file
@implementation ICENativePropertiesAdmin
-(void) addUpdateCallback:(id<ICEPropertiesAdminUpdateCallback>)cb
{
IceUtil::Mutex::Lock sync(mutex_);
std::lock_guard lock(mutex_);

std::function<void()> remover = std::dynamic_pointer_cast<Ice::NativePropertiesAdmin>(object_)->addUpdateCallback(
[cb](const Ice::PropertyDict& properties)
Expand Down Expand Up @@ -254,7 +254,7 @@ -(void) addUpdateCallback:(id<ICEPropertiesAdminUpdateCallback>)cb

-(void) removeUpdateCallback:(id<ICEPropertiesAdminUpdateCallback>)cb
{
IceUtil::Mutex::Lock sync(mutex_);
std::lock_guard lock(mutex_);

// Each removeUpdateCallback only removes the first occurrence
auto p = std::find_if(callbacks_.begin(), callbacks_.end(), [cb](const auto& q) { return q.first == cb; });
Expand Down
34 changes: 9 additions & 25 deletions php/src/Communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ const string _defaultProfileName = "";
//
typedef map<string, ActiveCommunicatorPtr> RegisteredCommunicatorMap;
RegisteredCommunicatorMap _registeredCommunicators;
IceUtil::Mutex* _registeredCommunicatorsMutex = 0;

// std::mutex constructor is constexpr so it is statically initialized
std::mutex _registeredCommunicatorsMutex;

IceUtil::TimerPtr _timer;

Expand All @@ -228,24 +230,6 @@ IceUtil::TimerPtr _timer;
// been used) by the request.
//
typedef map<Ice::CommunicatorPtr, CommunicatorInfoIPtr> CommunicatorMap;

class Init
{
public:

Init()
{
_registeredCommunicatorsMutex = new IceUtil::Mutex();
}

~Init()
{
delete _registeredCommunicatorsMutex;
_registeredCommunicatorsMutex = 0;
}
};

Init init;
}

extern "C"
Expand Down Expand Up @@ -335,7 +319,7 @@ ZEND_METHOD(Ice_Communicator, destroy)
// Remove all registrations.
//
{
IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_registeredCommunicatorsMutex);
lock_guard lock(_registeredCommunicatorsMutex);
for(vector<string>::iterator p = _this->ac->ids.begin(); p != _this->ac->ids.end(); ++p)
{
_registeredCommunicators.erase(*p);
Expand Down Expand Up @@ -1260,7 +1244,7 @@ ZEND_FUNCTION(Ice_register)
CommunicatorInfoIPtr info = Wrapper<CommunicatorInfoIPtr>::value(comm);
assert(info);

IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_registeredCommunicatorsMutex);
lock_guard lock(_registeredCommunicatorsMutex);

RegisteredCommunicatorMap::iterator p = _registeredCommunicators.find(id);
if(p != _registeredCommunicators.end())
Expand Down Expand Up @@ -1312,7 +1296,7 @@ ZEND_FUNCTION(Ice_unregister)

string id(s, sLen);

IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_registeredCommunicatorsMutex);
lock_guard lock(_registeredCommunicatorsMutex);

RegisteredCommunicatorMap::iterator p = _registeredCommunicators.find(id);
if(p == _registeredCommunicators.end())
Expand Down Expand Up @@ -1347,7 +1331,7 @@ ZEND_FUNCTION(Ice_find)

string id(s, sLen);

IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_registeredCommunicatorsMutex);
lock_guard lock(_registeredCommunicatorsMutex);

RegisteredCommunicatorMap::iterator p = _registeredCommunicators.find(id);
if(p == _registeredCommunicators.end())
Expand Down Expand Up @@ -1802,7 +1786,7 @@ IcePHP::communicatorShutdown(void)
{
_profiles.clear();

IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_registeredCommunicatorsMutex);
lock_guard lock(_registeredCommunicatorsMutex);

if(_timer)
{
Expand Down Expand Up @@ -2198,7 +2182,7 @@ IcePHP::ValueFactoryManager::destroy()
void
IcePHP::ReaperTask::runTimerTask()
{
IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_registeredCommunicatorsMutex);
lock_guard lock(_registeredCommunicatorsMutex);

IceUtil::Time now = IceUtil::Time::now();
RegisteredCommunicatorMap::iterator p = _registeredCommunicators.begin();
Expand Down
3 changes: 2 additions & 1 deletion python/modules/IcePy/ValueFactoryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include <Config.h>
#include <Ice/ValueFactory.h>
#include <IceUtil/Mutex.h>

#include <mutex>

namespace IcePy
{
Expand Down
10 changes: 5 additions & 5 deletions ruby/src/IceRuby/ValueFactoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ IceRuby::ValueFactoryManager::add(Ice::ValueFactoryFunc, const string&)
void
IceRuby::ValueFactoryManager::add(const Ice::ValueFactoryPtr& f, const string& id)
{
Lock lock(*this);
std::lock_guard lock(_mutex);

if(id.empty())
{
Expand Down Expand Up @@ -129,7 +129,7 @@ IceRuby::ValueFactoryManager::find(const string& id) const noexcept
Ice::ValueFactoryPtr
IceRuby::ValueFactoryManager::findCore(const string& id) const noexcept
{
Lock lock(*this);
std::lock_guard lock(_mutex);

if(id.empty())
{
Expand Down Expand Up @@ -176,7 +176,7 @@ IceRuby::ValueFactoryManager::findValueFactory(const string& id) const
void
IceRuby::ValueFactoryManager::mark()
{
Lock lock(*this);
std::lock_guard lock(_mutex);

for(FactoryMap::iterator p = _factories.begin(); p != _factories.end(); ++p)
{
Expand All @@ -196,7 +196,7 @@ IceRuby::ValueFactoryManager::markSelf()
volatile VALUE self;

{
Lock lock(*this);
std::lock_guard lock(_mutex);

self = _self;
}
Expand All @@ -219,7 +219,7 @@ IceRuby::ValueFactoryManager::destroy()
FactoryMap factories;

{
Lock lock(*this);
std::lock_guard lock(_mutex);
if(_self == Qnil)
{
//
Expand Down
4 changes: 3 additions & 1 deletion ruby/src/IceRuby/ValueFactoryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DefaultValueFactory : public Ice::ValueFactory
};
using DefaultValueFactoryPtr = std::shared_ptr<DefaultValueFactory>;

class ValueFactoryManager final : public Ice::ValueFactoryManager, public IceUtil::Mutex
class ValueFactoryManager final : public Ice::ValueFactoryManager
{
public:

Expand Down Expand Up @@ -88,6 +88,8 @@ class ValueFactoryManager final : public Ice::ValueFactoryManager, public IceUti
VALUE _self;
FactoryMap _factories;
DefaultValueFactoryPtr _defaultFactory;

mutable std::mutex _mutex;
};
using ValueFactoryManagerPtr = std::shared_ptr<ValueFactoryManager>;

Expand Down

0 comments on commit 68d53bb

Please sign in to comment.