From 6940ad2b06f4f8d6f90bed1df69396e7dcee6873 Mon Sep 17 00:00:00 2001 From: Christian Risi <75698846+CnF-Gris@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:03:24 +0000 Subject: [PATCH] V0.6.1 Arroyo Toad Fixed MultiThread support, now supporting 1K devices --- Sources/IoT-Simulator-Core/Classes/Devices/EdgeDevice.swift | 1 + Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift | 5 ++--- Tests/IoT-Simulator-CoreTests/IoTCore-Tests.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/IoT-Simulator-Core/Classes/Devices/EdgeDevice.swift b/Sources/IoT-Simulator-Core/Classes/Devices/EdgeDevice.swift index 50ae599..c0639ab 100644 --- a/Sources/IoT-Simulator-Core/Classes/Devices/EdgeDevice.swift +++ b/Sources/IoT-Simulator-Core/Classes/Devices/EdgeDevice.swift @@ -51,6 +51,7 @@ public class EdgeDevice: EdgeDeviceP { // UGLY: Declaring here some variables manually, remove them if you want to offere flexibility let numberOfSamples: Int = 10 + // FIXME: Probably here we have some pointer problems let rowPointer = UnsafeMutablePointer?>.allocate(capacity: numberOfSamples) diff --git a/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift b/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift index dad3472..be61ccd 100644 --- a/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift +++ b/Sources/IoT-Simulator-Core/IoT_Simulator_Core.swift @@ -26,7 +26,7 @@ public actor IoTSimulatorCore { // schedule work let task = IoTSimulatorCore.schedule(envID: environment.location, deviceID: device.deviceID) { msg in - //print("\(msg.description)\n\n") + print("\(msg.description)\n\n") } failure: { print("Something is wrong") } @@ -67,7 +67,6 @@ public actor IoTSimulatorCore { let env = IoTSimulatorCore.getEnv(name: envID)! while notCancelled { - usleep(__useconds_t(dev.dutyCicle * 1000)) let message = dev.work(envrionment: env) do { @@ -77,7 +76,7 @@ public actor IoTSimulatorCore { } do { - try Task.checkCancellation() + try await Task.sleep(nanoseconds: UInt64(dev.dutyCicle) * UInt64(1E6)) } catch { notCancelled = false diff --git a/Tests/IoT-Simulator-CoreTests/IoTCore-Tests.swift b/Tests/IoT-Simulator-CoreTests/IoTCore-Tests.swift index 8d958a2..3206c5a 100644 --- a/Tests/IoT-Simulator-CoreTests/IoTCore-Tests.swift +++ b/Tests/IoT-Simulator-CoreTests/IoTCore-Tests.swift @@ -66,7 +66,7 @@ import Testing @Test func stressLoop1() async throws { - let devices: Int = 1000 + let devices: Int = 5000 let env = PhysicalEnvironment("Delta") let truth = PhysicalData(.Temperature, 22)