]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ukfile: Add try acquire operation
authorAndrei Tatar <andrei@unikraft.io>
Tue, 24 Sep 2024 15:03:34 +0000 (17:03 +0200)
committerUnikraft Bot <monkey@unikraft.io>
Mon, 10 Feb 2025 10:47:39 +0000 (10:47 +0000)
This change adds a try_acquire operation on files which allows callers
holding a weakref to attempt to take a strong ref. This call may fail if
no other strongrefs are currently held (and thus finalizers and the
destructor are scheduled to run).

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1579

lib/ukfile/include/uk/file.h
lib/ukfile/include/uk/file/final.h

index a1ebcdf7da3cf42df214bdc3d1ef7d6936e05ddb..402a55ddfca171eda8b785a02b80fbdccc60a51a 100644 (file)
@@ -183,6 +183,7 @@ typedef struct uk_file_finref uk_file_refcnt;
 
 #define uk_file_refcnt_acquire         uk_file_finref_acquire
 #define uk_file_refcnt_acquire_weak    uk_file_finref_acquire_weak
+#define uk_file_refcnt_try_acquire     uk_file_finref_try_acquire
 #define uk_file_refcnt_release         uk_file_finref_release
 #define uk_file_refcnt_release_weak    uk_file_finref_release_weak
 
@@ -196,6 +197,7 @@ typedef struct uk_swrefcount uk_file_refcnt;
 
 #define uk_file_refcnt_acquire         uk_swrefcount_acquire
 #define uk_file_refcnt_acquire_weak    uk_swrefcount_acquire_weak
+#define uk_file_refcnt_try_acquire     uk_swrefcount_try_acquire
 #define uk_file_refcnt_release         uk_swrefcount_release
 #define uk_file_refcnt_release_weak    uk_swrefcount_release_weak
 
@@ -268,6 +270,12 @@ void uk_file_acquire_weak(const struct uk_file *f)
        uk_file_refcnt_acquire_weak(f->refcnt);
 }
 
+static inline
+int uk_file_try_acquire(const struct uk_file *f)
+{
+       return uk_file_refcnt_try_acquire(f->refcnt);
+}
+
 static inline
 void uk_file_release(const struct uk_file *f)
 {
index dda133d145bf27d91e820b5f1f63e4b0c735509c..6905d72837a357087c8048c7ce09be63f27eb9a9 100644 (file)
@@ -51,6 +51,12 @@ void uk_file_finref_acquire_weak(struct uk_file_finref *r)
        uk_swrefcount_acquire_weak(&r->cnt);
 }
 
+static inline
+int uk_file_finref_try_acquire(struct uk_file_finref *r)
+{
+       return uk_swrefcount_try_acquire(&r->cnt);
+}
+
 static inline
 int uk_file_finref_release(struct uk_file_finref *r)
 {