Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ext/opcache/zend_accelerator_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, zend_
if (entry->hash_value == hash_value
&& zend_string_equals(entry->key, key)) {

/* Lookups are lock-free: order the initialization of whatever the new
* data points to before the pointer update (writer side only; readers
* rely on the address dependency when following data). */
ZEND_ATOMIC_FENCE_RELEASE();
if (entry->indirect) {
if (indirect_bucket) {
entry->data = indirect_bucket;
Expand Down Expand Up @@ -134,6 +138,10 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, zend_
entry->hash_value = hash_value;
entry->key = key;
entry->next = accel_hash->hash_table[index];
/* Lookups are lock-free: the entry must be fully initialized before it
* becomes reachable from the bucket, otherwise a concurrent reader can see
* a matching hash_value with a NULL key (weakly ordered CPUs, e.g. aarch64). */
ZEND_ATOMIC_FENCE_RELEASE();
accel_hash->hash_table[index] = entry;
return entry;
}
Expand All @@ -151,6 +159,11 @@ static zend_always_inline void* zend_accel_hash_find_ex(zend_accel_hash *accel_h
index = hash_value % accel_hash->max_num_entries;

entry = accel_hash->hash_table[index];
if (entry) {
/* Order the bucket read before the entry field reads; pairs with the
* release fence before the bucket store in zend_accel_hash_update(). */
ZEND_ATOMIC_FENCE_ACQUIRE();
}
while (entry) {
if (entry->hash_value == hash_value
&& zend_string_equals(entry->key, key)) {
Expand Down
7 changes: 6 additions & 1 deletion ext/opcache/zend_accelerator_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,12 @@ static int accelerator_get_scripts(zval *return_value)

array_init(return_value);
for (i = 0; i<ZCSG(hash).max_num_entries; i++) {
for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
cache_entry = ZCSG(hash).hash_table[i];
if (cache_entry) {
/* Lock-free reader, see zend_accel_hash_find_ex(). */
ZEND_ATOMIC_FENCE_ACQUIRE();
}
for (; cache_entry; cache_entry = cache_entry->next) {
zend_persistent_script *script;
char *str;
size_t len;
Expand Down
Loading