Changeset 46c20c8 in mainline for kernel/generic/include/proc/thread.h


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

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

    rfb150d78 r46c20c8  
    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. */
    10793        void (* thread_code)(void *);
    10894        /** Argument passed to thread_code() function. */
    10995        void *thread_arg;
    110 
     96       
    11197        /**
    11298         * From here, the stored context is restored when the thread is
     
    124110         */
    125111        context_t sleep_interruption_context;
    126 
     112       
    127113        /** If true, the thread can be interrupted from sleep. */
    128114        bool sleep_interruptible;
     
    132118        timeout_t sleep_timeout;
    133119        /** Flag signalling sleep timeout in progress. */
    134         volatile int timeout_pending;
    135 
     120        volatile bool timeout_pending;
     121       
    136122        /**
    137123         * True if this thread is executing copy_from_uspace().
     
    149135         * thread_exit() before returning to userspace.
    150136         */
    151         bool interrupted;                       
     137        bool interrupted;
    152138       
    153139        /** If true, thread_join_timeout() cannot be used on this thread. */
     
    157143        /** Link used in the joiner_head list. */
    158144        link_t joiner_link;
    159 
     145       
    160146        fpu_context_t *saved_fpu_context;
    161147        int fpu_context_exists;
    162 
     148       
    163149        /*
    164150         * Defined only if thread doesn't run.
     
    167153         */
    168154        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 
     155       
    177156        /** Thread's state. */
    178157        state_t state;
    179158        /** Thread's flags. */
    180         int flags;
     159        unsigned int flags;
    181160       
    182161        /** Thread's CPU. */
     
    184163        /** Containing task. */
    185164        task_t *task;
    186 
     165       
    187166        /** Ticks before preemption. */
    188167        uint64_t ticks;
    189168       
    190169        /** Thread accounting. */
    191         uint64_t cycles;
     170        uint64_t ucycles;
     171        uint64_t kcycles;
    192172        /** Last sampled cycle. */
    193173        uint64_t last_cycle;
    194         /** Thread doesn't affect accumulated accounting. */   
     174        /** Thread doesn't affect accumulated accounting. */
    195175        bool uncounted;
    196 
     176       
    197177        /** Thread's priority. Implemented as index to CPU->rq */
    198178        int priority;
     
    202182        /** Architecture-specific data. */
    203183        thread_arch_t arch;
    204 
     184       
    205185        /** Thread's kernel stack. */
    206186        uint8_t *kstack;
    207 
     187       
    208188#ifdef CONFIG_UDEBUG
    209189        /** Debugging stuff */
    210190        udebug_thread_t udebug;
    211 #endif
    212 
     191#endif /* CONFIG_UDEBUG */
    213192} thread_t;
    214193
     
    219198 *
    220199 */
    221 SPINLOCK_EXTERN(threads_lock);
     200IRQ_SPINLOCK_EXTERN(threads_lock);
    222201
    223202/** AVL tree containing all threads. */
     
    225204
    226205extern void thread_init(void);
    227 extern thread_t *thread_create(void (*)(void *), void *, task_t *, int, char *,
    228     bool);
     206extern thread_t *thread_create(void (*)(void *), void *, task_t *,
     207    unsigned int, const char *, bool);
    229208extern void thread_attach(thread_t *, task_t *);
    230209extern void thread_ready(thread_t *);
     
    234213extern void thread_create_arch(thread_t *);
    235214#endif
     215
    236216#ifndef thr_constructor_arch
    237217extern void thr_constructor_arch(thread_t *);
    238218#endif
     219
    239220#ifndef thr_destructor_arch
    240221extern void thr_destructor_arch(thread_t *);
     
    246227#define thread_join(t) \
    247228        thread_join_timeout((t), SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE)
    248 extern int thread_join_timeout(thread_t *, uint32_t, int);
     229
     230extern int thread_join_timeout(thread_t *, uint32_t, unsigned int);
    249231extern void thread_detach(thread_t *);
    250232
    251 extern void thread_register_call_me(void (*)(void *), void *);
    252 extern void thread_print_list(void);
    253 extern void thread_destroy(thread_t *);
    254 extern void thread_update_accounting(void);
     233extern void thread_print_list(bool);
     234extern void thread_destroy(thread_t *, bool);
     235extern thread_t *thread_find_by_id(thread_id_t);
     236extern void thread_update_accounting(bool);
    255237extern bool thread_exists(thread_t *);
    256238
Note: See TracChangeset for help on using the changeset viewer.