diff options
author | Neil Horman <nhorman@openssl.org> | 2024-01-12 10:39:56 -0500 |
---|---|---|
committer | Neil Horman <nhorman@openssl.org> | 2024-02-01 08:33:25 -0500 |
commit | d0e1a0ae701cfaca7f3dd3bf28a3f934a6408813 (patch) | |
tree | ffb54122cc592cf0a3ac3b6eb69e00dbf1e9f8a5 /include | |
parent | de18dc3a635c3a82c365b3f2beeb491c78b01b11 (diff) |
RCU lock implementation
Introduce an RCU lock implementation as an alternative locking mechanism
to openssl. The api is documented in the ossl_rcu.pod
file
Read side implementaiton is comparable to that of RWLOCKS:
ossl_rcu_read_lock(lock);
<
critical section in which data can be accessed via
ossl_derefrence
>
ossl_rcu_read_unlock(lock);
Write side implementation is:
ossl_rcu_write_lock(lock);
<
critical section in which data can be updated via
ossl_assign_pointer
and stale data can optionally be scheduled for removal
via ossl_rcu_call
>
ossl_rcu_write_unlock(lock);
...
ossl_synchronize_rcu(lock);
ossl_rcu_call fixup
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22729)
Diffstat (limited to 'include')
-rw-r--r-- | include/internal/rcu.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/internal/rcu.h b/include/internal/rcu.h new file mode 100644 index 0000000000..31a270222d --- /dev/null +++ b/include/internal/rcu.h @@ -0,0 +1,31 @@ +/* + * Copyright 2023 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#ifndef OPENSSL_RCU_H +# define OPENSSL_RCU_H +# pragma once + +typedef void (*rcu_cb_fn)(void *data); + +typedef struct rcu_lock_st CRYPTO_RCU_LOCK; + +CRYPTO_RCU_LOCK *ossl_rcu_lock_new(int num_writers); +void ossl_rcu_lock_free(CRYPTO_RCU_LOCK *lock); +void ossl_rcu_read_lock(CRYPTO_RCU_LOCK *lock); +void ossl_rcu_write_lock(CRYPTO_RCU_LOCK *lock); +void ossl_rcu_write_unlock(CRYPTO_RCU_LOCK *lock); +void ossl_rcu_read_unlock(CRYPTO_RCU_LOCK *lock); +void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock); +int ossl_rcu_call(CRYPTO_RCU_LOCK *lock, rcu_cb_fn cb, void *data); +void *ossl_rcu_uptr_deref(void **p); +void ossl_rcu_assign_uptr(void **p, void **v); +#define ossl_rcu_deref(p) ossl_rcu_uptr_deref((void **)p) +#define ossl_rcu_assign_ptr(p,v) ossl_rcu_assign_uptr((void **)p, (void **)v) + +#endif |