Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/thread.h

    r7faabb7 rdf58e44  
    4040#include <time/timeout.h>
    4141#include <cpu.h>
    42 #include <synch/rwlock.h>
    4342#include <synch/spinlock.h>
    4443#include <adt/avl.h>
     
    4847#include <proc/uarg.h>
    4948#include <udebug/udebug.h>
    50 
    51 #define THREAD_STACK_SIZE       STACK_SIZE
    52 #define THREAD_NAME_BUFLEN      20
    53 
    54 extern char *thread_states[];
     49#include <sysinfo/abi.h>
     50
     51#define THREAD_STACK_SIZE   STACK_SIZE
     52#define THREAD_NAME_BUFLEN  20
     53
     54extern const char *thread_states[];
    5555
    5656/* Thread flags */
     
    6060 * When using this flag, the caller must set cpu in the thread_t
    6161 * structure manually before calling thread_ready (even on uniprocessor).
    62  */
    63 #define THREAD_FLAG_WIRED       (1 << 0)
     62 *
     63 */
     64#define THREAD_FLAG_WIRED  (1 << 0)
     65
    6466/** Thread was migrated to another CPU and has not run yet. */
    65 #define THREAD_FLAG_STOLEN      (1 << 1)
     67#define THREAD_FLAG_STOLEN  (1 << 1)
     68
    6669/** Thread executes in userspace. */
    67 #define THREAD_FLAG_USPACE      (1 << 2)
     70#define THREAD_FLAG_USPACE  (1 << 2)
     71
    6872/** Thread will be attached by the caller. */
    69 #define THREAD_FLAG_NOATTACH    (1 << 3)
    70 
    71 /** Thread states. */
    72 typedef enum {
    73         /** It is an error, if thread is found in this state. */
    74         Invalid,
    75         /** State of a thread that is currently executing on some CPU. */
    76         Running,
    77         /** Thread in this state is waiting for an event. */
    78         Sleeping,
    79         /** State of threads in a run queue. */
    80         Ready,
    81         /** Threads are in this state before they are first readied. */
    82         Entering,
    83         /** After a thread calls thread_exit(), it is put into Exiting state. */
    84         Exiting,
    85         /** Threads that were not detached but exited are Lingering. */
    86         Lingering
    87 } state_t;
     73#define THREAD_FLAG_NOATTACH  (1 << 3)
    8874
    8975/** Thread structure. There is one per thread. */
    9076typedef struct thread {
    91         link_t rq_link;         /**< Run queue link. */
    92         link_t wq_link;         /**< Wait queue link. */
    93         link_t th_link;         /**< Links to threads within containing task. */
    94 
     77        link_t rq_link;  /**< Run queue link. */
     78        link_t wq_link;  /**< Wait queue link. */
     79        link_t th_link;  /**< Links to threads within containing task. */
     80       
    9581        /** Threads linkage to the threads_tree. */
    9682        avltree_node_t threads_tree_node;
     
    10086         * Protects the whole thread structure except list links above.
    10187         */
    102         SPINLOCK_DECLARE(lock);
    103 
     88        IRQ_SPINLOCK_DECLARE(lock);
     89       
    10490        char name[THREAD_NAME_BUFLEN];
    105 
     91       
    10692        /** Function implementing the thread. */
    107         void (* thread_code)(void *);
     93        void (*thread_code)(void *);
    10894        /** Argument passed to thread_code() function. */
    10995        void *thread_arg;
    110 
    111         /**
    112          * From here, the stored context is restored when the thread is
    113          * scheduled.
     96       
     97        /**
     98         * From here, the stored context is restored
     99         * when the thread is scheduled.
    114100         */
    115101        context_t saved_context;
    116         /**
    117          * From here, the stored timeout context is restored when sleep times
    118          * out.
     102       
     103        /**
     104         * From here, the stored timeout context
     105         * is restored when sleep times out.
    119106         */
    120107        context_t sleep_timeout_context;
    121         /**
    122          * From here, the stored interruption context is restored when sleep is
    123          * interrupted.
     108       
     109        /**
     110         * From here, the stored interruption context
     111         * is restored when sleep is interrupted.
    124112         */
    125113        context_t sleep_interruption_context;
    126 
     114       
    127115        /** If true, the thread can be interrupted from sleep. */
    128116        bool sleep_interruptible;
     
    132120        timeout_t sleep_timeout;
    133121        /** Flag signalling sleep timeout in progress. */
    134         volatile int timeout_pending;
    135 
     122        volatile bool timeout_pending;
     123       
    136124        /**
    137125         * True if this thread is executing copy_from_uspace().
     
    139127         */
    140128        bool in_copy_from_uspace;
     129       
    141130        /**
    142131         * True if this thread is executing copy_to_uspace().
     
    149138         * thread_exit() before returning to userspace.
    150139         */
    151         bool interrupted;                       
     140        bool interrupted;
     141       
     142        /**
     143         * If true, the scheduler will print a stack trace
     144         * to the kernel console upon scheduling this thread.
     145         */
     146        bool btrace;
    152147       
    153148        /** If true, thread_join_timeout() cannot be used on this thread. */
     
    157152        /** Link used in the joiner_head list. */
    158153        link_t joiner_link;
    159 
     154       
    160155        fpu_context_t *saved_fpu_context;
    161156        int fpu_context_exists;
    162 
     157       
    163158        /*
    164159         * Defined only if thread doesn't run.
     
    167162         */
    168163        int fpu_context_engaged;
    169 
    170         rwlock_type_t rwlock_holder_type;
    171 
    172         /** Callback fired in scheduler before the thread is put asleep. */
    173         void (* call_me)(void *);
    174         /** Argument passed to call_me(). */
    175         void *call_me_with;
    176 
     164       
    177165        /** Thread's state. */
    178166        state_t state;
    179167        /** Thread's flags. */
    180         int flags;
     168        unsigned int flags;
    181169       
    182170        /** Thread's CPU. */
     
    184172        /** Containing task. */
    185173        task_t *task;
    186 
     174       
    187175        /** Ticks before preemption. */
    188176        uint64_t ticks;
    189177       
    190178        /** Thread accounting. */
    191         uint64_t cycles;
     179        uint64_t ucycles;
     180        uint64_t kcycles;
    192181        /** Last sampled cycle. */
    193182        uint64_t last_cycle;
    194         /** Thread doesn't affect accumulated accounting. */   
     183        /** Thread doesn't affect accumulated accounting. */
    195184        bool uncounted;
    196 
     185       
    197186        /** Thread's priority. Implemented as index to CPU->rq */
    198187        int priority;
     
    202191        /** Architecture-specific data. */
    203192        thread_arch_t arch;
    204 
     193       
    205194        /** Thread's kernel stack. */
    206195        uint8_t *kstack;
    207 
     196       
    208197#ifdef CONFIG_UDEBUG
    209198        /** Debugging stuff */
    210199        udebug_thread_t udebug;
    211 #endif
    212 
     200#endif /* CONFIG_UDEBUG */
    213201} thread_t;
    214202
     
    219207 *
    220208 */
    221 SPINLOCK_EXTERN(threads_lock);
     209IRQ_SPINLOCK_EXTERN(threads_lock);
    222210
    223211/** AVL tree containing all threads. */
     
    225213
    226214extern void thread_init(void);
    227 extern thread_t *thread_create(void (* func)(void *), void *arg, task_t *task,
    228     int flags, char *name, bool uncounted);
    229 extern void thread_attach(thread_t *t, task_t *task);
    230 extern void thread_ready(thread_t *t);
     215extern thread_t *thread_create(void (*)(void *), void *, task_t *,
     216    unsigned int, const char *, bool);
     217extern void thread_attach(thread_t *, task_t *);
     218extern void thread_ready(thread_t *);
    231219extern void thread_exit(void) __attribute__((noreturn));
    232220
    233221#ifndef thread_create_arch
    234 extern void thread_create_arch(thread_t *t);
    235 #endif
     222extern void thread_create_arch(thread_t *);
     223#endif
     224
    236225#ifndef thr_constructor_arch
    237 extern void thr_constructor_arch(thread_t *t);
    238 #endif
     226extern void thr_constructor_arch(thread_t *);
     227#endif
     228
    239229#ifndef thr_destructor_arch
    240 extern void thr_destructor_arch(thread_t *t);
    241 #endif
    242 
    243 extern void thread_sleep(uint32_t sec);
    244 extern void thread_usleep(uint32_t usec);
     230extern void thr_destructor_arch(thread_t *);
     231#endif
     232
     233extern void thread_sleep(uint32_t);
     234extern void thread_usleep(uint32_t);
    245235
    246236#define thread_join(t) \
    247237        thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    248 extern int thread_join_timeout(thread_t *t, uint32_t usec, int flags);
    249 extern void thread_detach(thread_t *t);
    250 
    251 extern void thread_register_call_me(void (* call_me)(void *),
    252     void *call_me_with);
    253 extern void thread_print_list(void);
    254 extern void thread_destroy(thread_t *t);
    255 extern void thread_update_accounting(void);
    256 extern bool thread_exists(thread_t *t);
     238
     239extern int thread_join_timeout(thread_t *, uint32_t, unsigned int);
     240extern void thread_detach(thread_t *);
     241
     242extern void thread_print_list(bool);
     243extern void thread_destroy(thread_t *, bool);
     244extern thread_t *thread_find_by_id(thread_id_t);
     245extern void thread_update_accounting(bool);
     246extern bool thread_exists(thread_t *);
     247extern void thread_stack_trace(thread_id_t);
    257248
    258249/** Fpu context slab cache. */
     
    260251
    261252/* Thread syscall prototypes. */
    262 extern unative_t sys_thread_create(uspace_arg_t *uspace_uarg,
    263     char *uspace_name, size_t name_len, thread_id_t *uspace_thread_id);
    264 extern unative_t sys_thread_exit(int uspace_status);
    265 extern unative_t sys_thread_get_id(thread_id_t *uspace_thread_id);
     253extern sysarg_t sys_thread_create(uspace_arg_t *, char *, size_t,
     254    thread_id_t *);
     255extern sysarg_t sys_thread_exit(int);
     256extern sysarg_t sys_thread_get_id(thread_id_t *);
     257extern sysarg_t sys_thread_usleep(uint32_t);
    266258
    267259#endif
Note: See TracChangeset for help on using the changeset viewer.