aboutsummaryrefslogtreecommitdiff
path: root/pw_sync_zephyr/public
diff options
context:
space:
mode:
Diffstat (limited to 'pw_sync_zephyr/public')
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h2
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h2
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_inline.h36
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_native.h31
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_inline.h41
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_native.h23
-rw-r--r--pw_sync_zephyr/public/pw_sync_zephyr/timed_thread_notification_inline.h33
7 files changed, 166 insertions, 2 deletions
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h
index 9afe7ceb1..7bd05509a 100644
--- a/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_inline.h
@@ -13,7 +13,7 @@
// the License.
#pragma once
-#include <kernel.h>
+#include <zephyr/kernel.h>
#include "pw_assert/assert.h"
#include "pw_chrono/system_clock.h"
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h
index 946a93433..fbe82a7c4 100644
--- a/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/binary_semaphore_native.h
@@ -13,7 +13,7 @@
// the License.
#pragma once
-#include <kernel.h>
+#include <zephyr/kernel.h>
namespace pw::sync::backend {
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_inline.h b/pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_inline.h
new file mode 100644
index 000000000..c98f6d9ad
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_inline.h
@@ -0,0 +1,36 @@
+// Copyright 2023 The Pigweed Authors
+//
+// 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
+//
+// https://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 "pw_sync/interrupt_spin_lock.h"
+
+namespace pw::sync {
+
+constexpr InterruptSpinLock::InterruptSpinLock()
+ : native_type_{.lock = {}, .locked = false, .key = {0}} {}
+
+inline bool InterruptSpinLock::try_lock() {
+ // This backend will spin the current processor until the deadlock is
+ // available and does not implement a 'try' mechanism. Recursive locking is
+ // already detected by lock().
+ lock();
+ return true;
+}
+
+inline InterruptSpinLock::native_handle_type
+InterruptSpinLock::native_handle() {
+ return native_type_;
+}
+
+} // namespace pw::sync
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_native.h b/pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_native.h
new file mode 100644
index 000000000..4cd71e037
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/interrupt_spin_lock_native.h
@@ -0,0 +1,31 @@
+// Copyright 2023 The Pigweed Authors
+//
+// 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
+//
+// https://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 <zephyr/spinlock.h>
+
+#include "pw_sync/interrupt_spin_lock.h"
+
+namespace pw::sync::backend {
+
+struct ZephyrSpinLock {
+ struct k_spinlock lock;
+ bool locked; // Used to detect recursion.
+ k_spinlock_key_t key;
+};
+
+using NativeInterruptSpinLock = struct ZephyrSpinLock;
+using NativeInterruptSpinLockHandle = NativeInterruptSpinLock&;
+
+} // namespace pw::sync::backend
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_inline.h b/pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_inline.h
new file mode 100644
index 000000000..f14028ce2
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_inline.h
@@ -0,0 +1,41 @@
+// Copyright 2023 The Pigweed Authors
+//
+// 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
+//
+// https://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 <zephyr/sys/sem.h>
+
+#include "pw_assert/assert.h"
+#include "pw_interrupt/context.h"
+#include "pw_sync/thread_notification.h"
+
+namespace pw::sync {
+
+inline ThreadNotification::ThreadNotification() : native_type_() {}
+
+inline ThreadNotification::~ThreadNotification() = default;
+
+inline void ThreadNotification::release() { native_type_.release(); }
+
+inline void ThreadNotification::acquire() { native_type_.acquire(); }
+
+inline bool ThreadNotification::try_acquire() {
+ return native_type_.try_acquire();
+}
+
+inline ThreadNotification::native_handle_type
+ThreadNotification::native_handle() {
+ return native_type_;
+}
+
+} // namespace pw::sync
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_native.h b/pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_native.h
new file mode 100644
index 000000000..5fb0495ef
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/thread_notification_native.h
@@ -0,0 +1,23 @@
+// Copyright 2023 The Pigweed Authors
+//
+// 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
+//
+// https://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 <pw_sync/binary_semaphore.h>
+
+namespace pw::sync::backend {
+
+using NativeThreadNotification = pw::sync::BinarySemaphore;
+using NativeThreadNotificationHandle = NativeThreadNotification&;
+
+} // namespace pw::sync::backend
diff --git a/pw_sync_zephyr/public/pw_sync_zephyr/timed_thread_notification_inline.h b/pw_sync_zephyr/public/pw_sync_zephyr/timed_thread_notification_inline.h
new file mode 100644
index 000000000..c24388f92
--- /dev/null
+++ b/pw_sync_zephyr/public/pw_sync_zephyr/timed_thread_notification_inline.h
@@ -0,0 +1,33 @@
+// Copyright 2023 The Pigweed Authors
+//
+// 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
+//
+// https://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 <pw_sync/binary_semaphore.h>
+
+#include "pw_chrono/system_clock.h"
+#include "pw_sync/timed_thread_notification.h"
+
+namespace pw::sync {
+
+inline bool TimedThreadNotification::try_acquire_for(
+ chrono::SystemClock::duration timeout) {
+ return native_handle().try_acquire_for(timeout);
+}
+
+inline bool TimedThreadNotification::try_acquire_until(
+ chrono::SystemClock::time_point deadline) {
+ return try_acquire_for(deadline - chrono::SystemClock::now());
+}
+
+} // namespace pw::sync