1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-02-01 01:37:12 +00:00

No need to synchronize the BufferStack with a Mutex

A single BufferStack object is only ever accessed by a single thread.
This is guaranteed by the Logger. Exceptions to the rule are not special
enough to break the rules.
This commit is contained in:
Holger Just 2017-07-25 22:30:47 +02:00
parent c370aecbcd
commit 248a1d558f

View File

@ -5,8 +5,6 @@
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE.txt file for details.
require 'thread'
require 'rackstash/buffer'
module Rackstash
@ -21,7 +19,6 @@ module Rackstash
def initialize(sink)
@sink = sink
@stack = []
@stack_mutex = Mutex.new
end
# Get the current, i.e., latest, top-most, {Buffer} on the internal stack.
@ -30,10 +27,8 @@ module Rackstash
#
# @return [Buffer]
def current
@stack_mutex.synchronize do
@stack.last || Buffer.new(@sink, buffering: false).tap do |buffer|
@stack.push buffer
end
@stack.last || Buffer.new(@sink, buffering: false).tap do |buffer|
@stack.push buffer
end
end
@ -49,9 +44,7 @@ module Rackstash
# @return [Buffer] the newly created buffer
def push(buffer_args = {})
buffer = Buffer.new(sink, buffer_args)
@stack_mutex.synchronize do
@stack.push buffer
end
@stack.push buffer
buffer
end