summaryrefslogtreecommitdiffstats
path: root/lib/libc_r/uthread/uthread_fork.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc_r/uthread/uthread_fork.c')
-rw-r--r--lib/libc_r/uthread/uthread_fork.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/libc_r/uthread/uthread_fork.c b/lib/libc_r/uthread/uthread_fork.c
index 960c1de..5582c1e 100644
--- a/lib/libc_r/uthread/uthread_fork.c
+++ b/lib/libc_r/uthread/uthread_fork.c
@@ -41,7 +41,7 @@
pid_t
fork(void)
{
- int flags;
+ int i, flags;
pid_t ret;
pthread_t pthread;
pthread_t pthread_next;
@@ -88,6 +88,11 @@ fork(void)
else if (_thread_sys_fcntl(_thread_kern_pipe[1], F_SETFL, flags | O_NONBLOCK) == -1) {
/* Abort this application: */
abort();
+ /* Initialize the ready queue: */
+ } else if (_pq_init(&_readyq, PTHREAD_MIN_PRIORITY,
+ PTHREAD_MAX_PRIORITY) != 0) {
+ /* Abort this application: */
+ PANIC("Cannot allocate priority ready queue.");
} else {
/* Point to the first thread in the list: */
pthread = _thread_link_list;
@@ -119,6 +124,33 @@ fork(void)
/* Point to the next thread: */
pthread = pthread_next;
}
+
+ /* Re-init the waiting queues. */
+ TAILQ_INIT(&_waitingq);
+
+ /* Initialize the scheduling switch hook routine: */
+ _sched_switch_hook = NULL;
+
+ /* Clear out any locks in the file descriptor table: */
+ for (i = 0; i < _thread_dtablesize; i++) {
+ if (_thread_fd_table[i] != NULL) {
+ /* Initialise the file locks: */
+ memset(&_thread_fd_table[i]->lock, 0,
+ sizeof(_thread_fd_table[i]->lock));
+ _thread_fd_table[i]->r_owner = NULL;
+ _thread_fd_table[i]->w_owner = NULL;
+ _thread_fd_table[i]->r_fname = NULL;
+ _thread_fd_table[i]->w_fname = NULL;
+ _thread_fd_table[i]->r_lineno = 0;;
+ _thread_fd_table[i]->w_lineno = 0;;
+ _thread_fd_table[i]->r_lockcount = 0;;
+ _thread_fd_table[i]->w_lockcount = 0;;
+
+ /* Initialise the read/write queues: */
+ _thread_queue_init(&_thread_fd_table[i]->r_queue);
+ _thread_queue_init(&_thread_fd_table[i]->w_queue);
+ }
+ }
}
}
OpenPOWER on IntegriCloud