Why not check the return status of the lock and unlock calls?? On Feb 28, 2011, at 12:26 PM, Simone Caruso wrote:
> Hi all, > > I wrote a simple cache inside my module with apr_shm and apr_rmm, but I have > problems with apr mutex... > > I have this peace of code: > > static apr_global_mutex_t *mtx = NULL; > static void module_translate_name(request_rec *r) > { > if(apr_global_mutex_trylock(mtx) == APR_EBUSY) > ap_log_rerror(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, 0, r, > "Memory Locked!! "); > apr_global_mutex_lock(mtx); > element = get_from_cache(); > if(element == NULL){ > element = insert_into_cache(); > strcpy(element.name,"name\0"); > } > apr_global_mutex_unlock(mtx); > } > > static void module_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t > *ptemp, server_rec *s) > { > result = apr_global_mutex_create(&mtx, "cache_entries_lck", > APR_LOCK_DEFAULT, p); > } > > > static void mod_vhost_ldap_child_init(apr_pool_t * p, server_rec * s) > { > apr_status_t ret; > ret = apr_global_mutex_child_init(&mtx, "cache_entries_lck", p); > } > > > > During my tests with 'ab -c 15 -n 3000' i NEVER get the "Memory Locked" error > in logs, plus i get duplicated entries in cache but I don't know why! > > Does someone have an idea? (please consider i use apr_global_mutex_trylock() > only for test) > Regards. > > -- > Simone Caruso >