diff options
author | bje <bje> | 1998-07-22 09:09:24 +0000 |
---|---|---|
committer | bje <bje> | 1998-07-22 09:09:24 +0000 |
commit | c9b8e5d0d1c38c48570be14216112201158503da (patch) | |
tree | ccdeed11b64ff0e7aa4541139f063a7e40b80cb1 | |
parent | 0884b3d61a65fbec11f5fdae262af335e0c46869 (diff) |
1998-07-22 Ben Elliston <bje@cygnus.com>
* pthread.h (pthread_atfork): Add function prototype.
* fork.c (pthread_atfork): Preliminary implementation.
(_pthread_fork): Likewise.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | fork.c | 64 | ||||
-rw-r--r-- | pthread.h | 4 |
3 files changed, 75 insertions, 0 deletions
@@ -1,3 +1,10 @@ +1998-07-22 Ben Elliston <bje@cygnus.com> + + * pthread.h (pthread_atfork): Add function prototype. + + * fork.c (pthread_atfork): Preliminary implementation. + (_pthread_fork): Likewise. + Wed Jul 22 00:16:22 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * cleanup.c (_pthread_cleanup_push): Implement. @@ -0,0 +1,64 @@ +/* + * fork.c + * + * Description: + * Implementation of fork() for POSIX threads. + */ + +int +pthread_atfork(void (*prepare)(void), + void (*parent)(void), + void (*child)(void)) +{ + /* Push handlers (unless NULL) onto their respective stacks. */ + + if (prepare != NULL) + { + /* Push prepare. */ + /* If push fails, return ENOMEM. */ + } + + if (parent != NULL) + { + /* Push parent. */ + /* If push fails, return ENOMEM. */ + } + + if (child != NULL) + { + /* Push child. */ + /* If push fails, return ENOMEM. */ + } + + /* Everything is okay. */ + return 0; +} + +/* It looks like the GNU linker is capable of selecting this version of + fork() over a version provided in more primitive libraries further down + the linker command line. */ + +pid_t +fork() +{ + pid_t pid; + + /* Pop prepare handlers here. */ + + /* Now call Cygwin32's fork(). */ + + if ((pid = _fork()) > 0) + { + /* Pop parent handlers. */ + return pid; + } + else + { + /* Pop child handlers. */ + /* Terminate all threads except pthread_self() using + pthread_cancel(). */ + return 0; + } + + /* Not reached. */ +} @@ -51,6 +51,10 @@ typedef struct { extern "C" { #endif /* __cplusplus */ +int pthread_atfork (void (*prepare)(void), + void (*parent)(void), + void (*child)(void)); + int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void * (*start_routine) (void *), |