Skip to content

Commit 3d59d60

Browse files
committed
ext/opcache/ZendAccelerator: move duplicate code to zend_accel_discard_script()
1 parent 46104bc commit 3d59d60

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,39 @@ zend_string *accel_make_persistent_key(zend_string *str)
13421342
return str;
13431343
}
13441344

1345+
/**
1346+
* Discard a #zend_persistent_script currently stored in shared
1347+
* memory.
1348+
*
1349+
* Caller must lock shared memory via zend_shared_alloc_lock().
1350+
*/
1351+
static void zend_accel_discard_script(zend_persistent_script *persistent_script)
1352+
{
1353+
if (persistent_script->corrupted)
1354+
/* already discarded */
1355+
return;
1356+
1357+
persistent_script->corrupted = true;
1358+
persistent_script->timestamp = 0;
1359+
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
1360+
if (ZSMMG(memory_exhausted)) {
1361+
zend_accel_restart_reason reason =
1362+
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
1363+
zend_accel_schedule_restart_if_necessary(reason);
1364+
}
1365+
}
1366+
1367+
/**
1368+
* Wrapper for zend_accel_discard_script() which locks shared memory
1369+
* via zend_shared_alloc_lock().
1370+
*/
1371+
static void zend_accel_lock_discard_script(zend_persistent_script *persistent_script)
1372+
{
1373+
zend_shared_alloc_lock();
1374+
zend_accel_discard_script(persistent_script);
1375+
zend_shared_alloc_unlock();
1376+
}
1377+
13451378
int zend_accel_invalidate(zend_string *filename, bool force)
13461379
{
13471380
zend_string *realpath;
@@ -1372,18 +1405,7 @@ int zend_accel_invalidate(zend_string *filename, bool force)
13721405
do_validate_timestamps(persistent_script, &file_handle) == FAILURE) {
13731406
HANDLE_BLOCK_INTERRUPTIONS();
13741407
SHM_UNPROTECT();
1375-
zend_shared_alloc_lock();
1376-
if (!persistent_script->corrupted) {
1377-
persistent_script->corrupted = true;
1378-
persistent_script->timestamp = 0;
1379-
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
1380-
if (ZSMMG(memory_exhausted)) {
1381-
zend_accel_restart_reason reason =
1382-
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
1383-
zend_accel_schedule_restart_if_necessary(reason);
1384-
}
1385-
}
1386-
zend_shared_alloc_unlock();
1408+
zend_accel_lock_discard_script(persistent_script);
13871409
SHM_PROTECT();
13881410
HANDLE_UNBLOCK_INTERRUPTIONS();
13891411
}
@@ -2078,18 +2100,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
20782100
/* If script is found then validate_timestamps if option is enabled */
20792101
if (persistent_script && ZCG(accel_directives).validate_timestamps) {
20802102
if (validate_timestamp_and_record(persistent_script, file_handle) == FAILURE) {
2081-
zend_shared_alloc_lock();
2082-
if (!persistent_script->corrupted) {
2083-
persistent_script->corrupted = true;
2084-
persistent_script->timestamp = 0;
2085-
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
2086-
if (ZSMMG(memory_exhausted)) {
2087-
zend_accel_restart_reason reason =
2088-
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
2089-
zend_accel_schedule_restart_if_necessary(reason);
2090-
}
2091-
}
2092-
zend_shared_alloc_unlock();
2103+
zend_accel_lock_discard_script(persistent_script);
20932104
persistent_script = NULL;
20942105
}
20952106
}
@@ -2103,18 +2114,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21032114
/* The checksum is wrong */
21042115
zend_accel_error(ACCEL_LOG_INFO, "Checksum failed for '%s': expected=0x%08x, found=0x%08x",
21052116
ZSTR_VAL(persistent_script->script.filename), persistent_script->dynamic_members.checksum, checksum);
2106-
zend_shared_alloc_lock();
2107-
if (!persistent_script->corrupted) {
2108-
persistent_script->corrupted = true;
2109-
persistent_script->timestamp = 0;
2110-
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
2111-
if (ZSMMG(memory_exhausted)) {
2112-
zend_accel_restart_reason reason =
2113-
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
2114-
zend_accel_schedule_restart_if_necessary(reason);
2115-
}
2116-
}
2117-
zend_shared_alloc_unlock();
2117+
zend_accel_lock_discard_script(persistent_script);
21182118
persistent_script = NULL;
21192119
}
21202120
}

0 commit comments

Comments
 (0)