From: Andrei Tatar Date: Tue, 24 Sep 2024 15:03:34 +0000 (+0200) Subject: lib/ukfile: Add try acquire operation X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=5269bcbc73682660c82eb784ff3e973d741db1bd;p=unikraft%2Funikraft.git lib/ukfile: Add try acquire operation 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 Approved-by: Sergiu Moga Reviewed-by: Sergiu Moga GitHub-Closes: #1579 --- diff --git a/lib/ukfile/include/uk/file.h b/lib/ukfile/include/uk/file.h index a1ebcdf7d..402a55ddf 100644 --- a/lib/ukfile/include/uk/file.h +++ b/lib/ukfile/include/uk/file.h @@ -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) { diff --git a/lib/ukfile/include/uk/file/final.h b/lib/ukfile/include/uk/file/final.h index dda133d14..6905d7283 100644 --- a/lib/ukfile/include/uk/file/final.h +++ b/lib/ukfile/include/uk/file/final.h @@ -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) {