Contiki learning notes --- process structure, contiki --- process

Source: Internet
Author: User

Contiki learning notes --- process structure, contiki --- process

Process, literally, process, look at its structure

 1 struct process { 2       struct process *next; 3 #if PROCESS_CONF_NO_PROCESS_NAMES 4 #define PROCESS_NAME_STRING(process) "" 5 #else 6       const char *name; 7 #define PROCESS_NAME_STRING(process) (process)->name 8 #endif 9       PT_THREAD((* thread)(struct pt *, process_event_t, process_data_t));10       struct pt pt;11       unsigned char state, needspoll;12 };

Process indicates a process, which is a struct:

1. struct process * next; the first member * next has its own type and its name starts with "next". It is obviously prepared for the linked list, indicating that all processes will be stored in a linked list. 2. const char * name; this indicates the name of the Process, 3 ~ Row 8: when the global variable PROCESS_CONF_NO_PROCESS_NAMES, the name is null, indicating that the process has no name. This should be prepared for some special CPUs. Ignore it and we will have a name for all processes. # Define PROCESS_NAME_STRING (process)-> name defines a method PROCESS_NAME_STRING () using a macro. Its function is to return the name Member of this struct. This implementation method is quite interesting. It is totally different from C # in the two spiritual worlds, and we will be able to adapt more in the future. 3. PT_THREAD (* thread) (struct pt *, process_event_t, process_data_t); PT_THREAD in Pt. the h header file is defined as follows: # define PT_THREAD (name_args) char name_args substitutes the entire code into the macro definition and expands as follows: char (* thread) (struct pt *, process_event_t, process_data_t) thread is a function pointer pointing to a function that contains three parameters and returns a char type. What does this function do? Study later.
4. struct pt; the variable name and struct name are the same. The C language is really different, but this variable name is only valid in the structure. Let's take a look at the pt definition of the struct, or in the Pt. h header file.
1  struct pt {2         lc_t lc;3     };
What is lc_t? Continue tracing, typedef unsigned short lc_t; unsigned short type in the Lc-switch.h header file, just a number, an identifier. Why does the pt struct have only one member? Let's make it clear later. 5. unsigned char state. This indicates the state of the process. The three numbers are 0, 1, and 2. Macro definition, in the Process. c file
#define PROCESS_STATE_NONE           0#define PROCESS_STATE_RUNNING     1#define PROCESS_STATE_CALLED        2
These three statuses can only be explained when they are used. 6. unsigned char needspoll; indicates the process priority, which will be used later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.