Sha256: d694eae61760bcc115f8fb903822e23394d8a198a6bcedee17af8e638fc31808

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require_relative '../fuse_context'

module FFI
  module Libfuse
    module Adapter
      # Injects a wrapper via #{FuseCallbacks#fuse_wrappers} make the current {FuseContext} object available to
      #  callbacks (except :destroy) via thread local variable :fuse_context
      module ThreadLocalContext
        # @!visibility private
        def fuse_wrappers(*wrappers)
          wrappers.unshift(
            {
              wrapper: proc { |_fm, *args, **_, &b| self.class.thread_local_context(*args, &b) },
              excludes: %i[destroy]
            }
          )
          return wrappers unless defined?(super)

          super(*wrappers)
        end

        module_function

        # Stores {FuseContext} in thread local variable :fuse_context before yielding
        def thread_local_context(*args)
          Thread.current[:fuse_context] = FuseContext.get
          yield(*args)
        ensure
          Thread.current[:fuse_context] = nil
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-libfuse-0.0.1.rctest12 lib/ffi/libfuse/adapter/thread_local_context.rb
ffi-libfuse-0.0.1.rctest11 lib/ffi/libfuse/adapter/thread_local_context.rb
ffi-libfuse-0.0.1.pre lib/ffi/libfuse/adapter/thread_local_context.rb