/[rtmk]/rtmk/task.c
ViewVC logotype

Diff of /rtmk/task.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by jrydberg, Tue Feb 5 20:45:32 2002 UTC revision 1.6 by jrydberg, Wed Feb 20 20:04:42 2002 UTC
# Line 46  task_create (struct task *parent_task, b Line 46  task_create (struct task *parent_task, b
46    
47    new_task = kmem_cache_alloc (task_cache);    new_task = kmem_cache_alloc (task_cache);
48    assert (new_task);    assert (new_task);
49      new_task->ref_cnt = 1;
   /* One reference for just being alive; one for the caller.  */  
   
   new_task->ref_cnt = 2;  
50    
51    /* Create memory map for task. */    /* Create memory map for task. */
   
52    if (inherit_memory_p)    if (inherit_memory_p)
53      new_task->map = vm_map_fork (parent_task->map);      new_task->map = vm_map_fork (parent_task->map);
54    else    else
# Line 79  task_create (struct task *parent_task, b Line 75  task_create (struct task *parent_task, b
75    return KERN_SUCCESS;    return KERN_SUCCESS;
76  }  }
77    
78  /* Terminate TASK and release all resources held by it.  */  /* Obtain reference to TASK.  */
79    void
80    task_reference (struct task *task)
81    {
82      task->ref_cnt++;
83    }
84    
85    /* Deallocate a reference to TASK.  If reference counter drops to
86       zero we release all resources held by task.  */
87    void
88    task_deallocate (struct task *task)
89    {
90      if (--task->ref_cnt != 0)
91        return;
92    
93      trace_printf ("implement task_deallocate");
94    }
95    
96    /* Terminate TASK and release all resources held by it.  
97       We loop through all threads in the task and terminate them.
98       (special case for current thread).   When they are deallocated
99       by the reaper thread, they will release their refernece to the
100       task.  When all threads are deallocated, so are the task.  */
101  kern_return_t  kern_return_t
102  task_terminate (struct task *task)  task_terminate (struct task *task)
103  {  {
104    panic ("task panic");    struct thread *self = THREAD_CURRENT (), *thread;
105      int zombify_p = 0;
106    
107      queue_iterate (& task->thread_list, thread, struct thread *, taskq)
108        {
109          if (thread != self)
110            thread_terminate (thread);
111          else
112            zombify_p = 1;
113        }
114    
115      /* Release our reference to the task.  */
116      task_deallocate (task);
117      
118      if (zombify_p)
119        thread_terminate (self);
120      return 0;
121  }  }
122    
123  void  void
124  task_init (void)  task_init (void)
125  {  {
   kern_return_t err;  
   
126    task_cache = kmem_cache_create ("task cache", sizeof (struct task), 0);    task_cache = kmem_cache_create ("task cache", sizeof (struct task), 0);
127    assert (task_cache);    assert (task_cache);
128    
129    /* We create the kernel task - and replace the memory map with VM_MAP_KERNEL. */    /* We can not use ``task_create'' to allocate our kernel task
130         -- since it uses TASK_KERNEL().  We have to do it manually.  */
131    
132    err = task_create (0, 0, &task_kernel);    task_kernel = kmem_cache_alloc (task_cache);
133    assert (err == KERN_SUCCESS);    memset (task_kernel, 0, sizeof (struct task));
134    
   /* ??? deallocate previous map.  */  
135    task_kernel->map = VM_MAP_KERNEL ();    task_kernel->map = VM_MAP_KERNEL ();
136      task_kernel->ref_cnt = 2;
137      queue_init (&task_kernel->thread_list);
138      task_kernel->ipc_object = ipc_object_create ();
139  }  }
140    
141  /* Task for returning name of send right to task in tasks IPC object.  */  /* Task for returning name of send right to task in tasks IPC object.  */

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26