Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hotmail.com>2002-09-21 05:59:46 +0400
committerRobert Collins <rbtcollins@hotmail.com>2002-09-21 05:59:46 +0400
commit20b94ee904e42c78f54dafa6b7638c2299e07a63 (patch)
tree36f904afbd7c131cf3c339998de264629d6981dc
parent8b1978c30ca6234e06596ef51fd68d98fcfa6aed (diff)
2002-09-21 Robert Collins <rbtcollins@hotmail.com>
* thread.cc: Partial refactoring of pthread_key destructor handling. Loosely based on Thomas Pfaff's work. (pthread_key_destructor_list::Insert): Remove. (pthread_key_destructor_list::Pop): Remove. (pthread_key_destructor_list::IterateNull): Call the key's run_destructor method. (pthread_key::pthread_key): Initialize new member. (pthread_key::get): Mark as const for correctness. (pthread_key::run_destructor): Implement. * thread.h (pthread_key::get): Mark as const for correctness. (pthread_key::run_destructor): Declare. (List): New template class that implements a generic list. (pthread_key_destructor_list): Inherit from List, and remove now duplicate functions.
-rw-r--r--winsup/cygwin/ChangeLog17
-rw-r--r--winsup/cygwin/thread.cc32
-rw-r--r--winsup/cygwin/thread.h60
3 files changed, 76 insertions, 33 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index ef9a7868e..5f03faf10 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,22 @@
2002-09-21 Robert Collins <rbtcollins@hotmail.com>
+ * thread.cc: Partial refactoring of pthread_key destructor
+ handling. Loosely based on Thomas Pfaff's work.
+ (pthread_key_destructor_list::Insert): Remove.
+ (pthread_key_destructor_list::Pop): Remove.
+ (pthread_key_destructor_list::IterateNull): Call the key's
+ run_destructor method.
+ (pthread_key::pthread_key): Initialize new member.
+ (pthread_key::get): Mark as const for correctness.
+ (pthread_key::run_destructor): Implement.
+ * thread.h (pthread_key::get): Mark as const for correctness.
+ (pthread_key::run_destructor): Declare.
+ (List): New template class that implements a generic list.
+ (pthread_key_destructor_list): Inherit from List, and remove
+ now duplicate functions.
+
+2002-09-21 Robert Collins <rbtcollins@hotmail.com>
+
* thread.cc: Change verifyable_object_isvalid calls with
PTHREAD_CONDATTR_MAGIC, PTHREAD_MUTEXATTR_MAGIC, PTHREAD_COND_MAGIC,
SEM_MAGIC to objecttype::isGoodObject() calls throughout.
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 3d64d69b6..1683b21c0 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -73,16 +73,6 @@ pthread_key_destructor::Next ()
return next;
}
-void
-pthread_key_destructor_list::Insert (pthread_key_destructor *node)
-{
- if (!node)
- return;
- head = node->InsertAfter (head);
- if (!head)
- head = node; /*first node special case */
-}
-
/*remove a given dataitem, wherever in the list it is */
pthread_key_destructor *
pthread_key_destructor_list::Remove (pthread_key *key)
@@ -103,15 +93,6 @@ pthread_key_destructor_list::Remove (pthread_key *key)
return NULL;
}
- /*get the first item and remove at the same time */
-pthread_key_destructor *
-pthread_key_destructor_list::Pop ()
-{
- pthread_key_destructor *temp = head;
- head = head->Next ();
- return temp;
-}
-
pthread_key_destructor::
pthread_key_destructor (void (*thedestructor) (void *), pthread_key *key)
{
@@ -126,7 +107,7 @@ pthread_key_destructor_list::IterateNull ()
pthread_key_destructor *temp = head;
while (temp)
{
- temp->destructor ((temp->key)->get ());
+ temp->key->run_destructor ();
temp = temp->Next ();
}
}
@@ -1056,7 +1037,7 @@ pthread_key::isGoodObject (pthread_key_t const *key)
/* non-static members */
-pthread_key::pthread_key (void (*destructor) (void *)):verifyable_object (PTHREAD_KEY_MAGIC)
+pthread_key::pthread_key (void (*aDestructor) (void *)):verifyable_object (PTHREAD_KEY_MAGIC), destructor (aDestructor)
{
dwTlsIndex = TlsAlloc ();
if (dwTlsIndex == TLS_OUT_OF_INDEXES)
@@ -1098,7 +1079,7 @@ pthread_key::set (const void *value)
}
void *
-pthread_key::get ()
+pthread_key::get () const
{
int savedError = ::GetLastError();
void *result = TlsGetValue (dwTlsIndex);
@@ -1121,6 +1102,13 @@ pthread_key::recreateKeyFromBuffer ()
set (fork_buf);
}
+void
+pthread_key::run_destructor () const
+{
+ if (destructor)
+ destructor (get());
+}
+
/*pshared mutexs:
* REMOVED FROM CURRENT. These can be reinstated with the daemon, when all the
diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
index ad4208f5d..05bf9793c 100644
--- a/winsup/cygwin/thread.h
+++ b/winsup/cygwin/thread.h
@@ -183,9 +183,10 @@ public:
class pthread_key *next;
int set (const void *);
- void *get ();
+ void *get () const;
+ void run_destructor () const;
- pthread_key (void (*)(void *));
+ pthread_key (void (*)(void *));
~pthread_key ();
static void fixup_before_fork();
static void fixup_after_fork();
@@ -194,8 +195,53 @@ private:
static pthread_key * keys;
void saveKeyToBuffer ();
void recreateKeyFromBuffer ();
+ void (*destructor) (void *);
};
+/* interface */
+template <class ListNode> class List {
+public:
+ void Insert (ListNode *aNode);
+ ListNode *Remove ( ListNode *aNode);
+ ListNode *Pop ();
+protected:
+ ListNode *head;
+};
+/* implementation */
+template <class ListNode> void
+List<ListNode>::Insert (ListNode *aNode)
+{
+ if (!aNode)
+ return;
+ head = aNode->InsertAfter (head);
+ if (!head)
+ head = aNode; /*first node special case */
+}
+template <class ListNode> ListNode *
+List<ListNode>::Remove ( ListNode *aNode)
+{
+ if (!aNode)
+ return NULL;
+ if (!head)
+ return NULL;
+ if (aNode == head)
+ return Pop ();
+ ListNode *resultPrev = head;
+ while (resultPrev && resultPrev->Next() && !(aNode == resultPrev->Next()))
+ resultPrev = resultprev->Next();
+ if (resultPrev)
+ return resultPrev->UnlinkNext ();
+ return NULL;
+}
+template <class ListNode> ListNode *
+List<ListNode>::Pop ()
+{
+ ListNode *result = head;
+ head = head->Next();
+ return result;
+}
+
+
/* FIXME: test using multiple inheritance and merging key_destructor into pthread_key
* for efficiency */
class pthread_key_destructor
@@ -211,21 +257,13 @@ public:
pthread_key *key;
};
-class pthread_key_destructor_list
+class pthread_key_destructor_list : public List<pthread_key_destructor>
{
public:
- void Insert (pthread_key_destructor * node);
-/* remove a given dataitem, wherever in the list it is */
- pthread_key_destructor *Remove (pthread_key_destructor * item);
-/* get the first item and remove at the same time */
- pthread_key_destructor *Pop ();
pthread_key_destructor *Remove (pthread_key * key);
void IterateNull ();
-private:
- pthread_key_destructor * head;
};
-
class pthread_attr:public verifyable_object
{
public: