Overview of real-time MiniGUI architecture

Source: Internet
Author: User
Article title: an overview of the real-time MiniGUI architecture. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   1 Introduction
  
So far, the latest MiniGUI version is 0.9.96. We have positioned the 0.9.xx series version as the preview version of MiniGUI 1.0. When version 0.9.xx is stable enough, we will release MiniGUI 1.0, and the current code will not be significantly adjusted. After the release of MiniGUI 1.0, we will start developing MiniGUI 2.0 immediately. This version is expected to make significant adjustments to the architecture. To attract more free software programmers to MiniGUI 2.0 development and to help MiniGUI programmers develop programs, we will write a series of articles to introduce the architecture of MiniGUI 1.0, analyze some of the shortcomings and the issues that need to be optimized and transformed in version 2.0. The document plan for introducing the architecture is as follows:
  
Architecture Overview (this article ). The MiniGUI 1.0 architecture will be introduced as a whole. Key points include: basic concepts of threads; multi-threaded microclient/server systems; key data structures of multi-thread communication ?? Message Queue, application of object-oriented technology in MiniGUI, and so on.
MiniGUI multi-window management. This section describes the multi-window mechanism of MiniGUI and related window technologies. It involves window cutting and Z-order processing, message transmission, control class design, input method module design, and so on.
MiniGUI graphical device management. This section focuses on how MiniGUI handles window rendering. It mainly includes the concept of the graphic context, coordinate ING, the concept of the local, global, and valid cut domain of the graphic context, and so on.
Graphics abstraction layer and input abstraction layer. The graphic abstraction layer (GAL) and the input abstraction layer (IAL) greatly improve the portability of the MiniGUI and separate the underlying graphics devices from the upper interfaces. Here we will focus on the GAL and IAL interfaces of MiniGUI, and take embedded systems such as EP7211 as an example to illustrate how to Port MiniGUI to a new embedded platform.
Supports multiple fonts and character sets. MiniGUI uses logical fonts to process multiple fonts and multiple character sets. This technology has successfully applied the object-oriented technology. through a single logical interface, it can support various character sets and fonts.
   2 POSIX thread
  
MiniGUI is a thread-based window system. To understand the MiniGUI architecture, we need to first understand the thread.
  
2.1 What Is thread
A thread is usually defined as a different execution route of code in a process. That is to say, in a process, multiple different code routes can be executed simultaneously. For example, in common word processing programs, the main thread processes user input, while other parallel running threads can save users' documents in the background when necessary. We can also say that the thread is a "lightweight process ". In Linux, each process consists of five basic parts: code, data, stack, file I/O, and signal table. Therefore, the system will spend more time processing processes, especially during process scheduling and task switching. In this sense, we can understand general processes as heavyweight processes. To share information between heavyweight processes, you can only use pipelines or shared memory. If a heavyweight process uses fork () to derive sub-processes, only the code between parent and child processes is shared.
  
The thread we mentioned here reduces some system expenses by sharing some basic components. By sharing these basic components, the task switching efficiency can be greatly improved, and data sharing is no longer difficult ?? Because almost everything can be shared.
  
There are two types of threads: user-level threads and kernel-level threads ".
  
A user thread is a thread implemented in a user program without kernel support. this thread can be implemented even in an operating system like DOS, but thread scheduling requires the user program to complete, there are some collaborative multitasking similar to Windows 3.x. In addition, the kernel needs to participate in thread scheduling. Both models have their own advantages and disadvantages. The user thread does not require additional kernel expenses, but when a thread is in the waiting state due to I/O, the entire process will be switched to the waiting state by the scheduler, other threads do not have the opportunity to run, while kernel threads do not have various restrictions, but occupy more system expenses.
  
Linux supports kernel-level multithreading. you can also download user-level thread libraries on Linux from the Internet. Linux kernel threads are better than other operating system kernel implementations. Most operating systems define threads separately, which increases the complexity of the kernel and Scheduler. in Linux, the thread is defined as "execution context", which is actually just another execution context of the process. In this way, the Linux kernel only needs to differentiate processes and only needs one process/thread array, while the scheduler is still a process scheduler. Linux clone system calls can be used to create new threads.
  
2.2 POSIX thread
POSIX standard defines the C language interface for thread operations. We can divide POSIX thread interfaces as follows:
  
Thread creation and destruction. Used to create threads, cancel threads, and create thread cancellation points.
Operation interface of mutex. Provides a basic shared object mutex access mechanism.
Semaphore operation interface. Provides a basic semaphore-based synchronization mechanism. It cannot be confused with the semaphore of the System v ipc mechanism.
Conditional operation interface. Provides a basic conditional synchronization mechanism. Although semaphores and conditional quantities can both be divided into synchronization mechanisms, the conditional quantities are more flexible than semaphores, such as broadcast and wait timeout settings. However, operations on the condition volume are complicated.
Signal operation interface. Process the signal sending and thread signal mask between threads.
Others. This includes local Thread storage and one-time functions.
Currently, the POSIX-compatible thread library on Linux is called LinuxThreads and has been released as part of glibc. The names of these functions start with pthread _ (the Semaphore operation function starts with sem ).
  
