Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleaned up exception handling. changed synchronization to stop using …
…Mutex and start using thread.critical.
- Loading branch information
Showing
5 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
require 'sync' | ||
|
||
|
||
module NewRelic::Agent::Synchronize | ||
|
||
def synchronize_sync(&block) | ||
@_local_sync ||= Sync.new | ||
|
||
@_local_sync.synchronize(:EX) do | ||
block.call | ||
end | ||
end | ||
|
||
|
||
def synchronize_thread | ||
old_val = Thread.critical | ||
|
||
Thread.critical = true | ||
|
||
begin | ||
yield | ||
ensure | ||
Thread.critical = old_val | ||
end | ||
end | ||
|
||
alias synchronize synchronize_thread | ||
alias synchronize_quick synchronize_thread | ||
alias synchronized_long synchronize_sync | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require "socket" | ||
|
||
|
||
class MockHTTPServer | ||
|
||
def initialize | ||
end | ||
|
||
def start(port, &block) | ||
dts = TCPServer.new('localhost', port) | ||
|
||
|
||
|
||
t = Thread.start do | ||
loop do | ||
begin | ||
s = dts.accept | ||
block.call(s) | ||
rescue | ||
ensure | ||
s.close | ||
end | ||
end | ||
|
||
end | ||
t | ||
end | ||
end | ||
|
||
|
||
server = MockHTTPServer.new | ||
|
||
t = server.start(3000) do |s| | ||
|
||
loop do | ||
p s.readline | ||
end | ||
end | ||
|
||
t.join |