celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] Oipo commented on a change in pull request #318: Feature/promise scheduler abstraction
Date Tue, 16 Feb 2021 19:29:07 GMT

Oipo commented on a change in pull request #318:
URL: https://github.com/apache/celix/pull/318#discussion_r577075923



##########
File path: libs/promises/api/celix/DefaultScheduledExecutor.h
##########
@@ -0,0 +1,138 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#pragma once
+
+#include <memory>
+#include <future>
+#include <functional>
+#include <unordered_map>
+
+#include "celix/IScheduledExecutor.h"
+
+namespace celix {
+
+    class DefaultDelayedScheduledFuture : public celix::IScheduledFuture {
+    public:
+        explicit DefaultDelayedScheduledFuture(std::chrono::duration<double, std::milli>
_delayInMs) : delayInMs{_delayInMs} {}
+
+        ~DefaultDelayedScheduledFuture() noexcept override = default;
+
+        bool isCancelled() const override {
+            std::lock_guard<std::mutex> lock{mutex};
+            return cancelled;
+        }
+
+        bool isDone() const override {
+            std::lock_guard<std::mutex> lock{mutex};
+            return done;
+        }
+
+        void setDone() {
+            std::lock_guard<std::mutex> lock{mutex};
+            done = true;
+            cond.notify_all();
+        }
+
+        void cancel() override {
+            std::lock_guard<std::mutex> lock{mutex};
+            cancelled = true;
+            cond.notify_all();
+        }
+
+        std::chrono::duration<double, std::milli> getDelayInMs() const {
+            std::lock_guard<std::mutex> lock{mutex};
+            return delayInMs;

Review comment:
       delayInMs cannot be updated, as such, it does not need a lock_guard.

##########
File path: libs/promises/api/celix/DefaultScheduledExecutor.h
##########
@@ -0,0 +1,138 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#pragma once
+
+#include <memory>
+#include <future>
+#include <functional>
+#include <unordered_map>
+
+#include "celix/IScheduledExecutor.h"
+
+namespace celix {
+
+    class DefaultDelayedScheduledFuture : public celix::IScheduledFuture {
+    public:
+        explicit DefaultDelayedScheduledFuture(std::chrono::duration<double, std::milli>
_delayInMs) : delayInMs{_delayInMs} {}
+
+        ~DefaultDelayedScheduledFuture() noexcept override = default;
+
+        bool isCancelled() const override {
+            std::lock_guard<std::mutex> lock{mutex};
+            return cancelled;
+        }
+
+        bool isDone() const override {
+            std::lock_guard<std::mutex> lock{mutex};
+            return done;
+        }
+
+        void setDone() {
+            std::lock_guard<std::mutex> lock{mutex};
+            done = true;
+            cond.notify_all();
+        }
+
+        void cancel() override {
+            std::lock_guard<std::mutex> lock{mutex};
+            cancelled = true;
+            cond.notify_all();
+        }
+
+        std::chrono::duration<double, std::milli> getDelayInMs() const {
+            std::lock_guard<std::mutex> lock{mutex};
+            return delayInMs;
+        }
+
+        void waitFor(std::chrono::duration<double, std::milli> time) {
+            std::unique_lock<std::mutex> lock{mutex};
+            cond.wait_for(lock, time);
+        }
+    private:
+        [[nodiscard]] std::chrono::duration<double, std::milli> getDelayOrPeriodInMilli()
const override {

Review comment:
       Unused function?

##########
File path: libs/promises/api/celix/DefaultScheduledExecutor.h
##########
@@ -0,0 +1,138 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you under the Apache License, Version 2.0 (the
+ *"License"); you may not use this file except in compliance
+ *with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *Unless required by applicable law or agreed to in writing,
+ *software distributed under the License is distributed on an
+ *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ *specific language governing permissions and limitations
+ *under the License.
+ */
+
+#pragma once
+
+#include <memory>
+#include <future>
+#include <functional>
+#include <unordered_map>
+
+#include "celix/IScheduledExecutor.h"
+
+namespace celix {
+
+    class DefaultDelayedScheduledFuture : public celix::IScheduledFuture {
+    public:
+        explicit DefaultDelayedScheduledFuture(std::chrono::duration<double, std::milli>
_delayInMs) : delayInMs{_delayInMs} {}
+
+        ~DefaultDelayedScheduledFuture() noexcept override = default;
+
+        bool isCancelled() const override {
+            std::lock_guard<std::mutex> lock{mutex};

Review comment:
       In C++17, specifying the template type is not necessary here. More info [here](https://accu.org/journals/overload/26/143/orr_2465/).

##########
File path: libs/promises/api/celix/impl/SharedPromiseState.h
##########
@@ -106,9 +107,11 @@ namespace celix::impl {
 
         std::shared_ptr<celix::IExecutor> getExecutor() const;
 
+        std::shared_ptr<celix::IScheduledExecutor> getScheduledExecutor() const;

Review comment:
       This function (and coincidentally the `getExecutor` function that was already there,
are good examples of being marked with `[[nodiscard]]`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message