Skip to content

RUBY-2495 rework the check_out method #2671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
env:
CI: true
TESTOPTS: "-v"
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
continue-on-error: true
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
os: [ ubuntu-20.04 ]
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1"]
mongodb: ["3.6", "4.4", "5.0"]
topology: [replica_set, sharded_cluster]
Expand Down
1 change: 1 addition & 0 deletions lib/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
require 'mongo/bson'
require 'mongo/semaphore'
require 'mongo/distinguishing_semaphore'
require 'mongo/condition_variable'
require 'mongo/options'
require 'mongo/loggable'
require 'mongo/cluster_time'
Expand Down
58 changes: 58 additions & 0 deletions lib/mongo/condition_variable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true
# encoding: utf-8

# Copyright (C) 2020 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Mongo
# This is an implementation of a condition variable.
#
# @api private
class ConditionVariable
extend Forwardable

def initialize(lock = Mutex.new)
@lock = lock
@cv = ::ConditionVariable.new
end

# Waits for the condition variable to be signaled up to timeout seconds.
# If condition variable is not signaled, returns after timeout seconds.
def wait(timeout = nil)
raise_unless_locked!
return false if timeout && timeout < 0
@cv.wait(@lock, timeout)
end

def broadcast
raise_unless_locked!
@cv.broadcast
end

def signal
raise_unless_locked!
@cv.signal
end

def_delegators :@lock, :synchronize

private

def raise_unless_locked!
unless @lock.owned?
raise ArgumentError, "the lock must be owned when calling this method"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/mongo/distinguishing_semaphore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Mongo
class DistinguishingSemaphore
def initialize
@lock = Mutex.new
@cv = ConditionVariable.new
@cv = ::ConditionVariable.new
@queue = []
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mongo/semaphore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Mongo
class Semaphore
def initialize
@lock = Mutex.new
@cv = ConditionVariable.new
@cv = ::ConditionVariable.new
end

# Waits for the semaphore to be signaled up to timeout seconds.
Expand Down
Loading