a few things to try: * you should use APR_STATUS_IS_EBUSY(s) instead of ... == APR_EBUSY * after creating the mutex, you might have to set permissions on it: #ifdef AP_NEED_SET_MUTEX_PERMS rc = unixd_set_global_mutex_perms(mutex); if(rc != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s, "Could not set permissions on global parent mutex %s", mutex_name); return rc; } #endif
* I *think* that calling the lock functions twice from a same thread (without unlocking first) can have undefined behavior, i.e. don't do the lock() just after the trylock() call. regards, thomas On Mon, Feb 28, 2011 at 18:26, Simone Caruso <i...@simonecaruso.com> 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 >