#include <shared-queue.hpp>
#include "launchpad-process-pool/log_private.hh"
+#include "launchpad-process-pool/rec_mutex.hh"
namespace launchpad {
namespace {
if (conn_)
return conn_;
+ std::lock_guard<std::recursive_mutex> lock(RecMutex::GetInst().GetMutex());
GError* error = nullptr;
conn_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
if (conn_ == nullptr) {
#include <sched_priority.hh>
#include "launchpad-process-pool/log_private.hh"
+#include "launchpad-process-pool/rec_mutex.hh"
namespace launchpad {
Executor::Executor(Executor::Delegator* delegator) : delegator_(delegator) {}
pid_t Executor::Execute(int priority) {
+ std::lock_guard<std::recursive_mutex> lock(RecMutex::GetInst().GetMutex());
pid_t pid = fork();
if (pid == -1) {
_E("Failed to create child process. errno(%d)", errno);
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed 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.
+ */
+
+#ifndef LAUNCHPAD_PROCESS_POOL_REC_MUTEX_HH_
+#define LAUNCHPAD_PROCESS_POOL_REC_MUTEX_HH_
+
+#include <mutex>
+
+namespace launchpad {
+
+class RecMutex {
+ public:
+ static RecMutex& GetInst() {
+ static RecMutex inst;
+ return inst;
+ }
+
+ std::recursive_mutex& GetMutex() const {
+ return mutex_;
+ }
+
+ private:
+ RecMutex() = default;
+ ~RecMutex() = default;
+
+ private:
+ mutable std::recursive_mutex mutex_;
+};
+
+} // namespace launchpad
+
+#endif // LAUNCHPAD_PROCESS_POOL_REC_MUTEX_HH_