Skip to content

Commit

Permalink
Remove the cache busy flag
Browse files Browse the repository at this point in the history
This is no longer used. We always acquire a full write lock for
cleanup operations.
  • Loading branch information
nikic committed Oct 21, 2018
1 parent 2adfa78 commit c068724
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 50 deletions.
42 changes: 8 additions & 34 deletions apc_cache.c
Expand Up @@ -302,7 +302,7 @@ PHP_APCU_API apc_cache_t* apc_cache_create(apc_sma_t* sma, apc_serializer_t* ser
cache->header->nexpunges = 0;
cache->header->gc = NULL;
cache->header->stime = time(NULL);
cache->header->state |= APC_CACHE_ST_NONE;
cache->header->state = 0;

/* set cache options */
cache->slots = (apc_cache_entry_t **) (((char*) cache->shmaddr) + sizeof(apc_cache_header_t));
Expand Down Expand Up @@ -695,8 +695,7 @@ static void apc_cache_wlocked_real_expunge(apc_cache_t* cache) {
/* {{{ apc_cache_clear */
PHP_APCU_API void apc_cache_clear(apc_cache_t* cache)
{
/* check there is a cache and it is not busy */
if (!cache || apc_cache_busy(cache)) {
if (!cache) {
return;
}

Expand All @@ -705,19 +704,13 @@ PHP_APCU_API void apc_cache_clear(apc_cache_t* cache)
return;
}

/* set busy */
cache->header->state |= APC_CACHE_ST_BUSY;

/* expunge cache */
apc_cache_wlocked_real_expunge(cache);

/* set info */
cache->header->stime = apc_time();
cache->header->nexpunges = 0;

/* unset busy */
cache->header->state &= ~APC_CACHE_ST_BUSY;

/* unlock header */
APC_WUNLOCK(cache->header);
}
Expand All @@ -730,9 +723,7 @@ PHP_APCU_API void apc_cache_default_expunge(apc_cache_t* cache, size_t size)
size_t suitable = 0L;
size_t available = 0L;


/* check there is a cache, and it is not busy */
if(!cache || apc_cache_busy(cache)) {
if(!cache) {
return;
}

Expand All @@ -741,9 +732,6 @@ PHP_APCU_API void apc_cache_default_expunge(apc_cache_t* cache, size_t size)
return;
}

/* update state in header */
cache->header->state |= APC_CACHE_ST_BUSY;

/* make suitable selection */
suitable = (cache->smart > 0L) ? (size_t) (cache->smart * size) : (size_t) (cache->sma->size/2);

Expand Down Expand Up @@ -789,9 +777,6 @@ PHP_APCU_API void apc_cache_default_expunge(apc_cache_t* cache, size_t size)
}
}

/* we are done */
cache->header->state &= ~APC_CACHE_ST_BUSY;

/* unlock header */
APC_WUNLOCK(cache->header);
}
Expand All @@ -802,8 +787,7 @@ PHP_APCU_API apc_cache_entry_t* apc_cache_find(apc_cache_t* cache, zend_string *
{
apc_cache_entry_t *entry;

/* check we are able to deal with the request */
if (!cache || apc_cache_busy(cache)) {
if (!cache) {
return NULL;
}

Expand All @@ -821,8 +805,7 @@ PHP_APCU_API zend_bool apc_cache_fetch(apc_cache_t* cache, zend_string *key, tim
apc_cache_entry_t *entry;
zend_bool retval = 0;

/* check we are able to deal with the request */
if (!cache || apc_cache_busy(cache)) {
if (!cache) {
return 0;
}

Expand All @@ -848,8 +831,7 @@ PHP_APCU_API zend_bool apc_cache_exists(apc_cache_t* cache, zend_string *key, ti
{
apc_cache_entry_t *entry;

if (apc_cache_busy(cache)) {
/* cache cleanup in progress */
if (!cache) {
return 0;
}

Expand All @@ -872,8 +854,7 @@ PHP_APCU_API zend_bool apc_cache_update(
zend_ulong h, s;
time_t t = apc_time();

if (apc_cache_busy(cache)) {
/* cannot service request right now */
if (!cache) {
return 0;
}

Expand Down Expand Up @@ -1144,13 +1125,6 @@ PHP_APCU_API zval *apc_cache_stat(apc_cache_t *cache, zend_string *key, zval *st
return stat;
}

/* {{{ apc_cache_busy */
PHP_APCU_API zend_bool apc_cache_busy(apc_cache_t* cache)
{
return (cache->header->state & APC_CACHE_ST_BUSY);
}
/* }}} */

/* {{{ apc_cache_defense */
PHP_APCU_API zend_bool apc_cache_defense(apc_cache_t *cache, zend_string *key, time_t t)
{
Expand Down Expand Up @@ -1205,7 +1179,7 @@ PHP_APCU_API void apc_cache_serializer(apc_cache_t* cache, const char* name) {
PHP_APCU_API void apc_cache_entry(apc_cache_t *cache, zval *key, zend_fcall_info *fci, zend_fcall_info_cache *fcc, zend_long ttl, zend_long now, zval *return_value) {/*{{{*/
apc_cache_entry_t *entry = NULL;

if(!cache || apc_cache_busy(cache)) {
if (!cache) {
return;
}

Expand Down
16 changes: 0 additions & 16 deletions apc_cache_api.h
Expand Up @@ -61,10 +61,6 @@ struct apc_cache_entry_t {
};
/* }}} */

/* {{{ state constants */
#define APC_CACHE_ST_NONE 0
#define APC_CACHE_ST_BUSY 0x00000001 /* }}} */

/* {{{ struct definition: apc_cache_header_t
Any values that must be shared among processes should go in here. */
typedef struct _apc_cache_header_t {
Expand Down Expand Up @@ -207,18 +203,6 @@ PHP_APCU_API zend_bool apc_cache_info(zval *info, apc_cache_t *cache, zend_bool
*/
PHP_APCU_API zval* apc_cache_stat(apc_cache_t* cache, zend_string *key, zval *stat);

/*
* apc_cache_busy returns true while the cache is busy
*
* a cache is considered busy when any of the following occur:
* a) the cache becomes busy when the allocator beneath it is running out of resources
* b) a clear of the cache was requested
* c) garbage collection is in progress
*
* Note: garbage collection can be invoked by the SMA and is invoked on insert
*/
PHP_APCU_API zend_bool apc_cache_busy(apc_cache_t* cache);

/*
* apc_cache_defense: guard against slamming a key
* will return true if the following conditions are met:
Expand Down

0 comments on commit c068724

Please sign in to comment.