// descriptors.cc -- manage file descriptors for gold
-// Copyright 2008 Free Software Foundation, Inc.
+// Copyright 2008, 2009 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
{
gold_assert(!pod->inuse);
pod->inuse = true;
+ if (descriptor == this->stack_top_)
+ {
+ this->stack_top_ = pod->stack_next;
+ pod->stack_next = -1;
+ pod->is_on_stack = false;
+ }
return descriptor;
}
}
pod->stack_next = -1;
pod->inuse = true;
pod->is_write = (flags & O_ACCMODE) != O_RDONLY;
+ pod->is_on_stack = false;
- if (!pod->is_claimed)
- ++this->current_;
- pod->is_claimed = false;
+ ++this->current_;
if (this->current_ >= this->limit_)
this->close_some_descriptor();
else
{
pod->inuse = false;
- if (!pod->is_write)
+ if (!pod->is_write && !pod->is_on_stack)
{
pod->stack_next = this->stack_top_;
this->stack_top_ = descriptor;
+ pod->is_on_stack = true;
}
}
}
-// Claim the file descriptor DESCRIPTOR for a plugin. This effectively
-// removes the descriptor from the pool of linker-managed descriptors,
-// as the plugin will assume responsibility for closing it.
-// The IS_CLAIMED flag allows us to recognize when a file descriptor
-// has been reused after being closed by the plugin.
-
-void
-Descriptors::claim_for_plugin(int descriptor)
-{
- Hold_lock hl(*this->lock_);
-
- gold_assert(descriptor >= 0
- && (static_cast<size_t>(descriptor)
- < this->open_descriptors_.size()));
- Open_descriptor* pod = &this->open_descriptors_[descriptor];
- pod->is_claimed = true;
-}
-
// Close some descriptor. The lock is held when this is called. We
// close the descriptor on the top of the free stack. Note that this
// is the opposite of an LRU algorithm--we close the most recently
this->stack_top_ = pod->stack_next;
else
this->open_descriptors_[last].stack_next = pod->stack_next;
+ pod->stack_next = -1;
+ pod->is_on_stack = false;
return true;
}
last = i;