Ignore:
File:
1 edited

Legend:

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

    ree42e43 re1b6742  
    4040#include <time/timeout.h>
    4141#include <cpu.h>
     42#include <synch/rwlock.h>
    4243#include <synch/spinlock.h>
    4344#include <adt/avl.h>
     
    4950#include <sysinfo/abi.h>
    5051
    51 #define THREAD_STACK_SIZE   STACK_SIZE
    52 #define THREAD_NAME_BUFLEN  20
     52#define THREAD_STACK_SIZE       STACK_SIZE
     53#define THREAD_NAME_BUFLEN      20
    5354
    5455extern const char *thread_states[];
     
    6061 * When using this flag, the caller must set cpu in the thread_t
    6162 * structure manually before calling thread_ready (even on uniprocessor).
    62  *
    63  */
    64 #define THREAD_FLAG_WIRED  (1 << 0)
    65 
     63 */
     64#define THREAD_FLAG_WIRED       (1 << 0)
    6665/** Thread was migrated to another CPU and has not run yet. */
    67 #define THREAD_FLAG_STOLEN  (1 << 1)
    68 
     66#define THREAD_FLAG_STOLEN      (1 << 1)
    6967/** Thread executes in userspace. */
    70 #define THREAD_FLAG_USPACE  (1 << 2)
    71 
     68#define THREAD_FLAG_USPACE      (1 << 2)
    7269/** Thread will be attached by the caller. */
    73 #define THREAD_FLAG_NOATTACH  (1 << 3)
     70#define THREAD_FLAG_NOATTACH    (1 << 3)
    7471
    7572/** Thread structure. There is one per thread. */
    7673typedef struct thread {
    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        
     74        link_t rq_link;         /**< Run queue link. */
     75        link_t wq_link;         /**< Wait queue link. */
     76        link_t th_link;         /**< Links to threads within containing task. */
     77
    8178        /** Threads linkage to the threads_tree. */
    8279        avltree_node_t threads_tree_node;
     
    8683         * Protects the whole thread structure except list links above.
    8784         */
    88         IRQ_SPINLOCK_DECLARE(lock);
    89        
     85        SPINLOCK_DECLARE(lock);
     86
    9087        char name[THREAD_NAME_BUFLEN];
    91        
     88
    9289        /** Function implementing the thread. */
    9390        void (* thread_code)(void *);
    9491        /** Argument passed to thread_code() function. */
    9592        void *thread_arg;
    96        
     93
    9794        /**
    9895         * From here, the stored context is restored when the thread is
     
    110107         */
    111108        context_t sleep_interruption_context;
    112        
     109
    113110        /** If true, the thread can be interrupted from sleep. */
    114111        bool sleep_interruptible;
     
    118115        timeout_t sleep_timeout;
    119116        /** Flag signalling sleep timeout in progress. */
    120         volatile bool timeout_pending;
    121        
     117        volatile int timeout_pending;
     118
    122119        /**
    123120         * True if this thread is executing copy_from_uspace().
     
    135132         * thread_exit() before returning to userspace.
    136133         */
    137         bool interrupted;
     134        bool interrupted;                       
    138135       
    139136        /** If true, thread_join_timeout() cannot be used on this thread. */
     
    143140        /** Link used in the joiner_head list. */
    144141        link_t joiner_link;
    145        
     142
    146143        fpu_context_t *saved_fpu_context;
    147144        int fpu_context_exists;
    148        
     145
    149146        /*
    150147         * Defined only if thread doesn't run.
     
    153150         */
    154151        int fpu_context_engaged;
    155        
     152
     153        rwlock_type_t rwlock_holder_type;
     154
     155        /** Callback fired in scheduler before the thread is put asleep. */
     156        void (* call_me)(void *);
     157        /** Argument passed to call_me(). */
     158        void *call_me_with;
     159
    156160        /** Thread's state. */
    157161        state_t state;
    158162        /** Thread's flags. */
    159         unsigned int flags;
     163        int flags;
    160164       
    161165        /** Thread's CPU. */
     
    163167        /** Containing task. */
    164168        task_t *task;
    165        
     169
    166170        /** Ticks before preemption. */
    167171        uint64_t ticks;
     
    172176        /** Last sampled cycle. */
    173177        uint64_t last_cycle;
    174         /** Thread doesn't affect accumulated accounting. */
     178        /** Thread doesn't affect accumulated accounting. */   
    175179        bool uncounted;
    176        
     180
    177181        /** Thread's priority. Implemented as index to CPU->rq */
    178182        int priority;
     
    182186        /** Architecture-specific data. */
    183187        thread_arch_t arch;
    184        
     188
    185189        /** Thread's kernel stack. */
    186190        uint8_t *kstack;
    187        
     191
    188192#ifdef CONFIG_UDEBUG
    189193        /** Debugging stuff */
    190194        udebug_thread_t udebug;
    191 #endif /* CONFIG_UDEBUG */
     195#endif
     196
    192197} thread_t;
    193198
     
    198203 *
    199204 */
    200 IRQ_SPINLOCK_EXTERN(threads_lock);
     205SPINLOCK_EXTERN(threads_lock);
    201206
    202207/** AVL tree containing all threads. */
     
    204209
    205210extern void thread_init(void);
    206 extern thread_t *thread_create(void (*)(void *), void *, task_t *,
    207     unsigned int, const char *, bool);
     211extern thread_t *thread_create(void (*)(void *), void *, task_t *, int,
     212    const char *, bool);
    208213extern void thread_attach(thread_t *, task_t *);
    209214extern void thread_ready(thread_t *);
     
    213218extern void thread_create_arch(thread_t *);
    214219#endif
    215 
    216220#ifndef thr_constructor_arch
    217221extern void thr_constructor_arch(thread_t *);
    218222#endif
    219 
    220223#ifndef thr_destructor_arch
    221224extern void thr_destructor_arch(thread_t *);
     
    227230#define thread_join(t) \
    228231        thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    229 
    230 extern int thread_join_timeout(thread_t *, uint32_t, unsigned int);
     232extern int thread_join_timeout(thread_t *, uint32_t, int);
    231233extern void thread_detach(thread_t *);
    232234
    233 extern void thread_print_list(bool);
    234 extern void thread_destroy(thread_t *, bool);
     235extern void thread_register_call_me(void (*)(void *), void *);
     236extern void thread_print_list(void);
     237extern void thread_destroy(thread_t *);
    235238extern thread_t *thread_find_by_id(thread_id_t);
    236239extern void thread_update_accounting(bool);
Note: See TracChangeset for help on using the changeset viewer.