Add Spanish translation to gold.
[binutils-gdb.git] / gold / descriptors.cc
index 73c03bf4a457552baafd7e13ba6e9a3b3c3e458c..862edae7fb37dcfe4c1627f9cb06851149f55aa1 100644 (file)
@@ -1,6 +1,6 @@
 // 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.
@@ -75,6 +75,12 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode)
        {
          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;
        }
     }
@@ -114,10 +120,9 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode)
          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();
 
@@ -160,32 +165,15 @@ Descriptors::release(int descriptor, bool permanent)
   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
@@ -213,6 +201,8 @@ Descriptors::close_some_descriptor()
            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;