You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/05/08 12:13:08 UTC

[incubator-opendal] branch make-sure-writer-is-sync created (now 088800d3)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a change to branch make-sure-writer-is-sync
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


      at 088800d3 feat: Add assert for public types to make sure Send + Sync

This branch includes the following new commits:

     new 088800d3 feat: Add assert for public types to make sure Send + Sync

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-opendal] 01/01: feat: Add assert for public types to make sure Send + Sync

Posted by xu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch make-sure-writer-is-sync
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git

commit 088800d3345f3443c3d406f0603675e000d190e5
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Mon May 8 20:12:46 2023 +0800

    feat: Add assert for public types to make sure Send + Sync
    
    Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
 core/src/lib.rs          | 14 ++++++++++++++
 core/src/raw/oio/page.rs |  2 +-
 core/src/types/list.rs   | 10 ++++++++++
 core/src/types/writer.rs |  5 +++++
 4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/core/src/lib.rs b/core/src/lib.rs
index 3cf0229e..eb888d6a 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -94,4 +94,18 @@ mod tests {
         assert_eq!(1, size_of::<EntryMode>());
         assert_eq!(24, size_of::<Scheme>());
     }
+
+    /// This is used to make sure our public API implement Send + Sync
+    trait AssertSendSync: Send + Sync {}
+    impl AssertSendSync for Entry {}
+    impl AssertSendSync for Capability {}
+    impl AssertSendSync for Error {}
+    impl AssertSendSync for Reader {}
+    impl AssertSendSync for Writer {}
+    impl AssertSendSync for Lister {}
+    impl AssertSendSync for Operator {}
+    impl AssertSendSync for BlockingReader {}
+    impl AssertSendSync for BlockingWriter {}
+    impl AssertSendSync for BlockingLister {}
+    impl AssertSendSync for BlockingOperator {}
 }
diff --git a/core/src/raw/oio/page.rs b/core/src/raw/oio/page.rs
index cf21a5e7..9dd833de 100644
--- a/core/src/raw/oio/page.rs
+++ b/core/src/raw/oio/page.rs
@@ -96,7 +96,7 @@ impl<P: Page> Page for Option<P> {
 }
 
 /// BlockingPage is the blocking version of [`Page`].
-pub trait BlockingPage: 'static {
+pub trait BlockingPage: Send + 'static {
     /// Fetch a new page of [`Entry`]
     ///
     /// `Ok(None)` means all pages have been returned. Any following call
diff --git a/core/src/types/list.rs b/core/src/types/list.rs
index 708effae..275a76db 100644
--- a/core/src/types/list.rs
+++ b/core/src/types/list.rs
@@ -47,6 +47,11 @@ pub struct Lister {
     fut: Option<BoxFuture<'static, (oio::Pager, Result<Option<Vec<oio::Entry>>>)>>,
 }
 
+/// # Safety
+///
+/// Lister will only be accessed by `&mut Self`
+unsafe impl Sync for Lister {}
+
 impl Lister {
     /// Create a new lister.
     pub(crate) fn new(pager: oio::Pager) -> Self {
@@ -166,6 +171,11 @@ pub struct BlockingLister {
     buf: VecDeque<oio::Entry>,
 }
 
+/// # Safety
+///
+/// BlockingLister will only be accessed by `&mut Self`
+unsafe impl Sync for BlockingLister {}
+
 impl BlockingLister {
     /// Create a new lister.
     pub(crate) fn new(pager: oio::BlockingPager) -> Self {
diff --git a/core/src/types/writer.rs b/core/src/types/writer.rs
index e709dba3..bb6adc1b 100644
--- a/core/src/types/writer.rs
+++ b/core/src/types/writer.rs
@@ -58,6 +58,11 @@ pub struct Writer {
     state: State,
 }
 
+/// # Safety
+///
+/// Writer will only be accessed by `&mut Self`
+unsafe impl Sync for Writer {}
+
 impl Writer {
     /// Create a new writer.
     ///