Permalink
Browse files

No need to use a weak map for fileno to ChannelDescriptor, since in C…

… land unclosed fd's live forever too. Eliminates special need for a hard map for sysopen and weak reference management for all other IOs.
  • Loading branch information...
headius committed Mar 7, 2010
1 parent 878d494 commit 0c012c78053e9ec19ffcdd48231a1141aba544b5
Showing with 2 additions and 31 deletions.
  1. +2 −31 src/org/jruby/Ruby.java
View
@@ -3320,48 +3320,22 @@ public int getFileno() {
}
}
- public Map<Integer, WeakDescriptorReference> getDescriptors() {
- return descriptors;
- }
-
- private void cleanDescriptors() {
- Reference reference;
- while ((reference = descriptorQueue.poll()) != null) {
- int fileno = ((WeakDescriptorReference)reference).getFileno();
- descriptors.remove(fileno);
- }
- }
-
public void registerDescriptor(ChannelDescriptor descriptor, boolean isRetained) {
- cleanDescriptors();
-
Integer filenoKey = descriptor.getFileno();
- descriptors.put(filenoKey, new WeakDescriptorReference(descriptor, descriptorQueue));
- if (isRetained) {
- retainedDescriptors.put(filenoKey, descriptor);
- }
+ retainedDescriptors.put(filenoKey, descriptor);
}
public void registerDescriptor(ChannelDescriptor descriptor) {
registerDescriptor(descriptor,false); // default: don't retain
}
public void unregisterDescriptor(int aFileno) {
- cleanDescriptors();
-
Integer aFilenoKey = aFileno;
- descriptors.remove(aFilenoKey);
retainedDescriptors.remove(aFilenoKey);
}
public ChannelDescriptor getDescriptorByFileno(int aFileno) {
- cleanDescriptors();
-
- Reference reference = descriptors.get(aFileno);
- if (reference == null) {
- return null;
- }
- return (ChannelDescriptor)reference.get();
+ return retainedDescriptors.get(aFileno);
}
public long incrementRandomSeedSequence() {
@@ -3707,9 +3681,6 @@ public Object getHierarchyLock() {
private ObjectSpace objectSpace = new ObjectSpace();
private final RubySymbol.SymbolTable symbolTable = new RubySymbol.SymbolTable(this);
- private Map<Integer, WeakDescriptorReference> descriptors = new ConcurrentHashMap<Integer, WeakDescriptorReference>();
- private ReferenceQueue<ChannelDescriptor> descriptorQueue = new ReferenceQueue<ChannelDescriptor>();
- // ChannelDescriptors opened by sysopen are cached to avoid collection
private Map<Integer, ChannelDescriptor> retainedDescriptors = new ConcurrentHashMap<Integer, ChannelDescriptor>();
private long randomSeed = 0;

0 comments on commit 0c012c7

Please sign in to comment.