File: synchronized_map_backend.rb

package info (click to toggle)
ruby-concurrent 1.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,136 kB
  • sloc: ruby: 30,875; java: 6,128; ansic: 265; makefile: 26; sh: 19
file content (85 lines) | stat: -rw-r--r-- 1,700 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require 'concurrent/collection/map/non_concurrent_map_backend'

module Concurrent

  # @!visibility private
  module Collection

    # @!visibility private
    class SynchronizedMapBackend < NonConcurrentMapBackend

      def initialize(*args, &block)
        super

        # WARNING: Mutex is a non-reentrant lock, so the synchronized methods are
        # not allowed to call each other.
        @mutex = Mutex.new
      end

      def [](key)
        @mutex.synchronize { super }
      end

      def []=(key, value)
        @mutex.synchronize { super }
      end

      def compute_if_absent(key)
        @mutex.synchronize { super }
      end

      def compute_if_present(key)
        @mutex.synchronize { super }
      end

      def compute(key)
        @mutex.synchronize { super }
      end

      def merge_pair(key, value)
        @mutex.synchronize { super }
      end

      def replace_pair(key, old_value, new_value)
        @mutex.synchronize { super }
      end

      def replace_if_exists(key, new_value)
        @mutex.synchronize { super }
      end

      def get_and_set(key, value)
        @mutex.synchronize { super }
      end

      def key?(key)
        @mutex.synchronize { super }
      end

      def delete(key)
        @mutex.synchronize { super }
      end

      def delete_pair(key, value)
        @mutex.synchronize { super }
      end

      def clear
        @mutex.synchronize { super }
      end

      def size
        @mutex.synchronize { super }
      end

      def get_or_default(key, default_value)
        @mutex.synchronize { super }
      end

      private
      def dupped_backend
        @mutex.synchronize { super }
      end
    end
  end
end