⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thread.hxx

📁 ecos为实时嵌入式操作系统
💻 HXX
📖 第 1 页 / 共 2 页
字号:
        // Constructor, Initialize the thread structure. The thread is    // created in suspended state, and needs to be resumed to execute.    // It is also started at some (configurable) default priority, which    // may need to be changed before calling resume.        Cyg_Thread (        cyg_thread_entry        *entry,         // entry point function        CYG_ADDRWORD            entry_data,     // entry data        cyg_ucount32            stack_size = 0, // stack size, 0 = use default        CYG_ADDRESS             stack_base = 0  // stack base, NULL = allocate        );    Cyg_Thread (        CYG_ADDRWORD            sched_info,     // Scheduling parameter(s)        cyg_thread_entry        *entry,         // entry point function        CYG_ADDRWORD            entry_data,     // entry data        char                    *name,          // thread name        CYG_ADDRESS             stack_base = 0, // stack base, NULL = allocate        cyg_ucount32            stack_size = 0  // stack size, 0 = use default        );    // Re-initialize the thread back to it's initial state.    void Cyg_Thread::reinitialize();        ~Cyg_Thread();        // The following are invoked implicitly on the current thread,    // hence they are static member functions.    static void         sleep();        // Put thread to sleep    static void         counted_sleep();// Decrement counter or put                                        // thread to sleep#ifdef CYGFUN_KERNEL_THREADS_TIMER    static void         counted_sleep( cyg_tick_count delay );                                        // ...for delay ticks#endif        static void         exit();         // Terminate thread    static void         yield();        // Yield CPU to another thread    static void         rotate_queue( cyg_priority pri );                                        // Rotate that run queue    void                to_queue_head( void );                                        // Move to the head of its queue                                        // (not necessarily a scheduler q)    static Cyg_Thread   *self();        // Return current thread            // The following are called on threads other than the current one.    void                wake();         // Wake this thread from sleep.    void                counted_wake(); // Increment counter or wake thread    cyg_uint32          cancel_counted_wake();                                        // Cancel counted wakeups for this                                        // thread and return how many were                                        // pending    void                suspend();      // Suspend this thread: increment counter and                                        // deschedule.        void                resume();       // Resume this thread: decrement counter and                                        // reschedule if counter is zero.    void                release();      // Release thread from sleep with BREAK                                        // wake_reason.        void                kill();         // Kill this thread        void                force_resume(); // Resume this thread: set counter to zero.    cyg_uint32          get_state();    // Return current thread state.    // Accessor functions to set and get wait_info.        void                set_wait_info(CYG_ADDRWORD data);    CYG_ADDRWORD        get_wait_info();        // This part of the API is used if we have a clock and want    // per-thread timers for doing delays and timeouts.    // delay the given number of ticks    void delay( cyg_tick_count delay );            enum cyg_reason                     // sleep/wakeup reason codes    {        NONE,                           // No recorded reason        WAIT,                           // Wait with no timeout        DELAY,                          // Simple time delay        TIMEOUT,                        // Wait with timeout/timeout expired        BREAK,                          // forced break out of sleep        DESTRUCT,                       // wait object destroyed[note]        EXIT,                           // forced termination        DONE                            // Wait/delay complete    };    // [note] NOT the thread, some object it was waiting on.    //        Thread destruction would first involve EXITing it.    private:#ifdef CYGFUN_KERNEL_THREADS_TIMER    Cyg_ThreadTimer     timer;          // per-thread timer#endif    cyg_reason          sleep_reason;   // reason for sleeping    cyg_reason          wake_reason;    // reason for waking    #ifdef CYGIMP_THREAD_PRIORITYpublic:    // If the scheduler implements priorities, provide    // functions to set and get it.        void set_priority( cyg_priority pri );    cyg_priority get_priority();    // This returns the current dispatching priority of the    // thread. This may differ from the result of get_priority()    // in the presence of priority inheritance or certain    // scheduling algorithms.    cyg_priority get_current_priority();        #endif#ifdef CYGVAR_KERNEL_THREADS_DATAprivate:    // Array of single word entries for each index.     CYG_ADDRWORD        thread_data[CYGNUM_KERNEL_THREADS_DATA_MAX];    // Map of free thread_data indexes. Each bit represents an index    // and is 1 if that index is free, and 0 if it is in use.    static cyg_ucount32        thread_data_map;public:        static CYG_ADDRWORD get_data( cyg_ucount32 index );    static CYG_ADDRWORD *get_data_ptr( cyg_ucount32 index );    void                set_data( cyg_ucount32 index, CYG_ADDRWORD data );    static cyg_ucount32 new_data_index();    static void         free_data_index( cyg_ucount32 index );#endif#ifdef CYGVAR_KERNEL_THREADS_NAMEprivate:    // An optional thread name string, for humans to read    char                        *name;public:        // function to get the name string    char                        *get_name();    #endif    #ifdef CYGVAR_KERNEL_THREADS_LIST        // Housekeeping list that tracks all threadsprivate:    Cyg_Thread                  *list_next;    static Cyg_Thread           *thread_list;    void                        add_to_list(      void );    void                        remove_from_list( void );public:    static Cyg_Thread           *get_list_head();        Cyg_Thread                  *get_list_next();    #endif    public:        // Set sleep reason to reason and wake reason to NONE    static void set_sleep_reason( cyg_reason reason = WAIT);    cyg_reason get_sleep_reason();        // Set the wakeup reason to the given value    void set_wake_reason( cyg_reason reason = DONE);    // Get current wake reason    cyg_reason get_wake_reason();    static void set_timer(              // Set timeout and sleep reason        cyg_tick_count  trigger,        // Absolute wakeup time        cyg_reason      sleep_reason    // reason for sleeping        );    static void clear_timer();          // disable thread timer    // Get a 16 bit unique id for this thread. This is    // used in tracing and instrumentation to identify the    // current thread.        cyg_uint16 get_unique_id();        };// -------------------------------------------------------------------------// Thread Queue class.// This defines the main API for manipulating queues of threads.class Cyg_ThreadQueue    : public Cyg_ThreadQueue_Implementation{    public:    CYGDBG_DEFINE_CHECK_THIS        // API used by rest of kernel.                            // Add thread to queue    void                enqueue(Cyg_Thread *thread);                        // return first thread on queue    Cyg_Thread          *highpri();                        // remove first thread on queue        Cyg_Thread          *dequeue();                        // remove specified thread from queue        void                remove(Cyg_Thread *thread);                        // test if queue is empty    cyg_bool            empty();    };// -------------------------------------------------------------------------// Thread inlines// Return current thread state.inline cyg_uint32 Cyg_Thread::get_state(){    return state;}inline void Cyg_Thread::set_wait_info(CYG_ADDRWORD data){    wait_info = data;}inline CYG_ADDRWORD Cyg_Thread::get_wait_info(){    return wait_info;}// -------------------------------------------------------------------------#endif // ifndef CYGONCE_KERNEL_THREAD_HXX// EOF thread.hxx

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -