Subversion Repositories HelenOS

Rev

Rev 2080 | Rev 2093 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2001-2004 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup genericproc
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #ifndef KERN_THREAD_H_
  36. #define KERN_THREAD_H_
  37.  
  38. #include <synch/waitq.h>
  39. #include <proc/task.h>
  40. #include <cpu.h>
  41. #include <synch/rwlock.h>
  42. #include <adt/btree.h>
  43. #include <mm/slab.h>
  44. #include <arch/cpu.h>
  45. #include <mm/tlb.h>
  46. #include <proc/uarg.h>
  47.  
  48. #define THREAD_STACK_SIZE   STACK_SIZE
  49.  
  50. extern char *thread_states[];
  51.  
  52. /* Thread flags */
  53. #define THREAD_FLAG_WIRED   (1 << 0)    /**< Thread cannot be migrated to another CPU. */
  54. #define THREAD_FLAG_STOLEN  (1 << 1)    /**< Thread was migrated to another CPU and has not run yet. */
  55. #define THREAD_FLAG_USPACE  (1 << 2)    /**< Thread executes in userspace. */
  56.  
  57. /** Thread list lock.
  58.  *
  59.  * This lock protects all link_t structures chained in threads_head.
  60.  * Must be acquired before T.lock for each T of type thread_t.
  61.  *
  62.  */
  63. extern spinlock_t threads_lock;
  64.  
  65. extern btree_t threads_btree;           /**< B+tree containing all threads. */
  66.  
  67. extern void thread_init(void);
  68. extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, int flags, char *name, bool uncounted);
  69. extern void thread_ready(thread_t *t);
  70. extern void thread_exit(void) __attribute__((noreturn));
  71.  
  72. #ifndef thread_create_arch
  73. extern void thread_create_arch(thread_t *t);
  74. #endif
  75. #ifndef thr_constructor_arch
  76. extern void thr_constructor_arch(thread_t *t);
  77. #endif
  78. #ifndef thr_destructor_arch
  79. extern void thr_destructor_arch(thread_t *t);
  80. #endif
  81.  
  82. extern void thread_sleep(uint32_t sec);
  83. extern void thread_usleep(uint32_t usec);
  84.  
  85. #define thread_join(t)  thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
  86. extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags);
  87. extern void thread_detach(thread_t *t);
  88.  
  89. extern void thread_register_call_me(void (* call_me)(void *), void *call_me_with);
  90. extern void thread_print_list(void);
  91. extern void thread_destroy(thread_t *t);
  92. extern void thread_update_accounting(void);
  93. extern bool thread_exists(thread_t *t);
  94. extern void thread_interrupt_sleep(thread_t *t);
  95.  
  96. /* Fpu context slab cache */
  97. extern slab_cache_t *fpu_context_slab;
  98.  
  99. /** Thread syscall prototypes. */
  100. unative_t sys_thread_create(uspace_arg_t *uspace_uarg, char *uspace_name);
  101. unative_t sys_thread_exit(int uspace_status);
  102.  
  103. #endif
  104.  
  105. /** @}
  106.  */
  107.