In order to have some perceptual knowledge about threads, we will give two examples here.
  
In the first example, after entering the main () function, call the pthread_create function to create another thread. Pthread_create has two main parameters: one is the thread_entry function of the new thread, and the other is the parameter passed to the entry function (data ), the identifier of the new thread is returned through the reference parameter (new_thread ). See List 1.
  
List 1 creation of a new thread
  
Void * thread_entry (void * data)
{
... // Do something.
Return NULL;
}
  
Int main (void)
{
  
Pthread_t new_thread;
Int data = 2;
  
Pthread_create (& new_thread, NULL, thread_entry, & data );
Pthread_join (new_thread, NULL );
}
  
After a new thread is created for the main () function, call the pthread_join function to wait until the execution of the new thread ends. Pthread_join is similar to a process-level wait system call. This function is returned when the waiting thread execution ends. Pthread_join can be used to implement some simple thread synchronization. Note that in the above example, the error check of the return value of the function call is ignored.
  
The second example is the two threads that use semaphores for synchronization. The examples used here use semaphores to solve the classic "producer/consumer" problem (list 2 ). First, we will explain the basic concepts of semaphores.
  
The semaphore concept was first proposed by E. W. Dijkstra in 1965. The Semaphore is actually an integer. the process (or thread) has two types of operations on the Semaphore. one is DOWN, and the other is UP. The result of the DOWN operation is to reduce the semaphore value by 1, and the result of the UP operation is to increase the semaphore value by 1. Before performing an actual operation, the process first checks the current value of the semaphore. if the current value is greater than 0, the process can perform the DOWN operation. Otherwise, the process is sleep, wait for the UP operation of other processes on the Semaphore, because the UP operation of other processes will increase the semaphore value, so that the DOWN operation can be completed successfully. After a semaphore is successfully operated by a process, other processes that sleep on the Semaphore may successfully complete their operations, the system is responsible for checking whether the sleep process can complete its own operations.
  
To understand semaphores, we imagine a ticket ordering system. At first, passengers usually have enough votes to meet the ticket quota. When the remaining number of air tickets is 1 and a passenger needs to set two tickets, the passenger cannot meet the customer's needs. at this time, the ticket sales lady asked the passenger to leave his phone number, if another person returns the ticket, the passenger can be given priority to issue a ticket. If a person finally returns the ticket, the ticket sales lady calls to inform the above-mentioned passengers who want to set two tickets, then the passengers can set their own tickets.
  
We can regard passengers as processes, while tickets can be seen as DOWN operations on semaphores, refunds can be seen as UP operations on semaphores, and initial semaphores are the total number of tickets, the ticket sales lady is equivalent to the Semaphore manager of the operating system. it is determined by her (the operating system) whether the passenger (process) can complete the operation and is responsible for notifying (awakening) when new conditions are ripe) registered (dormant) Passengers (processes ).
  
In the operating system, the simplest form of a semaphore is an integer. multiple processes can check and set the semaphore value. This kind of check and setup operations cannot be interrupted, also known as "atomic" operations. The result of checking and setting the operation is the result of adding the current and set values of the semaphore. The set value can be a positive value or a negative value. Depending on the check and setting results, the process that performs the operation may enter the sleep state. after other processes complete their own check and set the operation, the system checks whether the previous sleep process can complete the corresponding check and setting operations under the conditions of the new signal value. In this way, the operations of multiple processes can be coordinated through semaphores.
  
Semaphores can be used to implement "key segments ". A key segment refers to a code segment where only one process can execute code at a time. Semaphores can also be used to solve the classic issue of "producer/consumer". The issue of "producer/consumer" is similar to that of the aforementioned issue of ticketing. This problem can be described as follows:
  
The two processes share a public, fixed-size buffer. One process, that is, the producer, puts information into the buffer, and the other process, that is, the consumer, remove information from the buffer (this problem can also be generalized to m producers and n consumers ). When the producer puts information into the buffer zone, if the buffer zone is full, the producer goes to sleep, and when the consumer takes the information from the buffer zone, the producer can be awakened; when the consumer obtains information from the buffer, if the buffer is empty, the consumer enters sleep. when the producer writes information to the buffer, the consumer can be awakened.
  
The example in listing 2 is actually the thread version of the "producer/consumer" issue.
  
Listing 2 uses semaphores to solve the "producer/consumer" problem
  
/* The classic producer-consumer example, implemented with semaphores.
All integers between 0 and 9999 shoshould be printed exactly twi

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.