2002-09-17 Robert Collins <rbtcollins@hotmail.com>
This work inspires by Thomas Pfaff's pthread_fork patch (1). * fork.cc (fork_child): Remove MTinterface fixup call, it's adsorbed by pthread::atforkchild. Rename __pthread_atforkchild to pthread::atforkchild to give access to private members. (fork_parent): Rename __pthread_atforkparent to pthread::atforkparent to give it access to private members. Ditto for __pthread_atforkprepare. * thread.cc: Fix some formatting problems throughout. (MTinterface::fixup_before_fork): Implement. (MTinterface::fixup_after_fork): Fix pthread_keys. (pthread_key::keys): Implement. (pthread_key::fixup_before_fork): Ditto. (pthread_key::fixup_after_fork): Ditto. (pthread_key::pthread_key): Add to pthread_key::keys. (pthread_key::~pthread_key): Remove from pthread_key::keys. (pthread_key::saveKeyToBuffer): Implement. (pthread_key::recreateKeyFromBuffer): Ditto. (pthread::atforkprepare): Prepare all MT classes for fork. (pthread::atforkchild): And fix them up afterwards. * thread.h (pthread_key): Buffer the key value during fork in fork_buf. List the keys needing to be fixed up in a linked list with head pthread_key::keys. (pthread): Move atfork cygwin internal calls into the class. (MTInterface): Provide a fixup_before_fork for objecst that need to save state. (__pthread_atforkprepare): Remove. (__pthread_atforkparent): Remove. (__pthread_atforkchild): Remove.
This commit is contained in:
@@ -178,11 +178,21 @@ class pthread_key:public verifyable_object
|
||||
public:
|
||||
|
||||
DWORD dwTlsIndex;
|
||||
void *fork_buf;
|
||||
class pthread_key *next;
|
||||
|
||||
int set (const void *);
|
||||
void *get ();
|
||||
|
||||
pthread_key (void (*)(void *));
|
||||
~pthread_key ();
|
||||
static void fixup_before_fork();
|
||||
static void fixup_after_fork();
|
||||
private:
|
||||
// lists of objects. USE THREADSAFE INSERTS AND DELETES.
|
||||
static pthread_key * keys;
|
||||
void saveKeyToBuffer ();
|
||||
void recreateKeyFromBuffer ();
|
||||
};
|
||||
|
||||
/* FIXME: test using multiple inheritance and merging key_destructor into pthread_key
|
||||
@@ -281,6 +291,9 @@ public:
|
||||
|
||||
static void initMainThread(pthread *, HANDLE);
|
||||
static bool isGoodObject(pthread_t *);
|
||||
static void atforkprepare();
|
||||
static void atforkparent();
|
||||
static void atforkchild();
|
||||
|
||||
virtual void exit (void *value_ptr);
|
||||
|
||||
@@ -421,12 +434,13 @@ public:
|
||||
callback *pthread_child;
|
||||
callback *pthread_parent;
|
||||
|
||||
// list of mutex's. USE THREADSAFE INSERTS AND DELETES.
|
||||
// lists of pthread objects. USE THREADSAFE INSERTS AND DELETES.
|
||||
class pthread_mutex * mutexs;
|
||||
class pthread_cond * conds;
|
||||
class semaphore * semaphores;
|
||||
|
||||
void Init (int);
|
||||
void fixup_before_fork (void);
|
||||
void fixup_after_fork (void);
|
||||
|
||||
MTinterface ():reent_index (0), indexallocated (0), threadcount (1)
|
||||
@@ -437,10 +451,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void __pthread_atforkprepare(void);
|
||||
void __pthread_atforkparent(void);
|
||||
void __pthread_atforkchild(void);
|
||||
|
||||
/* Cancellation */
|
||||
int __pthread_cancel (pthread_t thread);
|
||||
|
||||
|
Reference in New Issue
Block a user