Import 2.3.18pre1
[davej-history.git] / include / linux / sched.h
blob6bc7cee4cf4cc4c57a7ca242bc6986794fb13466
1 #ifndef _LINUX_SCHED_H
2 #define _LINUX_SCHED_H
4 #include <asm/param.h> /* for HZ */
6 extern unsigned long event;
8 #include <linux/binfmts.h>
9 #include <linux/personality.h>
10 #include <linux/threads.h>
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/times.h>
14 #include <linux/timex.h>
16 #include <asm/system.h>
17 #include <asm/semaphore.h>
18 #include <asm/page.h>
19 #include <asm/ptrace.h>
21 #include <linux/smp.h>
22 #include <linux/tty.h>
23 #include <linux/sem.h>
24 #include <linux/signal.h>
25 #include <linux/securebits.h>
28 * cloning flags:
30 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
31 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
32 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
33 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
34 #define CLONE_SIGHAND 0x00000800 /* set if signal handlers shared */
35 #define CLONE_PID 0x00001000 /* set if pid shared */
36 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
37 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
38 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
41 * These are the constant used to fake the fixed-point load-average
42 * counting. Some notes:
43 * - 11 bit fractions expand to 22 bits by the multiplies: this gives
44 * a load-average precision of 10 bits integer + 11 bits fractional
45 * - if you want to count load-averages more often, you need more
46 * precision, or rounding will get you. With 2-second counting freq,
47 * the EXP_n values would be 1981, 2034 and 2043 if still using only
48 * 11 bit fractions.
50 extern unsigned long avenrun[]; /* Load averages */
52 #define FSHIFT 11 /* nr of bits of precision */
53 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
54 #define LOAD_FREQ (5*HZ) /* 5 sec intervals */
55 #define EXP_1 1884 /* 1/exp(5sec/1min) as fixed-point */
56 #define EXP_5 2014 /* 1/exp(5sec/5min) */
57 #define EXP_15 2037 /* 1/exp(5sec/15min) */
59 #define CALC_LOAD(load,exp,n) \
60 load *= exp; \
61 load += n*(FIXED_1-exp); \
62 load >>= FSHIFT;
64 #define CT_TO_SECS(x) ((x) / HZ)
65 #define CT_TO_USECS(x) (((x) % HZ) * 1000000/HZ)
67 extern int nr_running, nr_threads;
68 extern int last_pid;
70 #include <linux/fs.h>
71 #include <linux/time.h>
72 #include <linux/param.h>
73 #include <linux/resource.h>
74 #include <linux/timer.h>
76 #include <asm/processor.h>
78 #define TASK_RUNNING 0
79 #define TASK_INTERRUPTIBLE 1
80 #define TASK_UNINTERRUPTIBLE 2
81 #define TASK_ZOMBIE 4
82 #define TASK_STOPPED 8
83 #define TASK_SWAPPING 16
84 #define TASK_EXCLUSIVE 32
86 #define __set_task_state(tsk, state_value) \
87 do { tsk->state = state_value; } while (0)
88 #ifdef __SMP__
89 #define set_task_state(tsk, state_value) \
90 set_mb(tsk->state, state_value)
91 #else
92 #define set_task_state(tsk, state_value) \
93 __set_task_state(tsk, state_value)
94 #endif
96 #define __set_current_state(state_value) \
97 do { current->state = state_value; } while (0)
98 #ifdef __SMP__
99 #define set_current_state(state_value) \
100 set_mb(current->state, state_value)
101 #else
102 #define set_current_state(state_value) \
103 __set_current_state(state_value)
104 #endif
107 * Scheduling policies
109 #define SCHED_OTHER 0
110 #define SCHED_FIFO 1
111 #define SCHED_RR 2
114 * This is an additional bit set when we want to
115 * yield the CPU for one re-schedule..
117 #define SCHED_YIELD 0x10
119 struct sched_param {
120 int sched_priority;
123 #ifndef NULL
124 #define NULL ((void *) 0)
125 #endif
127 #ifdef __KERNEL__
129 #include <linux/spinlock.h>
132 * This serializes "schedule()" and also protects
133 * the run-queue from deletions/modifications (but
134 * _adding_ to the beginning of the run-queue has
135 * a separate lock).
137 extern rwlock_t tasklist_lock;
138 extern spinlock_t runqueue_lock;
140 extern void sched_init(void);
141 extern void init_idle(void);
142 extern void show_state(void);
143 extern void cpu_init (void);
144 extern void trap_init(void);
146 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
147 extern signed long FASTCALL(schedule_timeout(signed long timeout));
148 asmlinkage void schedule(void);
151 * The default fd array needs to be at least BITS_PER_LONG,
152 * as this is the granularity returned by copy_fdset().
154 #define NR_OPEN_DEFAULT BITS_PER_LONG
157 * Open file table structure
159 struct files_struct {
160 atomic_t count;
161 rwlock_t file_lock;
162 int max_fds;
163 int max_fdset;
164 int next_fd;
165 struct file ** fd; /* current fd array */
166 fd_set *close_on_exec;
167 fd_set *open_fds;
168 fd_set close_on_exec_init;
169 fd_set open_fds_init;
170 struct file * fd_array[NR_OPEN_DEFAULT];
173 #define INIT_FILES { \
174 ATOMIC_INIT(1), \
175 RW_LOCK_UNLOCKED, \
176 NR_OPEN_DEFAULT, \
177 __FD_SETSIZE, \
178 0, \
179 &init_files.fd_array[0], \
180 &init_files.close_on_exec_init, \
181 &init_files.open_fds_init, \
182 { { 0, } }, \
183 { { 0, } }, \
184 { NULL, } \
187 struct fs_struct {
188 atomic_t count;
189 int umask;
190 struct dentry * root, * pwd;
193 #define INIT_FS { \
194 ATOMIC_INIT(1), \
195 0022, \
196 NULL, NULL \
199 /* Maximum number of active map areas.. This is a random (large) number */
200 #define MAX_MAP_COUNT (65536)
202 /* Number of map areas at which the AVL tree is activated. This is arbitrary. */
203 #define AVL_MIN_MAP_COUNT 32
205 struct mm_struct {
206 struct vm_area_struct * mmap; /* list of VMAs */
207 struct vm_area_struct * mmap_avl; /* tree of VMAs */
208 struct vm_area_struct * mmap_cache; /* last find_vma result */
209 pgd_t * pgd;
210 atomic_t mm_users; /* How many users with user space? */
211 atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
212 int map_count; /* number of VMAs */
213 struct semaphore mmap_sem;
214 spinlock_t page_table_lock;
215 unsigned long context;
216 unsigned long start_code, end_code, start_data, end_data;
217 unsigned long start_brk, brk, start_stack;
218 unsigned long arg_start, arg_end, env_start, env_end;
219 unsigned long rss, total_vm, locked_vm;
220 unsigned long def_flags;
221 unsigned long cpu_vm_mask;
222 unsigned long swap_cnt; /* number of pages to swap on next pass */
223 unsigned long swap_address;
225 * This is an architecture-specific pointer: the portable
226 * part of Linux does not know about any segments.
228 void * segments;
231 #define INIT_MM(name) { \
232 &init_mmap, NULL, NULL, \
233 swapper_pg_dir, \
234 ATOMIC_INIT(2), ATOMIC_INIT(1), 1, \
235 __MUTEX_INITIALIZER(name.mmap_sem), \
236 SPIN_LOCK_UNLOCKED, \
237 0, \
238 0, 0, 0, 0, \
239 0, 0, 0, \
240 0, 0, 0, 0, \
241 0, 0, 0, \
242 0, 0, 0, 0, NULL }
244 struct signal_struct {
245 atomic_t count;
246 struct k_sigaction action[_NSIG];
247 spinlock_t siglock;
251 #define INIT_SIGNALS { \
252 ATOMIC_INIT(1), \
253 { {{0,}}, }, \
254 SPIN_LOCK_UNLOCKED }
257 * Some day this will be a full-fledged user tracking system..
258 * Right now it is only used to track how many processes a
259 * user has, but it has the potential to track memory usage etc.
261 struct user_struct;
263 struct task_struct {
264 /* these are hardcoded - don't touch */
265 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
266 unsigned long flags; /* per process flags, defined below */
267 int sigpending;
268 mm_segment_t addr_limit; /* thread address space:
269 0-0xBFFFFFFF for user-thead
270 0-0xFFFFFFFF for kernel-thread
272 struct exec_domain *exec_domain;
273 volatile long need_resched;
275 /* various fields */
276 long counter;
277 long priority;
278 cycles_t avg_slice;
279 /* SMP and runqueue state */
280 int has_cpu;
281 int processor;
282 int last_processor;
283 int lock_depth; /* Lock depth. We can context switch in and out of holding a syscall kernel lock... */
284 struct task_struct *next_task, *prev_task;
285 struct list_head run_list;
287 /* task state */
288 struct linux_binfmt *binfmt;
289 int exit_code, exit_signal;
290 int pdeath_signal; /* The signal sent when the parent dies */
291 /* ??? */
292 unsigned long personality;
293 int dumpable:1;
294 int did_exec:1;
295 pid_t pid;
296 pid_t pgrp;
297 pid_t tty_old_pgrp;
298 pid_t session;
299 /* boolean value for session group leader */
300 int leader;
302 * pointers to (original) parent process, youngest child, younger sibling,
303 * older sibling, respectively. (p->father can be replaced with
304 * p->p_pptr->pid)
306 struct task_struct *p_opptr, *p_pptr, *p_cptr, *p_ysptr, *p_osptr;
308 /* PID hash table linkage. */
309 struct task_struct *pidhash_next;
310 struct task_struct **pidhash_pprev;
312 wait_queue_head_t wait_chldexit; /* for wait4() */
313 struct semaphore *vfork_sem; /* for vfork() */
314 unsigned long policy, rt_priority;
315 unsigned long it_real_value, it_prof_value, it_virt_value;
316 unsigned long it_real_incr, it_prof_incr, it_virt_incr;
317 struct timer_list real_timer;
318 struct tms times;
319 unsigned long start_time;
320 long per_cpu_utime[NR_CPUS], per_cpu_stime[NR_CPUS];
321 /* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
322 unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap;
323 int swappable:1;
324 /* process credentials */
325 uid_t uid,euid,suid,fsuid;
326 gid_t gid,egid,sgid,fsgid;
327 int ngroups;
328 gid_t groups[NGROUPS];
329 kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
330 struct user_struct *user;
331 /* limits */
332 struct rlimit rlim[RLIM_NLIMITS];
333 unsigned short used_math;
334 char comm[16];
335 /* file system info */
336 int link_count;
337 struct tty_struct *tty; /* NULL if no tty */
338 /* ipc stuff */
339 struct sem_undo *semundo;
340 struct sem_queue *semsleeping;
341 /* CPU-specific state of this task */
342 struct thread_struct thread;
343 /* filesystem information */
344 struct fs_struct *fs;
345 /* open file information */
346 struct files_struct *files;
348 /* memory management info */
349 struct mm_struct *mm, *active_mm;
351 /* signal handlers */
352 spinlock_t sigmask_lock; /* Protects signal and blocked */
353 struct signal_struct *sig;
354 sigset_t signal, blocked;
355 struct signal_queue *sigqueue, **sigqueue_tail;
356 unsigned long sas_ss_sp;
357 size_t sas_ss_size;
361 * Per process flags
363 #define PF_ALIGNWARN 0x00000001 /* Print alignment warning msgs */
364 /* Not implemented yet, only for 486*/
365 #define PF_STARTING 0x00000002 /* being created */
366 #define PF_EXITING 0x00000004 /* getting shut down */
367 #define PF_PTRACED 0x00000010 /* set if ptrace (0) has been called */
368 #define PF_TRACESYS 0x00000020 /* tracing system calls */
369 #define PF_FORKNOEXEC 0x00000040 /* forked but didn't exec */
370 #define PF_SUPERPRIV 0x00000100 /* used super-user privileges */
371 #define PF_DUMPCORE 0x00000200 /* dumped core */
372 #define PF_SIGNALED 0x00000400 /* killed by a signal */
373 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
374 #define PF_VFORK 0x00001000 /* Wake up parent in mm_release */
376 #define PF_USEDFPU 0x00100000 /* task used FPU this quantum (SMP) */
377 #define PF_DTRACE 0x00200000 /* delayed trace (used on m68k, i386) */
380 * Limit the stack by to some sane default: root can always
381 * increase this limit if needed.. 8MB seems reasonable.
383 #define _STK_LIM (8*1024*1024)
385 #define DEF_PRIORITY (20*HZ/100) /* 200 ms time slices */
388 * INIT_TASK is used to set up the first task table, touch at
389 * your own risk!. Base=0, limit=0x1fffff (=2MB)
391 #define INIT_TASK(name) \
392 /* state etc */ { 0,0,0,KERNEL_DS,&default_exec_domain,0, \
393 /* counter */ DEF_PRIORITY,DEF_PRIORITY,0, \
394 /* SMP */ 0,0,0,-1, \
395 /* schedlink */ &init_task,&init_task, LIST_HEAD_INIT(init_task.run_list), \
396 /* binfmt */ NULL, \
397 /* ec,brk... */ 0,0,0,0,0,0, \
398 /* pid etc.. */ 0,0,0,0,0, \
399 /* proc links*/ &init_task,&init_task,NULL,NULL,NULL, \
400 /* pidhash */ NULL, NULL, \
401 /* chld wait */ __WAIT_QUEUE_HEAD_INITIALIZER(name.wait_chldexit), NULL, \
402 /* timeout */ SCHED_OTHER,0,0,0,0,0,0,0, \
403 /* timer */ { NULL, NULL, 0, 0, it_real_fn }, \
404 /* utime */ {0,0,0,0},0, \
405 /* per CPU times */ {0, }, {0, }, \
406 /* flt */ 0,0,0,0,0,0, \
407 /* swp */ 0, \
408 /* process credentials */ \
409 /* uid etc */ 0,0,0,0,0,0,0,0, \
410 /* suppl grps*/ 0, {0,}, \
411 /* caps */ CAP_INIT_EFF_SET,CAP_INIT_INH_SET,CAP_FULL_SET, \
412 /* user */ NULL, \
413 /* rlimits */ INIT_RLIMITS, \
414 /* math */ 0, \
415 /* comm */ "swapper", \
416 /* fs info */ 0,NULL, \
417 /* ipc */ NULL, NULL, \
418 /* thread */ INIT_THREAD, \
419 /* fs */ &init_fs, \
420 /* files */ &init_files, \
421 /* mm */ NULL, &init_mm, \
422 /* signals */ SPIN_LOCK_UNLOCKED, &init_signals, {{0}}, {{0}}, NULL, &init_task.sigqueue, 0, 0, \
425 #ifndef INIT_TASK_SIZE
426 # define INIT_TASK_SIZE 2048*sizeof(long)
427 #endif
429 union task_union {
430 struct task_struct task;
431 unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
434 extern union task_union init_task_union;
436 extern struct mm_struct init_mm;
437 extern struct task_struct *init_tasks[NR_CPUS];
439 /* PID hashing. (shouldnt this be dynamic?) */
440 #define PIDHASH_SZ (4096 >> 2)
441 extern struct task_struct *pidhash[PIDHASH_SZ];
443 #define pid_hashfn(x) ((((x) >> 8) ^ (x)) & (PIDHASH_SZ - 1))
445 extern __inline__ void hash_pid(struct task_struct *p)
447 struct task_struct **htable = &pidhash[pid_hashfn(p->pid)];
449 if((p->pidhash_next = *htable) != NULL)
450 (*htable)->pidhash_pprev = &p->pidhash_next;
451 *htable = p;
452 p->pidhash_pprev = htable;
455 extern __inline__ void unhash_pid(struct task_struct *p)
457 if(p->pidhash_next)
458 p->pidhash_next->pidhash_pprev = p->pidhash_pprev;
459 *p->pidhash_pprev = p->pidhash_next;
462 extern __inline__ struct task_struct *find_task_by_pid(int pid)
464 struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
466 for(p = *htable; p && p->pid != pid; p = p->pidhash_next)
469 return p;
472 /* per-UID process charging. */
473 extern int alloc_uid(struct task_struct *);
474 void free_uid(struct task_struct *);
476 #include <asm/current.h>
478 extern unsigned long volatile jiffies;
479 extern unsigned long itimer_ticks;
480 extern unsigned long itimer_next;
481 extern struct timeval xtime;
482 extern void do_timer(struct pt_regs *);
484 extern unsigned int * prof_buffer;
485 extern unsigned long prof_len;
486 extern unsigned long prof_shift;
488 #define CURRENT_TIME (xtime.tv_sec)
490 extern void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode));
491 extern void FASTCALL(sleep_on(wait_queue_head_t *q));
492 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
493 signed long timeout));
494 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
495 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
496 signed long timeout));
497 extern void FASTCALL(wake_up_process(struct task_struct * tsk));
499 #define wake_up(x) __wake_up((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE)
500 #define wake_up_interruptible(x) __wake_up((x),TASK_INTERRUPTIBLE)
502 extern int in_group_p(gid_t);
504 extern void flush_signals(struct task_struct *);
505 extern void flush_signal_handlers(struct task_struct *);
506 extern int dequeue_signal(sigset_t *, siginfo_t *);
507 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
508 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
509 extern int kill_pg_info(int, struct siginfo *, pid_t);
510 extern int kill_sl_info(int, struct siginfo *, pid_t);
511 extern int kill_proc_info(int, struct siginfo *, pid_t);
512 extern int kill_something_info(int, struct siginfo *, int);
513 extern void notify_parent(struct task_struct *, int);
514 extern void force_sig(int, struct task_struct *);
515 extern int send_sig(int, struct task_struct *, int);
516 extern int kill_pg(pid_t, int, int);
517 extern int kill_sl(pid_t, int, int);
518 extern int kill_proc(pid_t, int, int);
519 extern int do_sigaction(int, const struct k_sigaction *, struct k_sigaction *);
520 extern int do_sigaltstack(const stack_t *, stack_t *, unsigned long);
522 extern inline int signal_pending(struct task_struct *p)
524 return (p->sigpending != 0);
527 /* Reevaluate whether the task has signals pending delivery.
528 This is required every time the blocked sigset_t changes.
529 All callers should have t->sigmask_lock. */
531 static inline void recalc_sigpending(struct task_struct *t)
533 unsigned long ready;
534 long i;
536 switch (_NSIG_WORDS) {
537 default:
538 for (i = _NSIG_WORDS, ready = 0; --i >= 0 ;)
539 ready |= t->signal.sig[i] &~ t->blocked.sig[i];
540 break;
542 case 4: ready = t->signal.sig[3] &~ t->blocked.sig[3];
543 ready |= t->signal.sig[2] &~ t->blocked.sig[2];
544 ready |= t->signal.sig[1] &~ t->blocked.sig[1];
545 ready |= t->signal.sig[0] &~ t->blocked.sig[0];
546 break;
548 case 2: ready = t->signal.sig[1] &~ t->blocked.sig[1];
549 ready |= t->signal.sig[0] &~ t->blocked.sig[0];
550 break;
552 case 1: ready = t->signal.sig[0] &~ t->blocked.sig[0];
555 t->sigpending = (ready != 0);
558 /* True if we are on the alternate signal stack. */
560 static inline int on_sig_stack(unsigned long sp)
562 return (sp - current->sas_ss_sp < current->sas_ss_size);
565 static inline int sas_ss_flags(unsigned long sp)
567 return (current->sas_ss_size == 0 ? SS_DISABLE
568 : on_sig_stack(sp) ? SS_ONSTACK : 0);
571 extern int request_irq(unsigned int,
572 void (*handler)(int, void *, struct pt_regs *),
573 unsigned long, const char *, void *);
574 extern void free_irq(unsigned int, void *);
577 * This has now become a routine instead of a macro, it sets a flag if
578 * it returns true (to do BSD-style accounting where the process is flagged
579 * if it uses root privs). The implication of this is that you should do
580 * normal permissions checks first, and check suser() last.
582 * [Dec 1997 -- Chris Evans]
583 * For correctness, the above considerations need to be extended to
584 * fsuser(). This is done, along with moving fsuser() checks to be
585 * last.
587 * These will be removed, but in the mean time, when the SECURE_NOROOT
588 * flag is set, uids don't grant privilege.
590 extern inline int suser(void)
592 if (!issecure(SECURE_NOROOT) && current->euid == 0) {
593 current->flags |= PF_SUPERPRIV;
594 return 1;
596 return 0;
599 extern inline int fsuser(void)
601 if (!issecure(SECURE_NOROOT) && current->fsuid == 0) {
602 current->flags |= PF_SUPERPRIV;
603 return 1;
605 return 0;
609 * capable() checks for a particular capability.
610 * New privilege checks should use this interface, rather than suser() or
611 * fsuser(). See include/linux/capability.h for defined capabilities.
614 extern inline int capable(int cap)
616 #if 1 /* ok now */
617 if (cap_raised(current->cap_effective, cap))
618 #else
619 if (cap_is_fs_cap(cap) ? current->fsuid == 0 : current->euid == 0)
620 #endif
622 current->flags |= PF_SUPERPRIV;
623 return 1;
625 return 0;
629 * Routines for handling mm_structs
631 extern struct mm_struct * mm_alloc(void);
633 extern struct mm_struct * start_lazy_tlb(void);
634 extern void end_lazy_tlb(struct mm_struct *mm);
636 /* mmdrop drops the mm and the page tables */
637 extern inline void FASTCALL(__mmdrop(struct mm_struct *));
638 static inline void mmdrop(struct mm_struct * mm)
640 if (atomic_dec_and_test(&mm->mm_count))
641 __mmdrop(mm);
644 /* mmput gets rid of the mappings and all user-space */
645 extern void mmput(struct mm_struct *);
646 /* Remove the current tasks stale references to the old mm_struct */
647 extern void mm_release(void);
650 * Routines for handling the fd arrays
652 extern struct file ** alloc_fd_array(int);
653 extern int expand_fd_array(struct files_struct *, int nr);
654 extern void free_fd_array(struct file **, int);
656 extern fd_set *alloc_fdset(int);
657 extern int expand_fdset(struct files_struct *, int nr);
658 extern void free_fdset(fd_set *, int);
660 /* Expand files. Return <0 on error; 0 nothing done; 1 files expanded,
661 * we may have blocked.
663 * Should be called with the files->file_lock spinlock held for write.
665 static inline int expand_files(struct files_struct *files, int nr)
667 int err, expand = 0;
668 #ifdef FDSET_DEBUG
669 printk (KERN_ERR __FUNCTION__ " %d: nr = %d\n", current->pid, nr);
670 #endif
672 if (nr >= files->max_fdset) {
673 expand = 1;
674 if ((err = expand_fdset(files, nr)))
675 goto out;
677 if (nr >= files->max_fds) {
678 expand = 1;
679 if ((err = expand_fd_array(files, nr)))
680 goto out;
682 err = expand;
683 out:
684 #ifdef FDSET_DEBUG
685 if (err)
686 printk (KERN_ERR __FUNCTION__ " %d: return %d\n", current->pid, err);
687 #endif
688 return err;
691 extern int copy_thread(int, unsigned long, unsigned long, struct task_struct *, struct pt_regs *);
692 extern void flush_thread(void);
693 extern void exit_thread(void);
695 extern void exit_mm(struct task_struct *);
696 extern void exit_fs(struct task_struct *);
697 extern void exit_files(struct task_struct *);
698 extern void exit_sighand(struct task_struct *);
700 extern int do_execve(char *, char **, char **, struct pt_regs *);
701 extern int do_fork(unsigned long, unsigned long, struct pt_regs *);
703 extern inline void add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
705 unsigned long flags;
707 wq_write_lock_irqsave(&q->lock, flags);
708 __add_wait_queue(q, wait);
709 wq_write_unlock_irqrestore(&q->lock, flags);
712 extern inline void add_wait_queue_exclusive(wait_queue_head_t *q,
713 wait_queue_t * wait)
715 unsigned long flags;
717 wq_write_lock_irqsave(&q->lock, flags);
718 __add_wait_queue_tail(q, wait);
719 wq_write_unlock_irqrestore(&q->lock, flags);
722 extern inline void remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait)
724 unsigned long flags;
726 wq_write_lock_irqsave(&q->lock, flags);
727 __remove_wait_queue(q, wait);
728 wq_write_unlock_irqrestore(&q->lock, flags);
731 #define __wait_event(wq, condition) \
732 do { \
733 wait_queue_t __wait; \
734 init_waitqueue_entry(&__wait, current); \
736 add_wait_queue(&wq, &__wait); \
737 for (;;) { \
738 set_current_state(TASK_UNINTERRUPTIBLE); \
739 if (condition) \
740 break; \
741 schedule(); \
743 current->state = TASK_RUNNING; \
744 remove_wait_queue(&wq, &__wait); \
745 } while (0)
747 #define wait_event(wq, condition) \
748 do { \
749 if (condition) \
750 break; \
751 __wait_event(wq, condition); \
752 } while (0)
754 #define __wait_event_interruptible(wq, condition, ret) \
755 do { \
756 wait_queue_t __wait; \
757 init_waitqueue_entry(&__wait, current); \
759 add_wait_queue(&wq, &__wait); \
760 for (;;) { \
761 set_current_state(TASK_INTERRUPTIBLE); \
762 if (condition) \
763 break; \
764 if (!signal_pending(current)) { \
765 schedule(); \
766 continue; \
768 ret = -ERESTARTSYS; \
769 break; \
771 current->state = TASK_RUNNING; \
772 remove_wait_queue(&wq, &__wait); \
773 } while (0)
775 #define wait_event_interruptible(wq, condition) \
776 ({ \
777 int __ret = 0; \
778 if (!(condition)) \
779 __wait_event_interruptible(wq, condition, __ret); \
780 __ret; \
783 #define REMOVE_LINKS(p) do { \
784 (p)->next_task->prev_task = (p)->prev_task; \
785 (p)->prev_task->next_task = (p)->next_task; \
786 if ((p)->p_osptr) \
787 (p)->p_osptr->p_ysptr = (p)->p_ysptr; \
788 if ((p)->p_ysptr) \
789 (p)->p_ysptr->p_osptr = (p)->p_osptr; \
790 else \
791 (p)->p_pptr->p_cptr = (p)->p_osptr; \
792 } while (0)
794 #define SET_LINKS(p) do { \
795 (p)->next_task = &init_task; \
796 (p)->prev_task = init_task.prev_task; \
797 init_task.prev_task->next_task = (p); \
798 init_task.prev_task = (p); \
799 (p)->p_ysptr = NULL; \
800 if (((p)->p_osptr = (p)->p_pptr->p_cptr) != NULL) \
801 (p)->p_osptr->p_ysptr = p; \
802 (p)->p_pptr->p_cptr = p; \
803 } while (0)
805 #define for_each_task(p) \
806 for (p = &init_task ; (p = p->next_task) != &init_task ; )
809 static inline void del_from_runqueue(struct task_struct * p)
811 nr_running--;
812 list_del(&p->run_list);
813 p->run_list.next = NULL;
816 extern inline int task_on_runqueue(struct task_struct *p)
818 return (p->run_list.next != NULL);
821 extern inline void unhash_process(struct task_struct *p)
823 if (task_on_runqueue(p)) BUG();
824 nr_threads--;
825 write_lock_irq(&tasklist_lock);
826 unhash_pid(p);
827 REMOVE_LINKS(p);
828 write_unlock_irq(&tasklist_lock);
831 #endif /* __KERNEL__ */
833 #endif