Skip to content

Commit

Permalink
[sm,launcher] Use list to store current instances instead of array
Browse files Browse the repository at this point in the history
During process instances (namely stop instances) concurrently, we remove
instances from array. It leads to array rearrangement, as result currently
processed instances may point to wrong place. Use list instead of array to avoid
this issue.

Signed-off-by: Oleksandr Grytsov <[email protected]>
  • Loading branch information
al1img committed Jan 30, 2025
1 parent 96b4ac6 commit 12f45f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
6 changes: 3 additions & 3 deletions include/aos/sm/launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "aos/common/connectionsubsc.hpp"
#include "aos/common/monitoring/monitoring.hpp"
#include "aos/common/ocispec/ocispec.hpp"
#include "aos/common/tools/map.hpp"
#include "aos/common/tools/list.hpp"
#include "aos/common/tools/noncopyable.hpp"
#include "aos/common/types.hpp"
#include "aos/sm/config.hpp"
Expand Down Expand Up @@ -391,7 +391,7 @@ class Launcher : public LauncherItf,
[&serviceID](const servicemanager::ServiceData& service) { return serviceID == service.mServiceID; });
}

Instance* GetInstance(const String& instanceID)
List<Instance>::Iterator GetInstance(const String& instanceID)
{
return mCurrentInstances.FindIf(
[&instanceID](const Instance& instance) { return instanceID == instance.InstanceID(); });
Expand Down Expand Up @@ -423,7 +423,7 @@ class Launcher : public LauncherItf,
mutable ConditionalVariable mCondVar;

StaticArray<servicemanager::ServiceData, cMaxNumServices> mCurrentServices;
StaticArray<Instance, cMaxNumInstances> mCurrentInstances;
StaticList<Instance, cMaxNumInstances> mCurrentInstances;
cloudprotocol::EnvVarsInstanceInfoArray mCurrentEnvVars;
StaticString<cFilePathLen> mHostWhiteoutsDir;
NodeInfo mNodeInfo;
Expand Down
5 changes: 0 additions & 5 deletions include/aos/sm/launcher/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ class RuntimeItf {
*/
class Instance {
public:
/**
* Creates instance.
*/
Instance() = default;

/**
* Creates instance.
*
Expand Down
4 changes: 2 additions & 2 deletions src/sm/launcher/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ Error Launcher::StartInstance(const InstanceData& info)
return AOS_ERROR_WRAP(err);
}

instance = &mCurrentInstances[mCurrentInstances.Size() - 1];
instance = &mCurrentInstances.Back();

auto service = GetService(info.mInstanceInfo.mInstanceIdent.mServiceID);
if (service == mCurrentServices.end()) {
Expand Down Expand Up @@ -906,7 +906,7 @@ Error Launcher::StartInstance(const InstanceData& info)

Error Launcher::StopInstance(const String& instanceID)
{
Instance* instance = nullptr;
List<Instance>::Iterator instance;

{
LockGuard lock {mMutex};
Expand Down

0 comments on commit 12f45f9

Please sign in to comment.