Skip to content

Commit

Permalink
MB-36610: Use runInEventBaseThread for release()
Browse files Browse the repository at this point in the history
The release method of the server API may use the functionality
provided by the runInEventBaseThread to make sure it runs in
the right context and won't race with the connection.

Change-Id: Ic0b1a4c024f7e3a10de1e7e502063bec00a3023a
Reviewed-on: http://review.couchbase.org/c/kv_engine/+/148534
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Trond Norbye <trond.norbye@couchbase.com>
  • Loading branch information
trondn authored and daverigby committed May 25, 2021
1 parent c0d64ae commit 141bf2e
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions daemon/server_api.cc
Expand Up @@ -186,23 +186,14 @@ struct ServerCookieApi : public ServerCookieIface {
void release(gsl::not_null<const void*> void_cookie) override {
auto& cookie = getCookie(void_cookie);
auto& connection = cookie.getConnection();
auto& thr = connection.getThread();

TRACE_LOCKGUARD_TIMED(thr.mutex,
"mutex",
"release_cookie::threadLock",
SlowMutexThreshold);

// Releasing the reference to the object may cause it to change
// state. (NOTE: the release call shall never be called from the
// worker threads), so put the connection in the pool of pending
// IO and have the system retry the operation for the connection
cookie.decrementRefcount();

// kick the thread in the butt
if (thr.notification.push(&connection)) {
notify_thread(thr);
}
connection.getThread().eventBase.runInEventBaseThread([&cookie]() {
TRACE_LOCKGUARD_TIMED(cookie.getConnection().getThread().mutex,
"mutex",
"release",
SlowMutexThreshold);
cookie.decrementRefcount();
cookie.getConnection().triggerCallback();
});
}

void set_priority(gsl::not_null<const void*> cookie,
Expand Down

0 comments on commit 141bf2e

Please sign in to comment.