@@ -1342,6 +1342,40 @@ zend_string *accel_make_persistent_key(zend_string *str)
1342
1342
return str ;
1343
1343
}
1344
1344
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
+
1358
+ persistent_script -> corrupted = true;
1359
+ persistent_script -> timestamp = 0 ;
1360
+ ZSMMG (wasted_shared_memory ) += persistent_script -> dynamic_members .memory_consumption ;
1361
+ if (ZSMMG (memory_exhausted )) {
1362
+ zend_accel_restart_reason reason =
1363
+ zend_accel_hash_is_full (& ZCSG (hash )) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM ;
1364
+ zend_accel_schedule_restart_if_necessary (reason );
1365
+ }
1366
+ }
1367
+
1368
+ /**
1369
+ * Wrapper for zend_accel_discard_script() which locks shared memory
1370
+ * via zend_shared_alloc_lock().
1371
+ */
1372
+ static void zend_accel_lock_discard_script (zend_persistent_script * persistent_script )
1373
+ {
1374
+ zend_shared_alloc_lock ();
1375
+ zend_accel_discard_script (persistent_script );
1376
+ zend_shared_alloc_unlock ();
1377
+ }
1378
+
1345
1379
int zend_accel_invalidate (zend_string * filename , bool force )
1346
1380
{
1347
1381
zend_string * realpath ;
@@ -1372,18 +1406,7 @@ int zend_accel_invalidate(zend_string *filename, bool force)
1372
1406
do_validate_timestamps (persistent_script , & file_handle ) == FAILURE ) {
1373
1407
HANDLE_BLOCK_INTERRUPTIONS ();
1374
1408
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 ();
1409
+ zend_accel_lock_discard_script (persistent_script );
1387
1410
SHM_PROTECT ();
1388
1411
HANDLE_UNBLOCK_INTERRUPTIONS ();
1389
1412
}
@@ -2078,18 +2101,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2078
2101
/* If script is found then validate_timestamps if option is enabled */
2079
2102
if (persistent_script && ZCG (accel_directives ).validate_timestamps ) {
2080
2103
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 ();
2104
+ zend_accel_lock_discard_script (persistent_script );
2093
2105
persistent_script = NULL ;
2094
2106
}
2095
2107
}
@@ -2103,18 +2115,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2103
2115
/* The checksum is wrong */
2104
2116
zend_accel_error (ACCEL_LOG_INFO , "Checksum failed for '%s': expected=0x%08x, found=0x%08x" ,
2105
2117
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 ();
2118
+ zend_accel_lock_discard_script (persistent_script );
2118
2119
persistent_script = NULL ;
2119
2120
}
2120
2121
}
0 commit comments