TS-3156: remove MutexLock bool operators - Mutex[Try]Lock Structs loose lose APIs and bool() operator - change structs to classes - is_locked() API replaces bool() operator - remove unnecessary ink_scoped_mutex and ink_scoped_try_mutex
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/53e56ffc Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/53e56ffc Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/53e56ffc Branch: refs/heads/master Commit: 53e56ffc7499648bc096d63f9c0f9da0ea9212ba Parents: ffe2484 Author: Powell Molleti <[email protected]> Authored: Tue Oct 28 17:56:10 2014 -0700 Committer: James Peach <[email protected]> Committed: Fri Oct 31 15:03:53 2014 -0700 ---------------------------------------------------------------------- CHANGES | 3 + iocore/cache/Cache.cc | 6 +- iocore/cache/CacheDir.cc | 6 +- iocore/cache/CacheLink.cc | 6 +- iocore/cache/CachePagesInternal.cc | 6 +- iocore/cache/CacheRead.cc | 24 +-- iocore/cache/CacheVol.cc | 6 +- iocore/cache/CacheWrite.cc | 18 +- iocore/cache/P_CacheInternal.h | 18 +- iocore/cluster/ClusterAPI.cc | 8 +- iocore/cluster/ClusterCache.cc | 24 +-- iocore/cluster/ClusterConfig.cc | 2 +- iocore/cluster/ClusterHandler.cc | 4 +- iocore/cluster/ClusterHandlerBase.cc | 14 +- iocore/cluster/ClusterProcessor.cc | 6 +- iocore/cluster/ClusterVConnection.cc | 2 +- iocore/dns/DNS.cc | 6 +- iocore/eventsystem/I_Lock.h | 314 ++++++++++++++---------------- iocore/eventsystem/UnixEThread.cc | 2 +- iocore/hostdb/HostDB.cc | 49 +++-- iocore/net/SSLNetVConnection.cc | 8 +- iocore/net/SSLSessionCache.cc | 22 ++- iocore/net/SSLSessionCache.h | 4 +- iocore/net/Socks.cc | 2 +- iocore/net/UnixNet.cc | 2 +- iocore/net/UnixNetAccept.cc | 2 +- iocore/net/UnixNetPages.cc | 4 +- iocore/net/UnixNetProcessor.cc | 4 +- iocore/net/UnixNetVConnection.cc | 20 +- iocore/net/UnixUDPNet.cc | 2 +- lib/ts/ink_mutex.h | 44 ----- proxy/FetchSM.cc | 4 +- proxy/ICP.cc | 2 +- proxy/InkAPI.cc | 6 +- proxy/InkAPIInternal.h | 2 +- proxy/PluginVC.cc | 16 +- proxy/Prefetch.cc | 6 +- proxy/RegressionSM.cc | 2 +- proxy/Transform.cc | 10 +- proxy/Update.cc | 12 +- proxy/api/ts/InkAPIPrivateIOCore.h | 22 +-- proxy/congest/Congestion.cc | 2 +- proxy/congest/CongestionDB.cc | 18 +- proxy/http/HttpClientSession.cc | 2 +- proxy/http/HttpPages.cc | 10 +- proxy/http/HttpProxyServerMain.cc | 10 +- proxy/http/HttpSM.cc | 4 +- proxy/http/HttpSessionManager.cc | 6 +- proxy/http/HttpUpdateSM.cc | 2 +- 49 files changed, 356 insertions(+), 418 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index b67a4e9..ee19946 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.2.0 + *) [TS-3156] Remove MutexLock bool operators. + Author: Powell Molleti <[email protected]> + *) [TS-2682] Add per remap support for background fetch plugin *) [TS-2683]: Enhance the bg fetch plugin to support specifyng various http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/Cache.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc index 27a1926..3b1eebd 100644 --- a/iocore/cache/Cache.cc +++ b/iocore/cache/Cache.cc @@ -2474,7 +2474,7 @@ CacheVC::handleReadDone(int event, Event *e) return EVENT_CONT; { MUTEX_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); if ((!dir_valid(vol, &dir)) || (!io.ok())) { if (!io.ok()) { @@ -2823,7 +2823,7 @@ CacheVC::removeEvent(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) set_io_not_in_progress(); { MUTEX_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); if (_action.cancelled) { if (od) { @@ -2915,7 +2915,7 @@ Cache::remove(Continuation *cont, CacheKey *key, CacheFragType type, bool /* use cont = new_CacheRemoveCont(); CACHE_TRY_LOCK(lock, cont->mutex, this_ethread()); - ink_assert(lock); + ink_assert(lock.is_locked()); Vol *vol = key_to_vol(key, hostname, host_len); // coverity[var_decl] Dir result; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/CacheDir.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheDir.cc b/iocore/cache/CacheDir.cc index bd81325..c522ca0 100644 --- a/iocore/cache/CacheDir.cc +++ b/iocore/cache/CacheDir.cc @@ -109,7 +109,7 @@ OpenDir::signal_readers(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) CacheVC *c = NULL; while ((c = delayed_readers.dequeue())) { CACHE_TRY_LOCK(lock, c->mutex, t); - if (lock) { + if (lock.is_locked()) { c->f.open_read_timeout = 0; c->handleEvent(EVENT_IMMEDIATE, 0); continue; @@ -1140,7 +1140,7 @@ Lrestart: } { CACHE_TRY_LOCK(lock, gvol[vol]->mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { trigger = eventProcessor.schedule_in(this, HRTIME_MSECONDS(cache_config_mutex_retry_delay)); return EVENT_CONT; } @@ -1430,7 +1430,7 @@ EXCLUSIVE_REGRESSION_TEST(Cache_dir) (RegressionTest *t, int /* atype ATS_UNUSED Vol *d = gvol[0]; EThread *thread = this_ethread(); MUTEX_TRY_LOCK(lock, d->mutex, thread); - ink_release_assert(lock); + ink_release_assert(lock.is_locked()); rprintf(t, "clearing vol 0\n", free); vol_dir_clear(d); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/CacheLink.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheLink.cc b/iocore/cache/CacheLink.cc index 30f05b8..cbd03ad 100644 --- a/iocore/cache/CacheLink.cc +++ b/iocore/cache/CacheLink.cc @@ -88,7 +88,7 @@ Cache::deref(Continuation * cont, CacheKey * key, CacheFragType type, char *host CacheVC *c = NULL; { MUTEX_TRY_LOCK(lock, vol->mutex, cont->mutex->thread_holding); - if (lock) { + if (lock.is_locked()) { if (!dir_probe(key, vol, &result, &last_collision)) { cont->handleEvent(CACHE_EVENT_DEREF_FAILED, (void *) -ECACHE_NO_DOC); return ACTION_RESULT_DONE; @@ -101,7 +101,7 @@ Cache::deref(Continuation * cont, CacheKey * key, CacheFragType type, char *host c->dir = result; c->last_collision = last_collision; - if (!lock) { + if (!lock.is_locked()) { c->mutex->thread_holding->schedule_in_local(c, HRTIME_MSECONDS(cache_config_mutex_retry_delay)); return &c->_action; } @@ -147,7 +147,7 @@ CacheVC::derefRead(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) Lcollision:{ CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { mutex->thread_holding->schedule_in_local(this, HRTIME_MSECONDS(cache_config_mutex_retry_delay)); return EVENT_CONT; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/CachePagesInternal.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CachePagesInternal.cc b/iocore/cache/CachePagesInternal.cc index 3fd8e9a..0d7b191 100644 --- a/iocore/cache/CachePagesInternal.cc +++ b/iocore/cache/CachePagesInternal.cc @@ -209,7 +209,7 @@ ShowCacheInternal::showVolEvacuations(int event, Event * e) { Vol *p = gvol[vol_index]; CACHE_TRY_LOCK(lock, p->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) CONT_SCHED_LOCK_RETRY_RET(this); EvacuationBlock *b; @@ -260,7 +260,7 @@ ShowCacheInternal::showVolVolumes(int event, Event * e) { Vol *p = gvol[vol_index]; CACHE_TRY_LOCK(lock, p->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) CONT_SCHED_LOCK_RETRY_RET(this); char ctime[256]; @@ -314,7 +314,7 @@ ShowCacheInternal::showSegSegment(int event, Event * e) { Vol *p = gvol[vol_index]; CACHE_TRY_LOCK(lock, p->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) CONT_SCHED_LOCK_RETRY_RET(this); int free = 0, used = 0, empty = 0, valid = 0, agg_valid = 0, avg_size = 0; dir_segment_accounted(seg_index, p, 0, &free, &used, &empty, &valid, &agg_valid, &avg_size); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/CacheRead.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc index fa20f83..d6fe0f8 100644 --- a/iocore/cache/CacheRead.cc +++ b/iocore/cache/CacheRead.cc @@ -46,7 +46,7 @@ Cache::open_read(Continuation * cont, CacheKey * key, CacheFragType type, char * CacheVC *c = NULL; { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock || (od = vol->open_read(key)) || dir_probe(key, vol, &result, &last_collision)) { + if (!lock.is_locked() || (od = vol->open_read(key)) || dir_probe(key, vol, &result, &last_collision)) { c = new_CacheVC(cont); SET_CONTINUATION_HANDLER(c, &CacheVC::openReadStartHead); c->vio.op = VIO::READ; @@ -59,7 +59,7 @@ Cache::open_read(Continuation * cont, CacheKey * key, CacheFragType type, char * } if (!c) goto Lmiss; - if (!lock) { + if (!lock.is_locked()) { CONT_SCHED_LOCK_RETRY(c); return &c->_action; } @@ -108,7 +108,7 @@ Cache::open_read(Continuation * cont, CacheKey * key, CacheHTTPHdr * request, { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock || (od = vol->open_read(key)) || dir_probe(key, vol, &result, &last_collision)) { + if (!lock.is_locked() || (od = vol->open_read(key)) || dir_probe(key, vol, &result, &last_collision)) { c = new_CacheVC(cont); c->first_key = c->key = c->earliest_key = *key; c->vol = vol; @@ -120,7 +120,7 @@ Cache::open_read(Continuation * cont, CacheKey * key, CacheHTTPHdr * request, c->params = params; c->od = od; } - if (!lock) { + if (!lock.is_locked()) { SET_CONTINUATION_HANDLER(c, &CacheVC::openReadStartHead); CONT_SCHED_LOCK_RETRY(c); return &c->_action; @@ -312,7 +312,7 @@ CacheVC::openReadFromWriter(int event, Event * e) return free_CacheVC(this); } CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); od = vol->open_read(&first_key); // recheck in case the lock failed if (!od) { @@ -374,7 +374,7 @@ CacheVC::openReadFromWriter(int event, Event * e) } CACHE_TRY_LOCK(writer_lock, write_vc->mutex, mutex->thread_holding); - if (!writer_lock) { + if (!writer_lock.is_locked()) { DDebug("cache_read_agg", "%p: key: %X lock miss", this, first_key.slice32(1)); VC_SCHED_LOCK_RETRY(); } @@ -522,7 +522,7 @@ CacheVC::openReadClose(int event, Event * /* e ATS_UNUSED */) set_io_not_in_progress(); } CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); if (f.hit_evacuate && dir_valid(vol, &first_dir) && closed > 0) { if (f.single_fragment) @@ -547,7 +547,7 @@ CacheVC::openReadReadDone(int event, Event * e) set_io_not_in_progress(); { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); if (event == AIO_EVENT_DONE && !io.ok()) { dir_delete(&earliest_key, vol, &earliest_dir); @@ -752,7 +752,7 @@ Lread: { // a new EVENT_INTERVAL event. cancel_trigger(); CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { SET_HANDLER(&CacheVC::openReadMain); VC_SCHED_LOCK_RETRY(); } @@ -810,7 +810,7 @@ CacheVC::openReadStartEarliest(int /* event ATS_UNUSED */, Event * /* e ATS_UNUS return free_CacheVC(this); { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); if (!buf) goto Lread; @@ -968,7 +968,7 @@ CacheVC::openReadVecWrite(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */ return openWriteCloseDir(EVENT_IMMEDIATE, 0); { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); if (io.ok()) { ink_assert(f.evac_vector); @@ -1020,7 +1020,7 @@ CacheVC::openReadStartHead(int event, Event * e) return free_CacheVC(this); { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_SCHED_LOCK_RETRY(); if (!buf) goto Lread; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/CacheVol.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheVol.cc b/iocore/cache/CacheVol.cc index ccb6964..51e4306 100644 --- a/iocore/cache/CacheVol.cc +++ b/iocore/cache/CacheVol.cc @@ -168,7 +168,7 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) return free_CacheVC(this); CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { Debug("cache_scan_truss", "delay %p:scanObject", this); mutex->thread_holding->schedule_in_local(this, HRTIME_MSECONDS(cache_config_mutex_retry_delay)); return EVENT_CONT; @@ -404,7 +404,7 @@ CacheVC::scanOpenWrite(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) int ret = 0; { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { Debug("cache_scan", "vol->mutex %p:scanOpenWrite", this); VC_SCHED_LOCK_RETRY(); } @@ -477,7 +477,7 @@ CacheVC::scanUpdateDone(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) cancel_trigger(); // get volume lock CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (lock) { + if (lock.is_locked()) { // insert a directory entry for the previous fragment dir_overwrite(&first_key, vol, &dir, &od->first_dir, false); if (od->move_resident_alt) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/CacheWrite.cc ---------------------------------------------------------------------- diff --git a/iocore/cache/CacheWrite.cc b/iocore/cache/CacheWrite.cc index 4050c88..9000416 100644 --- a/iocore/cache/CacheWrite.cc +++ b/iocore/cache/CacheWrite.cc @@ -64,7 +64,7 @@ CacheVC::updateVector(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */) int ret = 0; { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock || od->writing_vec) + if (!lock.is_locked() || od->writing_vec) VC_SCHED_LOCK_RETRY(); int vec = alternate.valid(); @@ -310,7 +310,7 @@ Vol::aggWriteDone(int event, Event *e) // ensure we have the cacheDirSync lock if we intend to call it later // retaking the current mutex recursively is a NOOP CACHE_TRY_LOCK(lock, dir_sync_waiting ? cacheDirSync->mutex : mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { eventProcessor.schedule_in(this, HRTIME_MSECONDS(cache_config_mutex_retry_delay)); return EVENT_CONT; } @@ -1085,7 +1085,7 @@ CacheVC::openWriteCloseDir(int /* event ATS_UNUSED */, Event */* e ATS_UNUSED */ cancel_trigger(); { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { SET_HANDLER(&CacheVC::openWriteCloseDir); ink_assert(!is_io_in_progress()); VC_SCHED_LOCK_RETRY(); @@ -1144,7 +1144,7 @@ CacheVC::openWriteCloseHeadDone(int event, Event *e) return EVENT_CONT; { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_LOCK_RETRY_EVENT(); od->writing_vec = 0; if (!io.ok()) @@ -1220,7 +1220,7 @@ CacheVC::openWriteCloseDataDone(int event, Event *e) return openWriteCloseDir(event, e); { CACHE_TRY_LOCK(lock, vol->mutex, this_ethread()); - if (!lock) + if (!lock.is_locked()) VC_LOCK_RETRY_EVENT(); if (!fragment) { ink_assert(key == earliest_key); @@ -1315,7 +1315,7 @@ CacheVC::openWriteWriteDone(int event, Event *e) } { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_LOCK_RETRY_EVENT(); // store the earliest directory. Need to remove the earliest dir // in case the writer aborts. @@ -1441,7 +1441,7 @@ CacheVC::openWriteOverwrite(int event, Event *e) Lcollision: { CACHE_TRY_LOCK(lock, vol->mutex, this_ethread()); - if (!lock) + if (!lock.is_locked()) VC_LOCK_RETRY_EVENT(); int res = dir_probe(&first_key, vol, &dir, &last_collision); if (res > 0) { @@ -1472,7 +1472,7 @@ CacheVC::openWriteStartDone(int event, Event *e) } { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) + if (!lock.is_locked()) VC_LOCK_RETRY_EVENT(); if (_action.cancelled && (!od || !od->has_multiple_writers())) @@ -1758,7 +1758,7 @@ Cache::open_write(Continuation *cont, CacheKey *key, CacheHTTPInfo *info, time_t { CACHE_TRY_LOCK(lock, c->vol->mutex, cont->mutex->thread_holding); - if (lock) { + if (lock.is_locked()) { if ((err = c->vol->open_write(c, if_writers, cache_config_http_max_alts > 1 ? cache_config_http_max_alts : 0)) > 0) goto Lfailure; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cache/P_CacheInternal.h ---------------------------------------------------------------------- diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h index 4b840f0..ac15efe 100644 --- a/iocore/cache/P_CacheInternal.h +++ b/iocore/cache/P_CacheInternal.h @@ -757,7 +757,7 @@ CacheVC::handleWriteLock(int /* event ATS_UNUSED */, Event *e) int ret = 0; { CACHE_TRY_LOCK(lock, vol->mutex, mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { set_agg_write_in_progress(); trigger = mutex->thread_holding->schedule_in_local(this, HRTIME_MSECONDS(cache_config_mutex_retry_delay)); return EVENT_CONT; @@ -850,7 +850,7 @@ Vol::close_write_lock(CacheVC *cont) { EThread *t = cont->mutex->thread_holding; CACHE_TRY_LOCK(lock, mutex, t); - if (!lock) + if (!lock.is_locked()) return -1; return close_write(cont); } @@ -860,7 +860,7 @@ Vol::open_write_lock(CacheVC *cont, int allow_if_writers, int max_writers) { EThread *t = cont->mutex->thread_holding; CACHE_TRY_LOCK(lock, mutex, t); - if (!lock) + if (!lock.is_locked()) return -1; return open_write(cont, allow_if_writers, max_writers); } @@ -869,7 +869,7 @@ TS_INLINE OpenDirEntry * Vol::open_read_lock(INK_MD5 *key, EThread *t) { CACHE_TRY_LOCK(lock, mutex, t); - if (!lock) + if (!lock.is_locked()) return NULL; return open_dir.open_read(key); } @@ -885,7 +885,7 @@ Vol::begin_read_lock(CacheVC *cont) // VC is enqueued in stat_cache_vcs in the begin_read call EThread *t = cont->mutex->thread_holding; CACHE_TRY_LOCK(lock, mutex, t); - if (!lock) + if (!lock.is_locked()) return -1; return begin_read(cont); } @@ -895,7 +895,7 @@ Vol::close_read_lock(CacheVC *cont) { EThread *t = cont->mutex->thread_holding; CACHE_TRY_LOCK(lock, mutex, t); - if (!lock) + if (!lock.is_locked()) return -1; return close_read(cont); } @@ -905,7 +905,7 @@ dir_delete_lock(CacheKey *key, Vol *d, ProxyMutex *m, Dir *del) { EThread *thread = m->thread_holding; CACHE_TRY_LOCK(lock, d->mutex, thread); - if (!lock) + if (!lock.is_locked()) return -1; return dir_delete(key, d, del); } @@ -915,7 +915,7 @@ dir_insert_lock(CacheKey *key, Vol *d, Dir *to_part, ProxyMutex *m) { EThread *thread = m->thread_holding; CACHE_TRY_LOCK(lock, d->mutex, thread); - if (!lock) + if (!lock.is_locked()) return -1; return dir_insert(key, d, to_part); } @@ -925,7 +925,7 @@ dir_overwrite_lock(CacheKey *key, Vol *d, Dir *to_part, ProxyMutex *m, Dir *over { EThread *thread = m->thread_holding; CACHE_TRY_LOCK(lock, d->mutex, thread); - if (!lock) + if (!lock.is_locked()) return -1; return dir_overwrite(key, d, to_part, overwrite, must_overwrite); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cluster/ClusterAPI.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterAPI.cc b/iocore/cluster/ClusterAPI.cc index d2e07ab..3345713 100644 --- a/iocore/cluster/ClusterAPI.cc +++ b/iocore/cluster/ClusterAPI.cc @@ -131,7 +131,7 @@ MachineStatusSM::MachineStatusSMEvent(Event * /* e ATS_UNUSED */, void * /* d AT if (status_callouts[n].func && (status_callouts[n].state == NE_STATE_INITIALIZED)) { MUTEX_TRY_LOCK(lock, status_callouts[n].mutex, et); - if (lock) { + if (lock.is_locked()) { status_callouts[n].func(&_node_handle, _node_status); Debug("cluster_api", "callout: n %d ([%u.%u.%u.%u], %d)", n, DOT_SEPARATED(_node_handle), _node_status); } else { @@ -149,7 +149,7 @@ MachineStatusSM::MachineStatusSMEvent(Event * /* e ATS_UNUSED */, void * /* d AT n = CLUSTER_STATUS_HANDLE_TO_INDEX(_status_handle); if (status_callouts[n].func) { MUTEX_TRY_LOCK(lock, status_callouts[n].mutex, et); - if (lock) { + if (lock.is_locked()) { int mi; unsigned int my_ipaddr = (this_cluster_machine())->ip; ClusterConfiguration *cc; @@ -183,7 +183,7 @@ MachineStatusSM::MachineStatusSMEvent(Event * /* e ATS_UNUSED */, void * /* d AT n = CLUSTER_STATUS_HANDLE_TO_INDEX(_status_handle); if (status_callouts[n].func) { MUTEX_TRY_LOCK(lock, status_callouts[n].mutex, et); - if (lock) { + if (lock.is_locked()) { status_callouts[n].func(&_node_handle, _node_status); Debug("cluster_api", @@ -281,7 +281,7 @@ clusterAPI_init() "cluster API status_callout_q", (char *) &mssmp->link.next - (char *) mssmp); ClusterAPI_mutex = new_ProxyMutex(); MUTEX_TRY_LOCK(lock, ClusterAPI_mutex, this_ethread()); - ink_release_assert(lock); // Should never fail + ink_release_assert(lock.is_locked()); // Should never fail periodicSM = new ClusterAPIPeriodicSM(ClusterAPI_mutex); // TODO: Should we do something with this return value? http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cluster/ClusterCache.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterCache.cc b/iocore/cluster/ClusterCache.cc index 570168b..d6315d9 100644 --- a/iocore/cluster/ClusterCache.cc +++ b/iocore/cluster/ClusterCache.cc @@ -260,7 +260,7 @@ ClusterVConnectionCache::insert(INK_MD5 * key, ClusterVConnection * vc) ProxyMutex *mutex = thread->mutex; MUTEX_TRY_LOCK(lock, hash_lock[index], thread); - if (!lock) { + if (!lock.is_locked()) { CLUSTER_INCREMENT_DYN_STAT(CLUSTER_VC_CACHE_INSERT_LOCK_MISSES_STAT); return 0; // lock miss, retry later @@ -286,7 +286,7 @@ ClusterVConnectionCache::lookup(INK_MD5 * key) ProxyMutex *mutex = thread->mutex; MUTEX_TRY_LOCK(lock, hash_lock[index], thread); - if (!lock) { + if (!lock.is_locked()) { CLUSTER_INCREMENT_DYN_STAT(CLUSTER_VC_CACHE_LOOKUP_LOCK_MISSES_STAT); return vc; // lock miss, retry later @@ -314,7 +314,7 @@ ClusterVConnectionCacheEvent::eventHandler(int /* event ATS_UNUSED */, Event * e { CLUSTER_INCREMENT_DYN_STAT(CLUSTER_VC_CACHE_SCANS_STAT); MUTEX_TRY_LOCK(lock, cache->hash_lock[hash_index], this_ethread()); - if (!lock) { + if (!lock.is_locked()) { CLUSTER_INCREMENT_DYN_STAT(CLUSTER_VC_CACHE_SCAN_LOCK_MISSES_STAT); e->schedule_in(HRTIME_MSECONDS(10)); return EVENT_DONE; @@ -423,7 +423,7 @@ CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args, unsigned int hash = FOLDHASH(cc->target_ip, cc->seq_number); MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], this_ethread()); - if (!queuelock) { + if (!queuelock.is_locked()) { // failed to acquire lock: no problem, retry later cc->timeout = eventProcessor.schedule_in(cc, CACHE_RETRY_PERIOD, ET_CACHE_CONT_SM); @@ -797,7 +797,7 @@ CacheContinuation::remove_and_delete(int /* event ATS_UNUSED */, Event * e) { unsigned int hash = FOLDHASH(target_ip, seq_number); MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], this_ethread()); - if (queuelock) { + if (queuelock.is_locked()) { if (remoteCacheContQueue[hash].in(this)) { remoteCacheContQueue[hash].remove(this); } @@ -831,7 +831,7 @@ CacheContinuation::localVCsetupEvent(int event, ClusterVConnection * vc) unsigned int hash = FOLDHASH(target_ip, seq_number); MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], e->ethread); - if (!queuelock) { + if (!queuelock.is_locked()) { e->schedule_in(CACHE_RETRY_PERIOD); return EVENT_CONT; } @@ -1940,7 +1940,7 @@ CacheContinuation::handleDisposeEvent(int /* event ATS_UNUSED */, CacheContinuat { ink_assert(cc->magicno == (int) MagicNo); MUTEX_TRY_LOCK(lock, cc->tunnel_mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { // Write of initial object data is complete. if (!cc->tunnel_closed) { @@ -2071,7 +2071,7 @@ cache_op_result_ClusterFunction(ClusterHandler *ch, void *d, int l) // Failed to acquire lock, defer - if (!lock) { + if (!lock.is_locked()) { MUTEX_UNTAKE_LOCK(remoteCacheContQueueMutex[hash], thread); goto Lretry; } @@ -2143,7 +2143,7 @@ CacheContinuation::handleReplyEvent(int event, Event * e) // Acquire the lock to the continuation mutex MUTEX_TRY_LOCK(lock, c->mutex, e->ethread); - if (!lock) { + if (!lock.is_locked()) { // If we fail to acquire the lock, reschedule @@ -2230,7 +2230,7 @@ retry: unsigned int hash = FOLDHASH(target_ip, seq_number); MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], e->ethread); - if (!queuelock) { + if (!queuelock.is_locked()) { e->schedule_in(CACHE_RETRY_PERIOD); return EVENT_CONT; } @@ -2581,7 +2581,7 @@ CacheContinuation::do_remote_lookup(Continuation * cont, CacheKey * key, unsigned int hash = FOLDHASH(c->target_ip, c->seq_number); MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], this_ethread()); - if (!queuelock) { + if (!queuelock.is_locked()) { // failed to acquire lock: no problem, retry later c->timeout = eventProcessor.schedule_in(c, CACHE_RETRY_PERIOD, ET_CACHE_CONT_SM); } else { @@ -2803,7 +2803,7 @@ CacheContinuation::callback_user(int res, void *e) if (!is_ClusterThread(et)) { MUTEX_TRY_LOCK(lock, mutex, et); - if (lock) { + if (lock.is_locked()) { if (!action.cancelled) { action.continuation->handleEvent(res, e); } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cluster/ClusterConfig.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterConfig.cc b/iocore/cluster/ClusterConfig.cc index 332f10e..68bee6b 100644 --- a/iocore/cluster/ClusterConfig.cc +++ b/iocore/cluster/ClusterConfig.cc @@ -66,7 +66,7 @@ void ClusterAccept::ShutdownDelete() { MUTEX_TRY_LOCK(lock, this->mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { eventProcessor.schedule_imm(this, ET_CALL); return; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cluster/ClusterHandler.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterHandler.cc b/iocore/cluster/ClusterHandler.cc index 6f8abc3..bdfc3f3 100644 --- a/iocore/cluster/ClusterHandler.cc +++ b/iocore/cluster/ClusterHandler.cc @@ -1403,7 +1403,7 @@ ClusterHandler::finish_delayed_reads() DLL<ClusterVConnectionBase> l; while ((vc = (ClusterVConnection *) delayed_reads.pop())) { MUTEX_TRY_LOCK_SPIN(lock, vc->read.vio.mutex, thread, READ_LOCK_SPIN_COUNT); - if (lock) { + if (lock.is_locked()) { if (vc_ok_read(vc)) { ink_assert(!vc->read.queue); ByteBankDescriptor *d; @@ -3075,7 +3075,7 @@ ClusterHandler::do_open_local_requests() while ((cvc = local_incoming_open_local.pop())) { MUTEX_TRY_LOCK(lock, cvc->action_.mutex, tt); - if (lock) { + if (lock.is_locked()) { if (cvc->start(tt) < 0) { cvc->token.clear(); if (cvc->action_.continuation) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cluster/ClusterHandlerBase.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterHandlerBase.cc b/iocore/cluster/ClusterHandlerBase.cc index 7573ac0..a967778 100644 --- a/iocore/cluster/ClusterHandlerBase.cc +++ b/iocore/cluster/ClusterHandlerBase.cc @@ -359,7 +359,7 @@ ClusterState::doIO() ink_release_assert(io_complete); #if !defined(CLUSTER_IMMEDIATE_NETIO) MUTEX_TRY_LOCK(lock, this->mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { return 0; // unable to initiate operation } #endif @@ -558,7 +558,7 @@ ClusterState::IOComplete() if (do_iodone_event && !ch->mutex->thread_holding) { MUTEX_TRY_LOCK(lock, ch->mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { ch->handleEvent(EVENT_IMMEDIATE, (void *) 0); } else { eventProcessor.schedule_imm_signal(ch, ET_CLUSTER); @@ -1023,7 +1023,7 @@ ClusterHandler::startClusterEvent(int event, Event * e) UnixNetVConnection *vc = (UnixNetVConnection *)net_vc; MUTEX_TRY_LOCK(lock, vc->nh->mutex, e->ethread); MUTEX_TRY_LOCK(lock1, vc->mutex, e->ethread); - if (lock && lock1) { + if (lock.is_locked() && lock1.is_locked()) { vc->ep.stop(); vc->nh->open_list.remove(vc); vc->thread = NULL; @@ -1054,7 +1054,7 @@ ClusterHandler::startClusterEvent(int event, Event * e) UnixNetVConnection *vc = (UnixNetVConnection *)net_vc; MUTEX_TRY_LOCK(lock, nh->mutex, e->ethread); MUTEX_TRY_LOCK(lock1, vc->mutex, e->ethread); - if (lock && lock1) { + if (lock.is_locked() && lock1.is_locked()) { if (vc->read.in_enabled_list) nh->read_enable_list.push(vc); if (vc->write.in_enabled_list) @@ -1275,7 +1275,7 @@ ClusterHandler::protoZombieEvent(int /* event ATS_UNUSED */, Event * e) if (VALID_CHANNEL(vc)) { if (!vc->closed && vc->read.vio.op == VIO::READ) { MUTEX_TRY_LOCK(lock, vc->read.vio.mutex, t); - if (lock) { + if (lock.is_locked()) { cluster_signal_error_and_update(vc, &vc->read, 0); } else { failed = true; @@ -1285,7 +1285,7 @@ ClusterHandler::protoZombieEvent(int /* event ATS_UNUSED */, Event * e) if (VALID_CHANNEL(vc) && !vc->closed && vc->write.vio.op == VIO::WRITE) { MUTEX_TRY_LOCK(lock, vc->write.vio.mutex, t); - if (lock) { + if (lock.is_locked()) { cluster_signal_error_and_update(vc, &vc->write, 0); } else { failed = true; @@ -1316,7 +1316,7 @@ ClusterHandler::protoZombieEvent(int /* event ATS_UNUSED */, Event * e) for (int n = 0; n < MAX_COMPLETION_CALLBACK_EVENTS; ++n) { if (callout_cont[n]) { MUTEX_TRY_LOCK(lock, callout_cont[n]->mutex, t); - if (lock) { + if (lock.is_locked()) { callout_events[n]->cancel(callout_cont[n]); callout_events[n] = 0; delete callout_cont[n]; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cluster/ClusterProcessor.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterProcessor.cc b/iocore/cluster/ClusterProcessor.cc index a37d0a3..d205d43 100644 --- a/iocore/cluster/ClusterProcessor.cc +++ b/iocore/cluster/ClusterProcessor.cc @@ -133,7 +133,7 @@ ClusterProcessor::internal_invoke_remote(ClusterHandler *ch, int cluster_fn, ink_atomiclist_push(&ch->outgoing_control_al[q], (void *) c); MUTEX_TRY_LOCK(lock, ch->mutex, tt); - if (!lock) { + if (!lock.is_locked()) { if(ch->thread && ch->thread->signal_hook) ch->thread->signal_hook(ch->thread); return 1; @@ -258,7 +258,7 @@ ClusterProcessor::open_local(Continuation * cont, ClusterMachine */* m ATS_UNUSE CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPENNED_STAT); CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPEN_STAT); MUTEX_TRY_LOCK(lock, ch->mutex, thread); - if (!lock) { + if (!lock.is_locked()) { #endif if (immediate) { clusterVCAllocator_free(vc); @@ -327,7 +327,7 @@ ClusterProcessor::connect_local(Continuation * cont, ClusterVCToken * token, int CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPENNED_STAT); CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPEN_STAT); MUTEX_TRY_LOCK(lock, ch->mutex, thread); - if (!lock) { + if (!lock.is_locked()) { #endif if (immediate) { clusterVCAllocator_free(vc); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/cluster/ClusterVConnection.cc ---------------------------------------------------------------------- diff --git a/iocore/cluster/ClusterVConnection.cc b/iocore/cluster/ClusterVConnection.cc index 0630edf..c2c53ac 100644 --- a/iocore/cluster/ClusterVConnection.cc +++ b/iocore/cluster/ClusterVConnection.cc @@ -346,7 +346,7 @@ ClusterVConnection::start(EThread * t) // Establish the local side of the VC connection MUTEX_TRY_LOCK(lock, m, t); - if (!lock) { + if (!lock.is_locked()) { t->schedule_in(this, CLUSTER_CONNECT_RETRY); return EVENT_DONE; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/dns/DNS.cc ---------------------------------------------------------------------- diff --git a/iocore/dns/DNS.cc b/iocore/dns/DNS.cc index cb41b93..874d4d1 100644 --- a/iocore/dns/DNS.cc +++ b/iocore/dns/DNS.cc @@ -1098,7 +1098,7 @@ DNSProcessor::getby(const char *x, int len, int type, Continuation *cont, Option e->retries = dns_retries; e->init(x, len, type, cont, opt); MUTEX_TRY_LOCK(lock, e->mutex, this_ethread()); - if (!lock) + if (!lock.is_locked()) thread->schedule_imm(e); else e->handleEvent(EVENT_IMMEDIATE, 0); @@ -1210,7 +1210,7 @@ dns_result(DNSHandler *h, DNSEntry *e, HostEnt *ent, bool retry) { if (h->mutex->thread_holding == e->submit_thread) { MUTEX_TRY_LOCK(lock, e->action.mutex, h->mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { Debug("dns", "failed lock for result %s", e->qname); goto Lretry; } @@ -1249,7 +1249,7 @@ DNSEntry::post(DNSHandler *h, HostEnt *ent) result_ent = ent; if (h->mutex->thread_holding == submit_thread) { MUTEX_TRY_LOCK(lock, action.mutex, h->mutex->thread_holding); - if (!lock) { + if (!lock.is_locked()) { Debug("dns", "failed lock for result %s", qname); return 1; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/eventsystem/I_Lock.h ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/I_Lock.h b/iocore/eventsystem/I_Lock.h index 1bca2c8..d69a364 100644 --- a/iocore/eventsystem/I_Lock.h +++ b/iocore/eventsystem/I_Lock.h @@ -30,6 +30,131 @@ #define MAX_LOCK_TIME HRTIME_MSECONDS(200) #define THREAD_MUTEX_THREAD_HOLDING (-1024*1024) +/*------------------------------------------------------*\ +| Macros | +\*------------------------------------------------------*/ + +/** + Blocks until the lock to the ProxyMutex is acquired. + + This macro performs a blocking call until the lock to the ProxyMutex + is acquired. This call allocates a special object that holds the + lock to the ProxyMutex only for the scope of the function or + region. It is a good practice to delimit such scope explicitly + with '{' and '}'. + + @param _l Arbitrary name for the lock to use in this call + @param _m A pointer to (or address of) a ProxyMutex object + @param _t The current EThread executing your code. + +*/ +# ifdef DEBUG +# define MUTEX_LOCK(_l,_m,_t) MutexLock _l(__FILE__,__LINE__,NULL,_m,_t) +# else +# define MUTEX_LOCK(_l,_m,_t) MutexLock _l(_m,_t) +# endif //DEBUG + +# ifdef DEBUG +/** + Attempts to acquire the lock to the ProxyMutex. + + This macro attempts to acquire the lock to the specified ProxyMutex + object in a non-blocking manner. After using the macro you can + see if it was successful by comparing the lock variable with true + or false (the variable name passed in the _l parameter). + + @param _l Arbitrary name for the lock to use in this call (lock variable) + @param _m A pointer to (or address of) a ProxyMutex object + @param _t The current EThread executing your code. + +*/ +# define MUTEX_TRY_LOCK(_l,_m,_t) \ +MutexTryLock _l(__FILE__,__LINE__,(char*)NULL,_m,_t) + +/** + Attempts to acquire the lock to the ProxyMutex. + + This macro performs up to the specified number of attempts to + acquire the lock on the ProxyMutex object. It does so by running + a busy loop (busy wait) '_sc' times. You should use it with care + since it blocks the thread during that time and wastes CPU time. + + @param _l Arbitrary name for the lock to use in this call (lock variable) + @param _m A pointer to (or address of) a ProxyMutex object + @param _t The current EThread executing your code. + @param _sc The number of attempts or spin count. It must be a positive value. + +*/ +# define MUTEX_TRY_LOCK_SPIN(_l,_m,_t,_sc) \ +MutexTryLock _l(__FILE__,__LINE__,(char*)NULL,_m,_t,_sc) + +/** + Attempts to acquire the lock to the ProxyMutex. + + This macro attempts to acquire the lock to the specified ProxyMutex + object in a non-blocking manner. After using the macro you can + see if it was successful by comparing the lock variable with true + or false (the variable name passed in the _l parameter). + + @param _l Arbitrary name for the lock to use in this call (lock variable) + @param _m A pointer to (or address of) a ProxyMutex object + @param _t The current EThread executing your code. + @param _c Continuation whose mutex will be attempted to lock. + +*/ + +# define MUTEX_TRY_LOCK_FOR(_l,_m,_t,_c) \ +MutexTryLock _l(__FILE__,__LINE__,NULL,_m,_t) +# else //DEBUG +# define MUTEX_TRY_LOCK(_l,_m,_t) MutexTryLock _l(_m,_t) +# define MUTEX_TRY_LOCK_SPIN(_l,_m,_t,_sc) MutexTryLock _l(_m,_t,_sc) +# define MUTEX_TRY_LOCK_FOR(_l,_m,_t,_c) MutexTryLock _l(_m,_t) +# endif //DEBUG + +/** + Releases the lock on a ProxyMutex. + + This macro releases the lock on the ProxyMutex, provided it is + currently held. The lock must have been successfully acquired + with one of the MUTEX macros. + + @param _l Arbitrary name for the lock to use in this call (lock + variable) It must be the same name as the one used to acquire the + lock. + +*/ +# define MUTEX_RELEASE(_l) (_l).release() + +///////////////////////////////////// +// DEPRECATED DEPRECATED DEPRECATED +#ifdef DEBUG +# define MUTEX_TAKE_TRY_LOCK(_m,_t) \ +Mutex_trylock(__FILE__,__LINE__,(char*)NULL,_m,_t) +# define MUTEX_TAKE_TRY_LOCK_FOR(_m,_t,_c) \ +Mutex_trylock(__FILE__,__LINE__,(char*)NULL,_m,_t) +# define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m,_t,_c,_sc) \ +Mutex_trylock_spin(__FILE__,__LINE__,NULL,_m,_t,_sc) +#else +# define MUTEX_TAKE_TRY_LOCK(_m,_t) Mutex_trylock(_m,_t) +# define MUTEX_TAKE_TRY_LOCK_FOR(_m,_t,_c) Mutex_trylock(_m,_t) +# define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m,_t,_c,_sc) \ +Mutex_trylock_spin(_m,_t,_sc) +#endif + +#ifdef DEBUG +# define MUTEX_TAKE_LOCK(_m,_t)\ +Mutex_lock(__FILE__,__LINE__,(char*)NULL,_m,_t) +# define MUTEX_TAKE_LOCK_FOR(_m,_t,_c) \ +Mutex_lock(__FILE__,__LINE__,NULL,_m,_t) +#else +# define MUTEX_TAKE_LOCK(_m,_t) Mutex_lock(_m,_t) +# define MUTEX_TAKE_LOCK_FOR(_m,_t,_c) Mutex_lock(_m,_t) +#endif //DEBUG + +#define MUTEX_UNTAKE_LOCK(_m,_t) Mutex_unlock(_m,_t) +// DEPRECATED DEPRECATED DEPRECATED +///////////////////////////////////// + class EThread; typedef EThread *EThreadPtr; typedef volatile EThreadPtr VolatileEThreadPtr; @@ -85,7 +210,7 @@ public: */ volatile EThreadPtr thread_holding; - + int nthread_holding; #ifdef DEBUG @@ -313,36 +438,20 @@ Mutex_unlock(ProxyMutex * m, EThread * t) } } -struct MutexLock +/** Scoped lock class for ProxyMutex + */ +class MutexLock { +private: Ptr<ProxyMutex> m; - MutexLock():m(NULL) - { - }; - +public: MutexLock( #ifdef DEBUG const char *afile, int aline, const char *ahandler, #endif //DEBUG ProxyMutex * am, EThread * t):m(am) { - - Mutex_lock( -#ifdef DEBUG - afile, aline, ahandler, -#endif //DEBUG - m, t); - } - - void set_and_take( -#ifdef DEBUG - const char *afile, int aline, const char *ahandler, -#endif //DEBUG - ProxyMutex * am, EThread * t) - { - - m = am; Mutex_lock( #ifdef DEBUG afile, aline, ahandler, @@ -350,28 +459,21 @@ struct MutexLock m, t); } - void release() - { - if (m) - Mutex_unlock(m, m->thread_holding); - m.clear(); - } - ~MutexLock() { - if (m) - Mutex_unlock(m, m->thread_holding); + Mutex_unlock(m, m->thread_holding); } - - int operator!() const { return false; } - operator bool() { return true; } }; -struct MutexTryLock +/** Scoped try lock class for ProxyMutex + */ +class MutexTryLock { +private: Ptr<ProxyMutex> m; volatile bool lock_acquired; +public: MutexTryLock( #ifdef DEBUG const char *afile, int aline, const char *ahandler, @@ -408,8 +510,17 @@ struct MutexTryLock Mutex_unlock(m.m_ptr, m.m_ptr->thread_holding); } + /** Spin till lock is acquired + */ + void acquire(EThread * t) + { + MUTEX_TAKE_LOCK(m.m_ptr, t); + lock_acquired = true; + } + void release() { + ink_assert(m.m_ptr); if (m.m_ptr) { Mutex_unlock(m.m_ptr, m.m_ptr->thread_holding); m.clear(); @@ -417,8 +528,8 @@ struct MutexTryLock lock_acquired = false; } - int operator!() const { return !lock_acquired; } - operator bool() const { return lock_acquired; } + bool is_locked() const { return lock_acquired; } + const ProxyMutex* get_mutex() { return m.m_ptr; } }; inline void @@ -453,133 +564,4 @@ new_ProxyMutex() return m; } -/*------------------------------------------------------*\ -| Macros | -\*------------------------------------------------------*/ - -/** - Blocks until the lock to the ProxyMutex is acquired. - - This macro performs a blocking call until the lock to the ProxyMutex - is acquired. This call allocates a special object that holds the - lock to the ProxyMutex only for the scope of the function or - region. It is a good practice to delimit such scope explicitly - with '{' and '}'. - - @param _l Arbitrary name for the lock to use in this call - @param _m A pointer to (or address of) a ProxyMutex object - @param _t The current EThread executing your code. - -*/ -# ifdef DEBUG -# define MUTEX_LOCK(_l,_m,_t) MutexLock _l(__FILE__,__LINE__,NULL,_m,_t) -# else -# define MUTEX_LOCK(_l,_m,_t) MutexLock _l(_m,_t) -# endif //DEBUG - -# ifdef DEBUG -/** - Attempts to acquire the lock to the ProxyMutex. - - This macro attempts to acquire the lock to the specified ProxyMutex - object in a non-blocking manner. After using the macro you can - see if it was successful by comparing the lock variable with true - or false (the variable name passed in the _l parameter). - - @param _l Arbitrary name for the lock to use in this call (lock variable) - @param _m A pointer to (or address of) a ProxyMutex object - @param _t The current EThread executing your code. - -*/ -# define MUTEX_TRY_LOCK(_l,_m,_t) \ -MutexTryLock _l(__FILE__,__LINE__,(char*)NULL,_m,_t) - -/** - Attempts to acquire the lock to the ProxyMutex. - - This macro performs up to the specified number of attempts to - acquire the lock on the ProxyMutex object. It does so by running - a busy loop (busy wait) '_sc' times. You should use it with care - since it blocks the thread during that time and wastes CPU time. - - @param _l Arbitrary name for the lock to use in this call (lock variable) - @param _m A pointer to (or address of) a ProxyMutex object - @param _t The current EThread executing your code. - @param _sc The number of attempts or spin count. It must be a positive value. - -*/ -# define MUTEX_TRY_LOCK_SPIN(_l,_m,_t,_sc) \ -MutexTryLock _l(__FILE__,__LINE__,(char*)NULL,_m,_t,_sc) - - -/** - Attempts to acquire the lock to the ProxyMutex. - - This macro attempts to acquire the lock to the specified ProxyMutex - object in a non-blocking manner. After using the macro you can - see if it was successful by comparing the lock variable with true - or false (the variable name passed in the _l parameter). - - @param _l Arbitrary name for the lock to use in this call (lock variable) - @param _m A pointer to (or address of) a ProxyMutex object - @param _t The current EThread executing your code. - @param _c Continuation whose mutex will be attempted to lock. - -*/ - -# define MUTEX_TRY_LOCK_FOR(_l,_m,_t,_c) \ -MutexTryLock _l(__FILE__,__LINE__,NULL,_m,_t) -# else //DEBUG -# define MUTEX_TRY_LOCK(_l,_m,_t) MutexTryLock _l(_m,_t) -# define MUTEX_TRY_LOCK_SPIN(_l,_m,_t,_sc) MutexTryLock _l(_m,_t,_sc) -# define MUTEX_TRY_LOCK_FOR(_l,_m,_t,_c) MutexTryLock _l(_m,_t) -# endif //DEBUG - -/** - Releases the lock on a ProxyMutex. - - This macro releases the lock on the ProxyMutex, provided it is - currently held. The lock must have been successfully acquired - with one of the MUTEX macros. - - @param _l Arbitrary name for the lock to use in this call (lock - variable) It must be the same name as the one used to acquire the - lock. - -*/ -# define MUTEX_RELEASE(_l) (_l).release() - -///////////////////////////////////// -// DEPRECATED DEPRECATED DEPRECATED -#ifdef DEBUG -# define MUTEX_TAKE_TRY_LOCK(_m,_t) \ -Mutex_trylock(__FILE__,__LINE__,(char*)NULL,_m,_t) -# define MUTEX_TAKE_TRY_LOCK_FOR(_m,_t,_c) \ -Mutex_trylock(__FILE__,__LINE__,(char*)NULL,_m,_t) -# define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m,_t,_c,_sc) \ -Mutex_trylock_spin(__FILE__,__LINE__,NULL,_m,_t,_sc) -#else -# define MUTEX_TAKE_TRY_LOCK(_m,_t) Mutex_trylock(_m,_t) -# define MUTEX_TAKE_TRY_LOCK_FOR(_m,_t,_c) Mutex_trylock(_m,_t) -# define MUTEX_TAKE_TRY_LOCK_FOR_SPIN(_m,_t,_c,_sc) \ -Mutex_trylock_spin(_m,_t,_sc) -#endif - -#ifdef DEBUG -# define MUTEX_TAKE_LOCK(_m,_t)\ -Mutex_lock(__FILE__,__LINE__,(char*)NULL,_m,_t) -# define MUTEX_SET_AND_TAKE_LOCK(_s,_m,_t)\ -_s.set_and_take(__FILE__,__LINE__,(char*)NULL,_m,_t) -# define MUTEX_TAKE_LOCK_FOR(_m,_t,_c) \ -Mutex_lock(__FILE__,__LINE__,NULL,_m,_t) -#else -# define MUTEX_TAKE_LOCK(_m,_t) Mutex_lock(_m,_t) -# define MUTEX_SET_AND_TAKE_LOCK(_s,_m,_t)_s.set_and_take(_m,_t) -# define MUTEX_TAKE_LOCK_FOR(_m,_t,_c) Mutex_lock(_m,_t) -#endif //DEBUG - -#define MUTEX_UNTAKE_LOCK(_m,_t) Mutex_unlock(_m,_t) -// DEPRECATED DEPRECATED DEPRECATED -///////////////////////////////////// - #endif // _Lock_h_ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/eventsystem/UnixEThread.cc ---------------------------------------------------------------------- diff --git a/iocore/eventsystem/UnixEThread.cc b/iocore/eventsystem/UnixEThread.cc index 4c9fed9..cb4838b 100644 --- a/iocore/eventsystem/UnixEThread.cc +++ b/iocore/eventsystem/UnixEThread.cc @@ -132,7 +132,7 @@ EThread::process_event(Event * e, int calling_code) { ink_assert((!e->in_the_prot_queue && !e->in_the_priority_queue)); MUTEX_TRY_LOCK_FOR(lock, e->mutex.m_ptr, this, e->continuation); - if (!lock) { + if (!lock.is_locked()) { e->timeout_at = cur_time + DELAY_FOR_RETRY; EventQueueExternal.enqueue_local(e); } else { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/hostdb/HostDB.cc ---------------------------------------------------------------------- diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc index e295f7d..1e54bcd 100644 --- a/iocore/hostdb/HostDB.cc +++ b/iocore/hostdb/HostDB.cc @@ -725,7 +725,7 @@ HostDBProcessor::getby(Continuation * cont, if ((!hostdb_enable || (hostname && !*hostname)) || (hostdb_disable_reverse_lookup && ip)) { MUTEX_TRY_LOCK(lock, cont->mutex, thread); - if (!lock) + if (!lock.is_locked()) goto Lretry; cont->handleEvent(EVENT_HOST_DB_LOOKUP, NULL); return ACTION_RESULT_DONE; @@ -765,7 +765,7 @@ HostDBProcessor::getby(Continuation * cont, MUTEX_TRY_LOCK(lock, bmutex, thread); MUTEX_TRY_LOCK(lock2, cont->mutex, thread); - if (lock && lock2) { + if (lock.is_locked() && lock2.is_locked()) { // If we can get the lock and a level 1 probe succeeds, return HostDBInfo *r = probe(bmutex, md5, aforce_dns); if (r) { @@ -878,7 +878,7 @@ HostDBProcessor::getSRVbyname_imm(Continuation * cont, process_srv_info_pfn proc MUTEX_TRY_LOCK(lock, bucket_mutex, thread); // If we can get the lock and a level 1 probe succeeds, return - if (lock) { + if (lock.is_locked()) { HostDBInfo *r = probe(bucket_mutex, md5, false); if (r) { Debug("hostdb", "immediate SRV answer for %s from hostdb", hostname); @@ -964,22 +964,19 @@ HostDBProcessor::getbyname_imm(Continuation * cont, process_hostdb_info_pfn proc // find the partition lock ProxyMutex *bucket_mutex = hostDB.lock_for_bucket((int) (fold_md5(md5.hash) % hostDB.buckets)); MUTEX_LOCK(lock, bucket_mutex, thread); - - if (lock) { - // If we can get the lock do a level 1 probe for immediate result. - HostDBInfo *r = probe(bucket_mutex, md5, false); - if (r) { - if (r->failed()) // fail, see if we should retry with alternate - loop = check_for_retry(md5.db_mark, opt.host_res_style); - if (!loop) { - // No retry -> final result. Return it. - Debug("hostdb", "immediate answer for %.*s", md5.host_len, md5.host_name); - HOSTDB_INCREMENT_DYN_STAT(hostdb_total_hits_stat); - (cont->*process_hostdb_info) (r); - return ACTION_RESULT_DONE; - } - md5.refresh(); // Update for retry. + // do a level 1 probe for immediate result. + HostDBInfo *r = probe(bucket_mutex, md5, false); + if (r) { + if (r->failed()) // fail, see if we should retry with alternate + loop = check_for_retry(md5.db_mark, opt.host_res_style); + if (!loop) { + // No retry -> final result. Return it. + Debug("hostdb", "immediate answer for %.*s", md5.host_len, md5.host_name); + HOSTDB_INCREMENT_DYN_STAT(hostdb_total_hits_stat); + (cont->*process_hostdb_info) (r); + return ACTION_RESULT_DONE; } + md5.refresh(); // Update for retry. } } while (loop); } @@ -1060,7 +1057,7 @@ HostDBProcessor::setby(const char *hostname, int len, sockaddr const* ip, HostDB EThread *thread = this_ethread(); MUTEX_TRY_LOCK(lock, mutex, thread); - if (lock) { + if (lock.is_locked()) { HostDBInfo *r = probe(mutex, md5, false); if (r) do_setby(r, app, hostname, md5.ip); @@ -1207,7 +1204,7 @@ HostDBContinuation::removeEvent(int /* event ATS_UNUSED */, Event * e) Continuation *cont = action.continuation; MUTEX_TRY_LOCK(lock, cont ? (ProxyMutex *) cont->mutex : (ProxyMutex *) NULL, e->ethread); - if (!lock) { + if (!lock.is_locked()) { e->schedule_in(HOST_DB_RETRY_PERIOD); return EVENT_CONT; } @@ -1333,7 +1330,7 @@ HostDBContinuation::dnsPendingEvent(int event, Event * e) if (event == EVENT_INTERVAL) { // we timed out, return a failure to the user MUTEX_TRY_LOCK_FOR(lock, action.mutex, ((Event *) e)->ethread, action.continuation); - if (!lock) { + if (!lock.is_locked()) { timeout = eventProcessor.schedule_in(this, HOST_DB_RETRY_PERIOD); return EVENT_CONT; } @@ -1385,7 +1382,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt * e) return EVENT_DONE; } MUTEX_TRY_LOCK_FOR(lock, action.mutex, thread, action.continuation); - if (!lock) { + if (!lock.is_locked()) { timeout = thread->schedule_in(this, HOST_DB_RETRY_PERIOD); return EVENT_CONT; } @@ -1610,7 +1607,7 @@ HostDBContinuation::dnsEvent(int event, HostEnt * e) } MUTEX_TRY_LOCK_FOR(lock, action.mutex, thread, action.continuation); - if (!lock) { + if (!lock.is_locked()) { remove_trigger_pending_dns(); SET_HANDLER((HostDBContHandler) & HostDBContinuation::probeEvent); thread->schedule_in(this, HOST_DB_RETRY_PERIOD); @@ -1793,7 +1790,7 @@ HostDBContinuation::probeEvent(int /* event ATS_UNUSED */, Event * e) EThread *t = e ? e->ethread : this_ethread(); MUTEX_TRY_LOCK_FOR(lock, action.mutex, t, action.continuation); - if (!lock) { + if (!lock.is_locked()) { mutex->thread_holding->schedule_in(this, HOST_DB_RETRY_PERIOD); return EVENT_CONT; } @@ -1951,7 +1948,7 @@ HostDBContinuation::clusterResponseEvent(int/* event ATS_UNUSED */, Event * e) from_cont = 0; MUTEX_TRY_LOCK(lock, c->mutex, e->ethread); MUTEX_TRY_LOCK(lock2, c->action.mutex, e->ethread); - if (!lock || !lock2) { + if (!lock.is_locked() || !lock2.is_locked()) { e->schedule_in(HOST_DB_RETRY_PERIOD); return EVENT_CONT; } @@ -2021,7 +2018,7 @@ HostDBContinuation::clusterEvent(int event, Event * e) // case EVENT_INTERVAL:{ MUTEX_TRY_LOCK_FOR(lock, action.mutex, e->ethread, action.continuation); - if (!lock) { + if (!lock.is_locked()) { e->schedule_in(HOST_DB_RETRY_PERIOD); return EVENT_CONT; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/SSLNetVConnection.cc ---------------------------------------------------------------------- diff --git a/iocore/net/SSLNetVConnection.cc b/iocore/net/SSLNetVConnection.cc index e84008f..c334733 100644 --- a/iocore/net/SSLNetVConnection.cc +++ b/iocore/net/SSLNetVConnection.cc @@ -78,7 +78,7 @@ namespace { EThread* eth = this_ethread(); MUTEX_TRY_LOCK(lock, _target->mutex, eth); - if (lock) { // got the target lock, we can proceed. + if (lock.is_locked()) { // got the target lock, we can proceed. _target->handleEvent(_eventId, _edata); delete this; } else { // can't get both locks, try again. @@ -105,7 +105,7 @@ namespace { ) { EThread* eth = this_ethread(); MUTEX_TRY_LOCK(lock, target->mutex, eth); - if (lock) { + if (lock.is_locked()) { target->handleEvent(eventId, edata); } else { eventProcessor.schedule_imm(new ContWrapper(mutex, target, eventId, edata), ET_NET); @@ -399,7 +399,7 @@ SSLNetVConnection::net_read_io(NetHandler *nh, EThread *lthread) } MUTEX_TRY_LOCK_FOR(lock, s->vio.mutex, lthread, s->vio._cont); - if (!lock) { + if (!lock.is_locked()) { readReschedule(nh); return; } @@ -564,7 +564,7 @@ SSLNetVConnection::net_read_io(NetHandler *nh, EThread *lthread) break; case SSL_WRITE_WOULD_BLOCK: case SSL_READ_WOULD_BLOCK: - if (lock.m.m_ptr != s->vio.mutex.m_ptr) { + if (lock.get_mutex() != s->vio.mutex.m_ptr) { Debug("ssl", "ssl_read_from_net, mutex switched"); if (ret == SSL_READ_WOULD_BLOCK) readReschedule(nh); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/SSLSessionCache.cc ---------------------------------------------------------------------- diff --git a/iocore/net/SSLSessionCache.cc b/iocore/net/SSLSessionCache.cc index 8fb30d8..73b9eaa 100644 --- a/iocore/net/SSLSessionCache.cc +++ b/iocore/net/SSLSessionCache.cc @@ -121,13 +121,13 @@ void SSLSessionBucket::insertSession(const SSLSessionID &id, SSL_SESSION *sess) SSLSession *ssl_session = new SSLSession(id, buf, len); - ink_scoped_try_mutex scoped_mutex(mutex); - if (!scoped_mutex.hasLock()) { + MUTEX_TRY_LOCK(lock, &mutex, this_ethread()); + if (!lock.is_locked()) { SSL_INCREMENT_DYN_STAT(ssl_session_cache_lock_contention); if (SSLConfigParams::session_cache_skip_on_lock_contention) return; - scoped_mutex.lock(); + lock.acquire(this_ethread()); } PRINT_BUCKET("insertSession before") @@ -141,7 +141,8 @@ void SSLSessionBucket::insertSession(const SSLSessionID &id, SSL_SESSION *sess) PRINT_BUCKET("insertSession after") } -bool SSLSessionBucket::getSession(const SSLSessionID &id, SSL_SESSION **sess) const { +bool SSLSessionBucket::getSession(const SSLSessionID &id, + SSL_SESSION **sess) { char buf[id.len * 2 + 1]; buf[0] = '\0'; // just to be safe. if (is_debug_tag_set("ssl.session_cache")) { @@ -150,12 +151,13 @@ bool SSLSessionBucket::getSession(const SSLSessionID &id, SSL_SESSION **sess) co Debug("ssl.session_cache", "Looking for session with id '%s' in bucket %p", buf, this); - ink_scoped_try_mutex scoped_mutex(mutex); - if (!scoped_mutex.hasLock()) { + MUTEX_TRY_LOCK(lock, &mutex, this_ethread()); + if (!lock.is_locked()) { SSL_INCREMENT_DYN_STAT(ssl_session_cache_lock_contention); if (SSLConfigParams::session_cache_skip_on_lock_contention) return false; - scoped_mutex.lock(); + + lock.acquire(this_ethread()); } PRINT_BUCKET("getSession") @@ -211,7 +213,7 @@ void inline SSLSessionBucket::removeOldestSession() { } void SSLSessionBucket::removeSession(const SSLSessionID &id) { - ink_scoped_mutex scoped_mutex(mutex); // We can't bail on contention here because this session MUST be removed. + MUTEX_LOCK(lock, &mutex, this_ethread()); // We can't bail on contention here because this session MUST be removed. SSLSession *node = queue.head; while (node) { if (node->session_id == id) @@ -226,11 +228,11 @@ void SSLSessionBucket::removeSession(const SSLSessionID &id) { /* Session Bucket */ SSLSessionBucket::SSLSessionBucket() { - ink_mutex_init(&mutex, "session_bucket"); + mutex.init("session_bucket"); } SSLSessionBucket::~SSLSessionBucket() { - ink_mutex_destroy(&mutex); + } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/SSLSessionCache.h ---------------------------------------------------------------------- diff --git a/iocore/net/SSLSessionCache.h b/iocore/net/SSLSessionCache.h index 82f4959..38f0fbb 100644 --- a/iocore/net/SSLSessionCache.h +++ b/iocore/net/SSLSessionCache.h @@ -120,14 +120,14 @@ public: ~SSLSessionBucket(); void removeOldestSession(); void insertSession(const SSLSessionID &, SSL_SESSION *ctx); - bool getSession(const SSLSessionID &, SSL_SESSION **ctx) const; + bool getSession(const SSLSessionID &, SSL_SESSION **ctx); void removeSession(const SSLSessionID &); private: /* these method must be used while hold the lock */ void print(const char *) const; - mutable ink_mutex mutex; + ProxyMutex mutex; CountQueue<SSLSession> queue; }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/Socks.cc ---------------------------------------------------------------------- diff --git a/iocore/net/Socks.cc b/iocore/net/Socks.cc index 59f9d5f..073cf51 100644 --- a/iocore/net/Socks.cc +++ b/iocore/net/Socks.cc @@ -136,7 +136,7 @@ void SocksEntry::free() { MUTEX_TRY_LOCK(lock, action_.mutex, this_ethread()); - if (!lock) { + if (lock.is_locked()) { // Socks continuation share the user's lock // so acquiring a lock shouldn't fail ink_assert(0); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/UnixNet.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixNet.cc b/iocore/net/UnixNet.cc index 6588879..f4ee7e7 100644 --- a/iocore/net/UnixNet.cc +++ b/iocore/net/UnixNet.cc @@ -57,7 +57,7 @@ public: while (UnixNetVConnection *vc = nh->cop_list.pop()) { // If we cannot get the lock don't stop just keep cleaning MUTEX_TRY_LOCK(lock, vc->mutex, this_ethread()); - if (!lock.lock_acquired) { + if (!lock.is_locked()) { NET_INCREMENT_DYN_STAT(inactivity_cop_lock_acquire_failure_stat); continue; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/UnixNetAccept.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixNetAccept.cc b/iocore/net/UnixNetAccept.cc index 16481db..5ba79fc 100644 --- a/iocore/net/UnixNetAccept.cc +++ b/iocore/net/UnixNetAccept.cc @@ -328,7 +328,7 @@ NetAccept::acceptEvent(int event, void *ep) else m = mutex; MUTEX_TRY_LOCK(lock, m, e->ethread); - if (lock) { + if (lock.is_locked()) { if (action_->cancelled) { e->cancel(); NET_DECREMENT_DYN_STAT(net_accepts_currently_open_stat); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/UnixNetPages.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixNetPages.cc b/iocore/net/UnixNetPages.cc index bec4c8c..a734fa4 100644 --- a/iocore/net/UnixNetPages.cc +++ b/iocore/net/UnixNetPages.cc @@ -53,7 +53,7 @@ struct ShowNet: public ShowCont EThread *ethread = e->ethread; NetHandler *nh = get_NetHandler(ethread); MUTEX_TRY_LOCK(lock, nh->mutex, ethread); - if (!lock) { + if (!lock.is_locked()) { ethread->schedule_in(this, NET_RETRY_DELAY); return EVENT_DONE; } @@ -157,7 +157,7 @@ struct ShowNet: public ShowCont NetHandler *nh = get_NetHandler(ethread); PollDescriptor *pollDescriptor = get_PollDescriptor(ethread); MUTEX_TRY_LOCK(lock, nh->mutex, ethread); - if (!lock) { + if (!lock.is_locked()) { ethread->schedule_in(this, NET_RETRY_DELAY); return EVENT_DONE; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/UnixNetProcessor.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixNetProcessor.cc b/iocore/net/UnixNetProcessor.cc index a16946f..a07aed8 100644 --- a/iocore/net/UnixNetProcessor.cc +++ b/iocore/net/UnixNetProcessor.cc @@ -246,9 +246,9 @@ UnixNetProcessor::connect_re_internal( if (t->is_event_type(opt->etype)) { MUTEX_TRY_LOCK(lock, cont->mutex, t); - if (lock) { + if (lock.is_locked()) { MUTEX_TRY_LOCK(lock2, get_NetHandler(t)->mutex, t); - if (lock2) { + if (lock2.is_locked()) { int ret; ret = vc->connectUp(t, NO_FD); if ((using_socks) && (ret == CONNECT_SUCCESS)) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/UnixNetVConnection.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixNetVConnection.cc b/iocore/net/UnixNetVConnection.cc index c122fbe..955ffb2 100644 --- a/iocore/net/UnixNetVConnection.cc +++ b/iocore/net/UnixNetVConnection.cc @@ -212,7 +212,7 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) MUTEX_TRY_LOCK_FOR(lock, s->vio.mutex, thread, s->vio._cont); - if (!lock || lock.m.m_ptr != s->vio.mutex.m_ptr) { + if (!lock.is_locked() || lock.get_mutex() != s->vio.mutex.m_ptr) { read_reschedule(nh, vc); return; } @@ -320,7 +320,7 @@ read_from_net(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) if (read_signal_and_update(VC_EVENT_READ_READY, vc) != EVENT_CONT) return; // change of lock... don't look at shared variables! - if (lock.m.m_ptr != s->vio.mutex.m_ptr) { + if (lock.get_mutex() != s->vio.mutex.m_ptr) { read_reschedule(nh, vc); return; } @@ -360,7 +360,7 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) MUTEX_TRY_LOCK_FOR(lock, s->vio.mutex, thread, s->vio._cont); - if (!lock || lock.m.m_ptr != s->vio.mutex.m_ptr) { + if (!lock.is_locked() || lock.get_mutex() != s->vio.mutex.m_ptr) { write_reschedule(nh, vc); return; } @@ -506,7 +506,7 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection *vc, EThread *thread) return; } // change of lock... don't look at shared variables! - if (lock.m.m_ptr != s->vio.mutex.m_ptr) { + if (lock.get_mutex() != s->vio.mutex.m_ptr) { write_reschedule(nh, vc); return; } @@ -740,7 +740,7 @@ UnixNetVConnection::reenable(VIO *vio) } } else { MUTEX_TRY_LOCK(lock, nh->mutex, t); - if (!lock) { + if (!lock.is_locked()) { if (vio == &read.vio) { if (!read.in_enabled_list) { read.in_enabled_list = 1; @@ -951,7 +951,7 @@ int UnixNetVConnection::startEvent(int /* event ATS_UNUSED */, Event *e) { MUTEX_TRY_LOCK(lock, get_NetHandler(e->ethread)->mutex, e->ethread); - if (!lock) { + if (!lock.is_locked()) { e->schedule_in(NET_RETRY_DELAY); return EVENT_CONT; } @@ -968,7 +968,7 @@ UnixNetVConnection::acceptEvent(int event, Event *e) thread = e->ethread; MUTEX_TRY_LOCK(lock, get_NetHandler(thread)->mutex, e->ethread); - if (!lock) { + if (!lock.is_locked()) { if (event == EVENT_NONE) { thread->schedule_in(this, NET_RETRY_DELAY); return EVENT_DONE; @@ -1022,9 +1022,9 @@ UnixNetVConnection::mainEvent(int event, Event *e) MUTEX_TRY_LOCK(rlock, read.vio.mutex ? (ProxyMutex *) read.vio.mutex : (ProxyMutex *) e->ethread->mutex, e->ethread); MUTEX_TRY_LOCK(wlock, write.vio.mutex ? (ProxyMutex *) write.vio.mutex : (ProxyMutex *) e->ethread->mutex, e->ethread); - if (!hlock || !rlock || !wlock || - (read.vio.mutex.m_ptr && rlock.m.m_ptr != read.vio.mutex.m_ptr) || - (write.vio.mutex.m_ptr && wlock.m.m_ptr != write.vio.mutex.m_ptr)) { + if (!hlock.is_locked() || !rlock.is_locked() || !wlock.is_locked() || + (read.vio.mutex.m_ptr && rlock.get_mutex() != read.vio.mutex.m_ptr) || + (write.vio.mutex.m_ptr && wlock.get_mutex() != write.vio.mutex.m_ptr)) { #ifndef INACTIVITY_TIMEOUT if (e == active_timeout) #endif http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/iocore/net/UnixUDPNet.cc ---------------------------------------------------------------------- diff --git a/iocore/net/UnixUDPNet.cc b/iocore/net/UnixUDPNet.cc index 9201fdf..5c6f48d 100644 --- a/iocore/net/UnixUDPNet.cc +++ b/iocore/net/UnixUDPNet.cc @@ -155,7 +155,7 @@ UDPNetProcessorInternal::udp_callback(UDPNetHandler * nh, UDPConnection * xuc, E if (uc->continuation && uc->mutex) { MUTEX_TRY_LOCK_FOR(lock, uc->mutex, thread, uc->continuation); - if (!lock) { + if (!lock.is_locked()) { return 1; } uc->AddRef(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/lib/ts/ink_mutex.h ---------------------------------------------------------------------- diff --git a/lib/ts/ink_mutex.h b/lib/ts/ink_mutex.h index 1de3e9a..bc84da4 100644 --- a/lib/ts/ink_mutex.h +++ b/lib/ts/ink_mutex.h @@ -112,48 +112,4 @@ ink_mutex_try_acquire(ink_mutex * m) } #endif /* #if defined(POSIX_THREAD) */ - -struct ink_scoped_mutex -{ - explicit ink_scoped_mutex(ink_mutex& m) : mtx(m) { - ink_mutex_acquire(&mtx); - } - - ~ink_scoped_mutex() { - ink_mutex_release(&mtx); - } - -private: - ink_mutex& mtx; -}; - -struct ink_scoped_try_mutex -{ - explicit ink_scoped_try_mutex(ink_mutex& m) : mtx(m), has_lock(false) { - if(ink_mutex_try_acquire(&mtx)) { - has_lock = true; - } - } - - void lock() { - if (!has_lock) - ink_mutex_acquire(&mtx); - has_lock = true; - } - - bool hasLock() const { - return has_lock; - } - - ~ink_scoped_try_mutex() { - if (has_lock) - ink_mutex_release(&mtx); - } - -private: - ink_mutex& mtx; - bool has_lock; -}; - - #endif /* _ink_mutex_h_ */ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/FetchSM.cc ---------------------------------------------------------------------- diff --git a/proxy/FetchSM.cc b/proxy/FetchSM.cc index 8188dd7..18bbcd8 100644 --- a/proxy/FetchSM.cc +++ b/proxy/FetchSM.cc @@ -606,7 +606,7 @@ FetchSM::ext_read_data(char *buf, size_t len) if (fetch_flags & TS_FETCH_FLAGS_NEWLOCK) { MUTEX_TRY_LOCK(lock, mutex, this_ethread()); - if (!lock) + if (!lock.is_locked()) return 0; } @@ -656,7 +656,7 @@ FetchSM::ext_destroy() if (fetch_flags & TS_FETCH_FLAGS_NEWLOCK) { MUTEX_TRY_LOCK(lock, mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { eventProcessor.schedule_in(this, FETCH_LOCK_RETRY_TIME); return; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/ICP.cc ---------------------------------------------------------------------- diff --git a/proxy/ICP.cc b/proxy/ICP.cc index 57e1929..71afe9d 100644 --- a/proxy/ICP.cc +++ b/proxy/ICP.cc @@ -526,7 +526,7 @@ ICPPeerReadCont::PeerReadStateMachine(PeerReadData * s, Event * e) // State machine to process ICP data received on UDP socket //----------------------------------------------------------- MUTEX_TRY_LOCK(lock, this->mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { // we didn't get the lock, so we don't need to unlock it // coverity[missing_unlock] return EVENT_CONT; // try again later http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/InkAPI.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc index 4054d34..6ff206e 100644 --- a/proxy/InkAPI.cc +++ b/proxy/InkAPI.cc @@ -4497,7 +4497,7 @@ TSHttpSsnReenable(TSHttpSsn ssnp, TSEvent event) eventProcessor.schedule_imm(new TSHttpSsnCallback(cs, event), ET_NET); } else { MUTEX_TRY_LOCK(trylock, cs->mutex, eth); - if (!trylock) { + if (!trylock.is_locked()) { eventProcessor.schedule_imm(new TSHttpSsnCallback(cs, event), ET_NET); } else { cs->handleEvent((int) event, 0); @@ -5564,7 +5564,7 @@ TSHttpTxnReenable(TSHttpTxn txnp, TSEvent event) eventProcessor.schedule_imm(new TSHttpSMCallback(sm, event), ET_NET); } else { MUTEX_TRY_LOCK(trylock, sm->mutex, eth); - if (!trylock) { + if (!trylock.is_locked()) { eventProcessor.schedule_imm(new TSHttpSMCallback(sm, event), ET_NET); } else { sm->state_api_callback((int) event, 0); @@ -8764,7 +8764,7 @@ TSVConnReenable(TSVConn vconn) // callback on the VC thread or it doesn't work (not sure why - // deadlock or it ends up interacting with the wrong NetHandler). MUTEX_TRY_LOCK(trylock, ssl_vc->mutex, eth); - if (!trylock) { + if (!trylock.is_locked()) { ssl_vc->thread->schedule_imm(new TSSslCallback(ssl_vc)); } else { ssl_vc->reenable(ssl_vc->nh); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/InkAPIInternal.h ---------------------------------------------------------------------- diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h index 08664f1..319291b 100644 --- a/proxy/InkAPIInternal.h +++ b/proxy/InkAPIInternal.h @@ -319,7 +319,7 @@ public: { if (m_cont->mutex != NULL) { MUTEX_TRY_LOCK(trylock, m_cont->mutex, this_ethread()); - if (!trylock) { + if (!trylock.is_locked()) { eventProcessor.schedule_in(this, HRTIME_MSECONDS(10), ET_TASK); } else { m_cont->handleEvent(TS_EVENT_MGMT_UPDATE, NULL); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/PluginVC.cc ---------------------------------------------------------------------- diff --git a/proxy/PluginVC.cc b/proxy/PluginVC.cc index d5d4c07..f7db604 100644 --- a/proxy/PluginVC.cc +++ b/proxy/PluginVC.cc @@ -325,7 +325,7 @@ PluginVC::reenable_re(VIO * vio) Debug("pvc", "[%u] %s: reenable_re %s", core_obj->id, PVC_TYPE, (vio->op == VIO::WRITE) ? "Write" : "Read"); MUTEX_TRY_LOCK(lock, this->mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { if (vio->op == VIO::WRITE) { need_write_process = true; } else { @@ -376,7 +376,7 @@ PluginVC::do_io_close(int /* flag ATS_UNUSED */) MUTEX_TRY_LOCK(lock, mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { setup_event_cb(PVC_LOCK_RETRY_TIME, &sm_lock_retry_event); closed = true; return; @@ -491,7 +491,7 @@ PluginVC::process_write_side(bool other_side_call) EThread *my_ethread = mutex->thread_holding; ink_assert(my_ethread != NULL); MUTEX_TRY_LOCK(lock, write_state.vio.mutex, my_ethread); - if (!lock) { + if (!lock.is_locked()) { Debug("pvc_event", "[%u] %s: process_write_side lock miss, retrying", core_obj->id, PVC_TYPE); need_write_process = true; @@ -608,7 +608,7 @@ PluginVC::process_read_side(bool other_side_call) EThread *my_ethread = mutex->thread_holding; ink_assert(my_ethread != NULL); MUTEX_TRY_LOCK(lock, read_state.vio.mutex, my_ethread); - if (!lock) { + if (!lock.is_locked()) { Debug("pvc_event", "[%u] %s: process_read_side lock miss, retrying", core_obj->id, PVC_TYPE); need_read_process = true; @@ -753,7 +753,7 @@ PluginVC::process_timeout(Event * e, int event_to_send, Event ** our_eptr) if (read_state.vio.op == VIO::READ && !read_state.shutdown && read_state.vio.ntodo() > 0) { MUTEX_TRY_LOCK(lock, read_state.vio.mutex, e->ethread); - if (!lock) { + if (!lock.is_locked()) { e->schedule_in(PVC_LOCK_RETRY_TIME); return; } @@ -761,7 +761,7 @@ PluginVC::process_timeout(Event * e, int event_to_send, Event ** our_eptr) read_state.vio._cont->handleEvent(event_to_send, &read_state.vio); } else if (write_state.vio.op == VIO::WRITE && !write_state.shutdown && write_state.vio.ntodo() > 0) { MUTEX_TRY_LOCK(lock, write_state.vio.mutex, e->ethread); - if (!lock) { + if (!lock.is_locked()) { e->schedule_in(PVC_LOCK_RETRY_TIME); return; } @@ -1098,7 +1098,7 @@ PluginVCCore::state_send_accept_failed(int /* event ATS_UNUSED */, void * /* dat { MUTEX_TRY_LOCK(lock, connect_to->mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { connect_to->handleEvent(NET_EVENT_ACCEPT_FAILED, NULL); destroy(); } else { @@ -1115,7 +1115,7 @@ PluginVCCore::state_send_accept(int /* event ATS_UNUSED */, void * /* data ATS_U { MUTEX_TRY_LOCK(lock, connect_to->mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { connect_to->handleEvent(NET_EVENT_ACCEPT, &passive_vc); } else { SET_HANDLER(&PluginVCCore::state_send_accept); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/Prefetch.cc ---------------------------------------------------------------------- diff --git a/proxy/Prefetch.cc b/proxy/Prefetch.cc index 4ab8159..13541bd 100644 --- a/proxy/Prefetch.cc +++ b/proxy/Prefetch.cc @@ -483,7 +483,7 @@ PrefetchTransform::handle_event(int event, void *edata) ink_assert(m_output_vc != NULL); MUTEX_TRY_LOCK(trylock, m_write_vio.mutex, this_ethread()); - if (!trylock) { + if (!trylock.is_locked()) { retry(10); return 0; } @@ -1485,7 +1485,7 @@ PrefetchBlaster::handleEvent(int event, void *data) if (url_list) { MUTEX_TRY_LOCK(trylock, url_list->mutex, this_ethread()); - if (!trylock) { + if (!trylock.is_locked()) { this_ethread()->schedule_in(this, HRTIME_MSECONDS(10)); break; } @@ -2087,7 +2087,7 @@ KeepAliveConnTable::append(IpEndpoint const& ip, MIOBuffer *buf, IOBufferReader int index = ip_hash(ip); MUTEX_TRY_LOCK(trylock, arr[index].mutex, this_ethread()); - if (!trylock) { + if (!trylock.is_locked()) { /* This lock fails quite often. This can be expected because, multiple threads try to append their buffer all the the same time to the same connection. Other thread holds it for a long http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/RegressionSM.cc ---------------------------------------------------------------------- diff --git a/proxy/RegressionSM.cc b/proxy/RegressionSM.cc index ba77182..58a0c3c 100644 --- a/proxy/RegressionSM.cc +++ b/proxy/RegressionSM.cc @@ -170,7 +170,7 @@ void RegressionSM::run() // TODO: Why introduce another scope here? { MUTEX_TRY_LOCK(l, mutex, this_ethread()); - if (!l || nwaiting > 1) + if (!l.is_locked() || nwaiting > 1) goto Lretry; RegressionSM *x = 0; while (ichild < n) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/Transform.cc ---------------------------------------------------------------------- diff --git a/proxy/Transform.cc b/proxy/Transform.cc index 3df17ed..9f2366d 100644 --- a/proxy/Transform.cc +++ b/proxy/Transform.cc @@ -176,12 +176,12 @@ TransformTerminus::handle_event(int event, void * /* edata ATS_UNUSED */) int64_t towrite; MUTEX_TRY_LOCK(trylock1, m_write_vio.mutex, this_ethread()); - if (!trylock1) { + if (!trylock1.is_locked()) { RETRY(); } MUTEX_TRY_LOCK(trylock2, m_read_vio.mutex, this_ethread()); - if (!trylock2) { + if (!trylock2.is_locked()) { RETRY(); } @@ -236,7 +236,7 @@ TransformTerminus::handle_event(int event, void * /* edata ATS_UNUSED */) } } else { MUTEX_TRY_LOCK(trylock2, m_read_vio.mutex, this_ethread()); - if (!trylock2) { + if (!trylock2.is_locked()) { RETRY(); } @@ -656,7 +656,7 @@ NullTransform::handle_event(int event, void *edata) } MUTEX_TRY_LOCK(trylock, m_write_vio.mutex, this_ethread()); - if (!trylock) { + if (!trylock.is_locked()) { retry(10); return 0; } @@ -805,7 +805,7 @@ RangeTransform::handle_event(int event, void *edata) } MUTEX_TRY_LOCK(trylock, m_write_vio.mutex, this_ethread()); - if (!trylock) { + if (!trylock.is_locked()) { retry(10); return 0; } http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/Update.cc ---------------------------------------------------------------------- diff --git a/proxy/Update.cc b/proxy/Update.cc index 1b1f75b..f72447c 100644 --- a/proxy/Update.cc +++ b/proxy/Update.cc @@ -795,7 +795,7 @@ int UpdateConfigManager::GetConfigParams(Ptr<UpdateConfigParams> *P) { MUTEX_TRY_LOCK(lock, mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { return 0; // Try again later } else { *P = _CP; @@ -807,7 +807,7 @@ int UpdateConfigManager::GetConfigList(Ptr<UpdateConfigList> *L) { MUTEX_TRY_LOCK(lock, mutex, this_ethread()); - if (!lock) { + if (!lock.is_locked()) { return 0; // Try again later } else { *L = _CL; @@ -1318,7 +1318,7 @@ UpdateScheduler::ChildExitEventHandler(int event, Event * /* e ATS_UNUSED */) case EVENT_INTERVAL: { MUTEX_TRY_LOCK(lock, _parent_US->mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { Debug("update", "Child UpdateScheduler exit id: %d", _base_EN->_id); _parent_US->handleEvent(EVENT_IMMEDIATE, _base_EN); delete this; @@ -1493,7 +1493,7 @@ UpdateSM::HandleSMEvent(int event, Event * /* e ATS_UNUSED */) } else { MUTEX_TRY_LOCK(lock, _US->mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { _US->handleEvent(EVENT_IMMEDIATE, (void *) _EN); delete this; return EVENT_DONE; @@ -1770,7 +1770,7 @@ RecursiveHttpGet::ExitEventHandler(int event, Event * /* e ATS_UNUSED */) case EVENT_INTERVAL: { MUTEX_TRY_LOCK(lock, _caller_cont->mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { Debug("update", "Exiting recursive read rid: %d [%s]", _id, html_parser._url); _caller_cont->handleEvent(UPDATE_EVENT_SUCCESS, 0); delete this; @@ -2550,7 +2550,7 @@ ObjectReloadCont::ObjectReloadEvent(int event, void *d) Debug("update-reload", "Connect start id=%d", _request_id); _state = ObjectReloadCont::ATTEMPT_CONNECT; MUTEX_TRY_LOCK(lock, this->mutex, this_ethread()); - ink_release_assert(lock); + ink_release_assert(lock.is_locked()); target.setToLoopback(AF_INET); target.port() = htons(HttpProxyPort::findHttp(AF_INET)->m_port); _cur_action = netProcessor.connect_re(this, &target.sa); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/api/ts/InkAPIPrivateIOCore.h ---------------------------------------------------------------------- diff --git a/proxy/api/ts/InkAPIPrivateIOCore.h b/proxy/api/ts/InkAPIPrivateIOCore.h index fab4b4a..aebf0ec 100644 --- a/proxy/api/ts/InkAPIPrivateIOCore.h +++ b/proxy/api/ts/InkAPIPrivateIOCore.h @@ -133,18 +133,16 @@ static ink_mutex big_mux; #define UNLOCK_MONGO_MUTEX ink_mutex_release (&big_mux) #endif -#define FORCE_PLUGIN_MUTEX(_c) \ - MutexLock ml; \ - LOCK_MONGO_MUTEX; \ - if (( (INKContInternal*)_c)->mutex == NULL) { \ - ( (INKContInternal*)_c)->mutex = new_ProxyMutex(); \ - UNLOCK_MONGO_MUTEX; \ - MUX_WARNING(_c); \ - MUTEX_SET_AND_TAKE_LOCK(ml, ((INKContInternal*)_c)->mutex, this_ethread()); \ - } else { \ - UNLOCK_MONGO_MUTEX; \ - MUTEX_SET_AND_TAKE_LOCK(ml, ((INKContInternal*)_c)->mutex, this_ethread()); \ - } +#define FORCE_PLUGIN_MUTEX(_c) \ + bool do_warn = false; \ + LOCK_MONGO_MUTEX; \ + if (( (INKContInternal*)_c)->mutex == NULL) { \ + ( (INKContInternal*)_c)->mutex = new_ProxyMutex(); \ + do_warn = true; \ + } \ + UNLOCK_MONGO_MUTEX; \ + if (do_warn) MUX_WARNING(_c); \ + MUTEX_LOCK(ml, ((INKContInternal*)_c)->mutex, this_ethread()); #ifdef __cplusplus extern "C" http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/congest/Congestion.cc ---------------------------------------------------------------------- diff --git a/proxy/congest/Congestion.cc b/proxy/congest/Congestion.cc index 7d7ae7a..1ab17a0 100644 --- a/proxy/congest/Congestion.cc +++ b/proxy/congest/Congestion.cc @@ -707,7 +707,7 @@ CongestionEntry::failed_at(ink_hrtime t) long time = t; Debug("congestion_control", "failed_at: %ld", time); MUTEX_TRY_LOCK(lock, m_hist_lock, this_ethread()); - if (lock) { + if (lock.is_locked()) { m_history.regist_event(time); if (!m_congested) { int32_t new_congested = compCongested(); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/congest/CongestionDB.cc ---------------------------------------------------------------------- diff --git a/proxy/congest/CongestionDB.cc b/proxy/congest/CongestionDB.cc index f7d505e..4179cc5 100644 --- a/proxy/congest/CongestionDB.cc +++ b/proxy/congest/CongestionDB.cc @@ -177,7 +177,7 @@ CongestionDB::addRecord(uint64_t key, CongestionEntry * pEntry) pEntry->get(); ProxyMutex *bucket_mutex = lock_for_key(key); MUTEX_TRY_LOCK(lock, bucket_mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { RunTodoList(part_num(key)); CongestionEntry *tmp = insert_entry(key, pEntry); if (tmp) @@ -199,7 +199,7 @@ CongestionDB::removeAllRecords() for (int part = 0; part < MT_HASHTABLE_PARTITIONS; part++) { ProxyMutex *bucket_mutex = lock_for_key(part); MUTEX_TRY_LOCK(lock, bucket_mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { RunTodoList(part); tmp = first_entry(part, &it); while (tmp) { @@ -222,7 +222,7 @@ CongestionDB::removeRecord(uint64_t key) CongestionEntry *tmp; ProxyMutex *bucket_mutex = lock_for_key(key); MUTEX_TRY_LOCK(lock, bucket_mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { RunTodoList(part_num(key)); tmp = remove_entry(key); if (tmp) @@ -325,7 +325,7 @@ CongestionDBCont::GC(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) ProxyMutex *bucket_mutex = theCongestionDB->lock_for_key(CDBC_pid); { MUTEX_TRY_LOCK(lock, bucket_mutex, this_ethread()); - if (lock) { + if (lock.is_locked()) { ink_hrtime now = ink_get_hrtime(); now = ink_hrtime_to_sec(now); theCongestionDB->RunTodoList(CDBC_pid); @@ -361,7 +361,7 @@ CongestionDBCont::get_congest_list(int /* event ATS_UNUSED */, Event * e) ProxyMutex *bucket_mutex = theCongestionDB->lock_for_key(CDBC_pid); { MUTEX_TRY_LOCK(lock_bucket, bucket_mutex, this_ethread()); - if (!lock_bucket) { + if (!lock_bucket.is_locked()) { e->schedule_in(SCHEDULE_CONGEST_CONT_INTERVAL); return EVENT_CONT; } else { @@ -400,7 +400,7 @@ CongestionDBCont::get_congest_entry(int /* event ATS_UNUSED */, Event * e) } ProxyMutex *bucket_mutex = theCongestionDB->lock_for_key(CDBC_key); MUTEX_TRY_LOCK(lock_bucket, bucket_mutex, this_ethread()); - if (lock_bucket) { + if (lock_bucket.is_locked()) { theCongestionDB->RunTodoList(theCongestionDB->part_num(CDBC_key)); *CDBC_ppE = theCongestionDB->lookup_entry(CDBC_key); if (*CDBC_ppE != NULL) { @@ -451,7 +451,7 @@ revalidateCongestionDB() bucket_mutex = theCongestionDB->lock_for_key(i); { MUTEX_TRY_LOCK(lock_bucket, bucket_mutex, this_ethread()); - if (lock_bucket) { + if (lock_bucket.is_locked()) { theCongestionDB->RunTodoList(i); theCongestionDB->revalidateBucket(i); } else { @@ -484,7 +484,7 @@ get_congest_entry(Continuation * cont, HttpRequestData * data, CongestionEntry * ProxyMutex *bucket_mutex = theCongestionDB->lock_for_key(key); MUTEX_TRY_LOCK(lock_bucket, bucket_mutex, this_ethread()); - if (lock_bucket) { + if (lock_bucket.is_locked()) { theCongestionDB->RunTodoList(theCongestionDB->part_num(key)); *ppEntry = theCongestionDB->lookup_entry(key); if (*ppEntry != NULL) { @@ -526,7 +526,7 @@ get_congest_list(Continuation * cont, MIOBuffer * buffer, int format) ProxyMutex *bucket_mutex = theCongestionDB->lock_for_key(i); { MUTEX_TRY_LOCK(lock_bucket, bucket_mutex, this_ethread()); - if (lock_bucket) { + if (lock_bucket.is_locked()) { theCongestionDB->RunTodoList(i); char buf[1024]; Iter it; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/53e56ffc/proxy/http/HttpClientSession.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpClientSession.cc b/proxy/http/HttpClientSession.cc index 57991de..e9cb6de 100644 --- a/proxy/http/HttpClientSession.cc +++ b/proxy/http/HttpClientSession.cc @@ -148,7 +148,7 @@ HttpClientSession::new_connection(NetVConnection * new_vc, MIOBuffer * iobuf, IO magic = HTTP_CS_MAGIC_ALIVE; mutex = new_vc->mutex; MUTEX_TRY_LOCK(lock, mutex, this_ethread()); - ink_assert(!!lock); + ink_assert(lock.is_locked()); // Disable hooks for backdoor connections. this->hooks_on = !backdoor;
