-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
threads_win: fix build error with VS2010 #24326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ struct rcu_lock_st { | |
CRYPTO_CONDVAR *alloc_signal; | ||
CRYPTO_MUTEX *prior_lock; | ||
CRYPTO_CONDVAR *prior_signal; | ||
CRYPTO_RWLOCK *rw_lock; | ||
}; | ||
|
||
static struct rcu_qp *allocate_new_qp_group(struct rcu_lock_st *lock, | ||
|
@@ -132,6 +133,7 @@ CRYPTO_RCU_LOCK *ossl_rcu_lock_new(int num_writers, OSSL_LIB_CTX *ctx) | |
return NULL; | ||
|
||
new->ctx = ctx; | ||
new->rw_lock = CRYPTO_THREAD_lock_new(); | ||
new->write_lock = ossl_crypto_mutex_new(); | ||
new->alloc_signal = ossl_crypto_condvar_new(); | ||
new->prior_signal = ossl_crypto_condvar_new(); | ||
|
@@ -143,7 +145,9 @@ CRYPTO_RCU_LOCK *ossl_rcu_lock_new(int num_writers, OSSL_LIB_CTX *ctx) | |
|| new->prior_signal == NULL | ||
|| new->write_lock == NULL | ||
|| new->alloc_lock == NULL | ||
|| new->prior_lock == NULL) { | ||
|| new->prior_lock == NULL | ||
|| new->rw_lock == NULL) { | ||
nhorman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CRYPTO_THREAD_lock_free(new->rw_lock); | ||
OPENSSL_free(new->qp_group); | ||
ossl_crypto_condvar_free(&new->alloc_signal); | ||
ossl_crypto_condvar_free(&new->prior_signal); | ||
|
@@ -159,6 +163,7 @@ CRYPTO_RCU_LOCK *ossl_rcu_lock_new(int num_writers, OSSL_LIB_CTX *ctx) | |
|
||
void ossl_rcu_lock_free(CRYPTO_RCU_LOCK *lock) | ||
{ | ||
CRYPTO_THREAD_lock_free(lock->rw_lock); | ||
OPENSSL_free(lock->qp_group); | ||
ossl_crypto_condvar_free(&lock->alloc_signal); | ||
ossl_crypto_condvar_free(&lock->prior_signal); | ||
|
@@ -168,17 +173,23 @@ void ossl_rcu_lock_free(CRYPTO_RCU_LOCK *lock) | |
OPENSSL_free(lock); | ||
} | ||
|
||
static inline struct rcu_qp *get_hold_current_qp(CRYPTO_RCU_LOCK *lock) | ||
static ossl_inline struct rcu_qp *get_hold_current_qp(CRYPTO_RCU_LOCK *lock) | ||
{ | ||
uint32_t qp_idx; | ||
uint32_t tmp; | ||
uint64_t tmp64; | ||
|
||
/* get the current qp index */ | ||
for (;;) { | ||
qp_idx = InterlockedOr(&lock->reader_idx, 0); | ||
InterlockedAdd64(&lock->qp_group[qp_idx].users, VAL_READER); | ||
if (qp_idx == InterlockedOr(&lock->reader_idx, 0)) | ||
CRYPTO_atomic_load_int(&lock->reader_idx, (int *)&qp_idx, | ||
lock->rw_lock); | ||
CRYPTO_atomic_add64(&lock->qp_group[qp_idx].users, VAL_READER, &tmp64, | ||
lock->rw_lock); | ||
CRYPTO_atomic_load_int(&lock->reader_idx, (int *)&tmp, lock->rw_lock); | ||
if (qp_idx == tmp) | ||
break; | ||
InterlockedAdd64(&lock->qp_group[qp_idx].users, -VAL_READER); | ||
CRYPTO_atomic_add64(&lock->qp_group[qp_idx].users, -VAL_READER, &tmp64, | ||
lock->rw_lock); | ||
} | ||
|
||
return &lock->qp_group[qp_idx]; | ||
|
@@ -253,7 +264,9 @@ void ossl_rcu_read_unlock(CRYPTO_RCU_LOCK *lock) | |
if (data->thread_qps[i].lock == lock) { | ||
data->thread_qps[i].depth--; | ||
if (data->thread_qps[i].depth == 0) { | ||
ret = InterlockedAdd64(&data->thread_qps[i].qp->users, -VAL_READER); | ||
CRYPTO_atomic_add64(&data->thread_qps[i].qp->users, | ||
-VAL_READER, (uint64_t *)&ret, | ||
lock->rw_lock); | ||
OPENSSL_assert(ret >= 0); | ||
data->thread_qps[i].qp = NULL; | ||
data->thread_qps[i].lock = NULL; | ||
|
@@ -268,6 +281,7 @@ static struct rcu_qp *update_qp(CRYPTO_RCU_LOCK *lock) | |
uint64_t new_id; | ||
uint32_t current_idx; | ||
uint32_t tmp; | ||
uint64_t tmp64; | ||
|
||
ossl_crypto_mutex_lock(lock->alloc_lock); | ||
/* | ||
|
@@ -291,8 +305,10 @@ static struct rcu_qp *update_qp(CRYPTO_RCU_LOCK *lock) | |
lock->id_ctr++; | ||
|
||
new_id = VAL_ID(new_id); | ||
InterlockedAnd64(&lock->qp_group[current_idx].users, ID_MASK); | ||
InterlockedAdd64(&lock->qp_group[current_idx].users, new_id); | ||
CRYPTO_atomic_and(&lock->qp_group[current_idx].users, ID_MASK, &tmp64, | ||
lock->rw_lock); | ||
CRYPTO_atomic_add64(&lock->qp_group[current_idx].users, new_id, &tmp64, | ||
lock->rw_lock); | ||
|
||
/* update the reader index to be the prior qp */ | ||
tmp = lock->current_alloc_idx; | ||
|
@@ -327,7 +343,7 @@ void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock) | |
|
||
/* wait for the reader count to reach zero */ | ||
do { | ||
count = InterlockedOr64(&qp->users, 0); | ||
CRYPTO_atomic_load(&qp->users, &count, lock->rw_lock); | ||
} while (READER_COUNT(count) != 0); | ||
|
||
/* retire in order */ | ||
|
@@ -558,6 +574,44 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock) | |
return 1; | ||
} | ||
|
||
int CRYPTO_atomic_add64(uint64_t *val, uint64_t op, uint64_t *ret, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to run make update to get this in the exported ordinals list, its why CI is failing here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I was wondering what this error means. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite. The CI test for symbol presence is failing, need to look at why. also, if you're going to add new exported library symbols, the docs check is going to fail if you don't document them in the appropriate pod file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Building on Windows works only with
I also noticed that apart from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe I need to add them to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you do need to add the definitions to threads_pthread.c and threads_none.c, as only one of the three (win/pthreads/none) gets compiled for the build and you need a definition for the exported symbols As for why make update isn't working. I expect its got something to do with the version of nmake on vs2010. Its worked for me on VS2022 community edition. note VS2010 isn't an officially supported platform I'd focus on getting the implementations defined on other platforms first, then worry about being able to make the update script. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added definitions to |
||
CRYPTO_RWLOCK *lock) | ||
{ | ||
#if (defined(NO_INTERLOCKEDOR64)) | ||
if (lock == NULL || !CRYPTO_THREAD_write_lock(lock)) | ||
return 0; | ||
*val += op; | ||
*ret = *val; | ||
|
||
if (!CRYPTO_THREAD_unlock(lock)) | ||
return 0; | ||
|
||
return 1; | ||
#else | ||
*ret = (uint64_t)InterlockedAdd64((LONG64 volatile *)val, (LONG64)op); | ||
return 1; | ||
#endif | ||
} | ||
|
||
int CRYPTO_atomic_and(uint64_t *val, uint64_t op, uint64_t *ret, | ||
CRYPTO_RWLOCK *lock) | ||
{ | ||
#if (defined(NO_INTERLOCKEDOR64)) | ||
if (lock == NULL || !CRYPTO_THREAD_write_lock(lock)) | ||
return 0; | ||
*val &= op; | ||
*ret = *val; | ||
|
||
if (!CRYPTO_THREAD_unlock(lock)) | ||
return 0; | ||
|
||
return 1; | ||
#else | ||
*ret = (uint64_t)InterlockedAnd64((LONG64 volatile *)val, (LONG64)op) & op; | ||
return 1; | ||
#endif | ||
} | ||
|
||
int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret, | ||
CRYPTO_RWLOCK *lock) | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.