CN118012638A - Network communication method, device and medium of vehicle-mounted safety computer - Google Patents

Network communication method, device and medium of vehicle-mounted safety computer Download PDF

Info

Publication number
CN118012638A
CN118012638A CN202311794142.5A CN202311794142A CN118012638A CN 118012638 A CN118012638 A CN 118012638A CN 202311794142 A CN202311794142 A CN 202311794142A CN 118012638 A CN118012638 A CN 118012638A
Authority
CN
China
Prior art keywords
event
module
activated
thread
reactor
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311794142.5A
Other languages
Chinese (zh)
Inventor
魏洋
彭宇飞
陈宜航
李长远
周宇恒
郑娟
华晴
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Casco Signal Ltd
Original Assignee
Casco Signal Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Casco Signal Ltd filed Critical Casco Signal Ltd
Priority to CN202311794142.5A priority Critical patent/CN118012638A/en
Publication of CN118012638A publication Critical patent/CN118012638A/en
Pending legal-status Critical Current

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention relates to a network communication method, equipment and medium of a vehicle-mounted safety computer, wherein the method is realized based on a Reactor model, and the method comprises the following steps: the application layer module initializes the Reactor controller module to provide preparation work for the subsequent application layer module registration event; the application layer module initializes an event processing module, creates an event of interest and binds an event callback function; the application layer module calls an event registration interface provided by the Reactor controller module to register the created event; the application layer module calls a main circulation interface of the Reactor controller module; the Reactor controller module monitors whether the registered event is activated or not by means of the multiplexing manager module, if yes, the Reactor controller informs the event processing module that the designated event is activated, and the event processing module processes the activated event after receiving the notification of the Reactor controller. Compared with the prior art, the method has the advantages of priority-based processing, high real-time performance, strong concurrent processing capability and the like.

Description

Network communication method, device and medium of vehicle-mounted safety computer
Technical Field
The invention relates to the technical field of vehicle-mounted safety of rail transit, in particular to a network communication method, device and medium of a vehicle-mounted safety computer.
Background
The train-mounted safety computer is a central of train operation command, and plays important roles of monitoring various parts of the train, processing train operation data, controlling train operation and the like, so that the train-mounted safety computer is one of key systems for ensuring the safe operation of the train. The train-mounted safety computer network communication system bears the communication function with the train control center and other train systems, plays a role of a bridge for the communication of the train-mounted safety computer and other systems, and comprises the steps of receiving driving permission commands, transmitting train state data, receiving scheduling information and the like. The train-mounted safety computer network communication system based on the train-mounted safety computer network communication system can meet the high real-time requirement of data transmission and can quickly respond to network data.
Conventional network communication systems are based on blocking network programming, where program flow is typically blocked from reading data. TCP and UDP are full duplex protocols that support simultaneous read and write operations, and when a thread/process is blocked on read data, sending data to the connection must wait for the read data to complete, which results in inefficiency. To solve the above problems, IO multiplexing technology has been developed, and a thread can process multiple connections through a multiplexer provided by an operating system such as select/poll/epoll, thereby improving data transceiving efficiency. Meanwhile, through the thought of a Reactor (Reactor), the universal codes of the network part are extracted into a public framework or library, and a user can realize complete network service by only writing business logic codes and registering the business logic codes into the framework through event callback.
How to realize the vehicle-mounted safety computer network communication with high real-time performance and strong concurrent processing capability becomes the technical problem to be solved.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provide a network communication method, equipment and medium of a vehicle-mounted safety computer.
The aim of the invention can be achieved by the following technical scheme:
According to one aspect of the present invention, there is provided a network communication method of a vehicle-mounted security computer, the method being implemented based on a Reactor model, the Reactor model including an event source module, a Reactor controller module, a multiplexing manager module, an event processing module, and an application layer module, the method comprising the steps of:
Step S1, an application layer module initializes a Reactor controller module to provide preparation work for a subsequent application layer module registration event;
Step S2, an application layer module initializes an event processing module, creates an event of interest and binds an event callback function;
step S3, the application layer module calls an event registration interface provided by the Reactor controller module to register the created event;
Step S4, the application layer module calls a main circulation interface of the Reactor controller module, and the step S5 is entered;
step S5, judging whether a registration event exists, if so, entering step S6; otherwise, ending;
step S6, judging whether a cycle end mark is set, if not, entering step S7; otherwise, ending;
step S7, the Reactor controller module monitors whether the registered event is activated or not by means of the multiplexing manager module, if yes, the step S8 is entered, and if not, the step S5 is entered;
step S8, the Reactor controller module informs the event processing module that the designated event is activated, and the event processing module processes the activated event after receiving the notification message, and then the step S5 is performed.
Preferably, the multiplexing manager module is respectively in communication connection with the Reactor controller module and the event source module, the Reactor controller module is respectively in communication connection with the event processing module and the application layer module, and the application layer module is respectively in communication connection with the event source module, the Reactor controller module and the event processing module.
More preferably, the event source module includes file descriptors, sockets, timers and signal sources of the system;
The multiplexing manager module is a bridge between the Reactor controller module and the event source module and is used for monitoring whether an event in the event source is activated or not, and if the activation event is monitored, the Reactor controller module is notified;
The Reactor controller module monitors whether an event source is activated or not by means of the multiplexing manager module; when the event source is monitored to be activated, calling a callback function associated with the event source by means of the event processing module to process the event;
the event processing module comprises a monitoring thread and a thread pool, and processes the activated event appointed by the Reactor controller module through the monitoring thread;
The application layer module is used for creating an event source of interest, binding a callback function of the event source, calling an event registration interface provided by the Reactor controller module and registering the event of interest into the Reactor model.
Preferably, the Reactor controller module adopts a one-dimensional array of stored events, the stored events have priorities, an index of the one-dimensional array is used as the event priorities, and the array elements are of a doubly linked list structure and are used for storing a plurality of events with the same priorities.
Preferably, the event that the registration has been created includes the steps of:
Step S101, an application layer module calls an event registration interface provided by a Reactor controller module, and registers an event of interest into the Reactor controller module;
Step S102, a Reactor controller module acquires a registered specific event from an event processing module;
step S103, registering the event into the multiplexing controller module by the Reactor controller module;
In step S104, the multiplexing controller module is responsible for returning the registration event result.
Preferably, the events include I/O events, timer events and signal events, and the process of fusion unifying the three events includes a process of fusion unification of I/O events and timer events and a process of fusion unification of I/O events and signal events.
More preferably, the fusion unification process of the I/O event and the timer event specifically includes: storing timer events registered in the multiplexing manager module by using the small root pile data structure, wherein the timing duration of the timer events is used as a key value of the small root pile data structure; in event loops of the Reactor controller module, acquiring a key value with the minimum timing duration in a small root pile data structure as the maximum timeout duration of an I/O multiplexing select or poll interface in each loop; when the system I/O multiplexing returns, all ready timer events are activated.
More preferably, the fusion unification process of the I/O event and the signal event specifically includes: a socket pair is created by utilizing a message notification mechanism, when a signal event occurs, a message notification is initiated on a write socket, and a multiplexing module is called in an event loop of a Reactor controller to monitor a readable I/O event on a read socket to monitor the occurrence of the signal event, wherein the socket pair comprises a read socket and a write socket.
Preferably, the Reactor controller module monitors whether the registered event is activated by means of the multiplexing manager module, and the Reactor controller module notifies the event processing module that the designated event is activated and processes the activated event into an asynchronous execution relationship after the event processing module receives the notification message.
Preferably, the processing of the activated event is realized by the event processing module executing a callback function of the activated event and a thread pool capacity dynamic capacity expansion mechanism.
More preferably, the process of processing the activated event includes the steps of:
step S201, the monitoring thread of the event processing module waits for an activated event and has a timeout mechanism;
step S202, judging whether an activated event exists, if not, entering step S201; otherwise, step S203 is entered;
Step S203, judging whether an idle working thread exists in the thread pool, if so, allocating one idle working thread in the thread pool to process the activated event, and entering step S201; otherwise, go to step S204;
Step S204, judging whether the number of the working threads in the current thread pool is larger than the maximum capacity of the thread pool, if not, newly creating a working thread to be added into the thread pool, executing a callback function of an activated event, and entering step S201; otherwise, step S205 is entered;
step S205, judging whether the priority of the activating event to be processed is higher than the priority of all working threads in a busy state in a thread pool, if so, creating a working thread to be added into the thread pool, and executing a callback function of the activating event to be processed; otherwise, the process waits for an idle thread and advances to step S201.
More preferably, the monitoring thread schedules the working threads in the thread pool based on the priority of the activated events, and the events with high priority are scheduled and processed preferentially.
More preferably, the event processing module further includes a thread pool capacity dynamic reduction mechanism, the thread pool capacity dynamic reduction mechanism including the steps of:
step S301, a monitoring thread of an event processing module waits for an activated event and is provided with a timeout mechanism;
Step S302, judging whether an activated event exists, if yes, processing the activated event; otherwise, when the timer has not timed out and has not been started, the step S303 is entered;
Step S303, judging whether an idle working thread exists in the current thread pool, if not, entering step S301 to wait for an activation event; otherwise, go to step S304;
step S304, judging whether the number of threads processed by the current thread Chi Zhonggong is larger than the maximum value of the capacity of the thread pool, if so, destroying the idle working threads, and entering step S301; otherwise, step S305 is entered;
step S305, judging whether the number of threads adopted by the current thread Chi Zhonggong is larger than the minimum value of the thread pool capacity, if not, entering step S301 to wait for an activated event; otherwise accumulating idle period values of idle working threads, and entering step S306;
Step S306, judging whether the idle period value of the working thread is larger than a set threshold value, if so, destroying the idle thread larger than the threshold value, and proceeding to step S301.
According to a second aspect of the present invention there is provided an electronic device comprising a memory and a processor, the memory having stored thereon a computer program, the processor implementing the method when executing the program.
According to a third aspect of the present invention, there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor implements the method.
Compared with the prior art, the invention has the following beneficial effects:
1. the thread pool capacity dynamic capacity expansion mechanism, the event priority management strategy and the preemptive scheduling strategy based on the task priority of the strong real-time operating system enable the high-priority event to be processed preferentially, ensure the real-time performance of processing the high-priority event and avoid the inversion of the event priority.
2. The invention combines the thread pool capacity dynamic reduction mechanism, dynamically releases idle threads according to the thread conditions in the thread pool, improves the concurrent processing capacity of the vehicle-mounted safety computer network communication system, and saves system resources.
3. The invention adopts the small root pile structure to store the timer event, utilizes the socket pair message notification to manage the signal event, and unifies the timer event, the signal event and the I/O event through the multiplexing mechanism of the operating system, thereby simplifying the call of the application layer module.
Drawings
FIG. 1 is a flow chart of a method of vehicle-mounted secure computer network communication in accordance with the present invention;
FIG. 2 is a schematic diagram of a control flow of a Reactor model for an event according to the present invention;
FIG. 3 is a schematic diagram of a Reactor model according to the present invention;
FIG. 4 is a flow chart of the processing of an activated event according to the present invention;
FIG. 5 is a diagram illustrating a dynamic thread pool capacity reduction mechanism according to the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
The embodiment relates to a network communication method of a vehicle-mounted safety computer, which is realized based on a Reactor model, as shown in fig. 1, and comprises the following steps:
Step S1, an application layer module initializes a Reactor controller module to provide preparation work for a subsequent application layer module registration event;
Step S2, an application layer module initializes an event processing module, creates an event of interest and binds an event callback function;
step S3, the application layer module calls an event registration interface provided by the Reactor controller module to register the created event;
step S4, judging whether a registration event exists, if so, entering a step S5; otherwise, ending;
Step S5, judging whether a circulation mark is set, if not, entering step S6; otherwise, ending;
step S6, the application layer module calls a main circulation interface of the Reactor controller module, and the step S7 is entered;
Step S7, the Reactor controller module monitors whether the registered event is activated or not by means of the multiplexing manager module, if yes, the step S8 is entered, otherwise, the step S7 is continued;
step S8, the Reactor controller module notifies the event processing module that the designated event is activated, and the event processing module processes the activated event after receiving the notification message.
The Reactor (Reactor) model is an event driven mechanism model, and differs from ordinary function calls in that: the application layer module does not actively call a certain API to finish processing, but rather, the Reactor model reverses the event processing flow, the application layer module needs to provide a corresponding interface and register the corresponding interface to the Reactor, and if a corresponding event occurs at a certain moment, the Reactor actively calls an interface function registered by the application layer module, namely a callback function.
Based on the thought of a Reactor (Reactor) model, the invention manages the timing event through a small root Reactor data structure, and because the I/O mechanism of an operating system like select and epoll and the like allow to formulate a maximum waiting time, the invention sets a minimum timeout time according to the stored Timer event in a minimum Reactor, and perfectly fuses the Timer event into the system I/O mechanism; binding local 'loopback address' through socket pair mechanism, realizing signal fusion into system I/O mechanism. The above structural unification simplifies the complexity of user layer call, and makes the call easier for users. In addition, in order to accelerate the response speed of the system and improve the concurrency processing capability, a message queue with priority is used for storing the message to be processed, the message is processed by utilizing a thread pool concurrency mode, the priority of the thread in the thread pool is dynamically adjusted according to the priority of the message to be processed, the task priority preemption scheduling strategy of the strong real-time operating system is fully utilized to ensure that the message with high priority is always executed preferentially, and meanwhile, a thread pool dynamic capacity expansion mechanism is introduced to avoid the occurrence of priority reversal. The invention further abstracts and unifies the signal, timing and I/O event registration callback modes on the basis of the Reactor model thought, considers the requirement of a strong real-time system on real-time performance, introduces a message queue mechanism with priority and a thread pool capacity dynamic adjustment mechanism, and effectively ensures the timeliness of high-priority messages.
The adopted Reactor model comprises an application layer module, an event source module, a Reactor controller module, a multiplexing manager module and an event processing module. Event sources, i.e., file descriptors, sockets, timers, or signal sources of the system, are collectively referred to herein as handles. Creating an event of interest requires specifying a handle and a callback function associated with the event, such as creating a network I/O event requires specifying a network socket associated with the I/O event and a callback processing function when the event occurs; the Reactor controller is an event management interface, runs an event main loop internally, monitors whether an event occurs by means of the multiplexing manager module, and calls a callback function associated with the event to process the event when the multiplexing manager module monitors that the event occurs on a certain handle; the multiplexing manager module is responsible for monitoring whether the event associated with the registered handle occurs or not, and the underlying principle is an I/O multiplexing mechanism provided by an operating system; the event processing module performs abstract packaging on different event types, unifies the commonalities of the different event types, and packages the callback function, the event state, the event attribute and other information of the event.
The event source module is responsible for creating and registering in the reactor model through the reactor controller module by the application layer module;
The Reactor (Reactor) controller module monitors whether an event source is activated or not by means of the multiplexing manager module, is not directly connected with the event source in a communication mode, communicates with the event processing module after monitoring that the event source is activated, and calls a callback function associated with the event source to process an event by means of the event processing module;
The multiplexing manager module is a bridge between the Reactor (Reactor) controller module and the event source, and is responsible for monitoring whether the event source is activated or not, and informing the Reactor controller module if the event source is activated;
The event processing module is in communication connection with the Reactor (Reactor) controller module and is responsible for processing callback functions of activated events appointed by the Reactor (Reactor) controller module;
The application layer module is responsible for creating an event source of interest and binding a callback function of the event source, calling an event registration interface provided by a Reactor controller, and registering the event of interest into a Reactor (Reactor) model;
The control flow of the Reactor model for events is shown in fig. 2, wherein registering created events includes the steps of:
Step S101, an application layer module calls an event registration interface provided by a Reactor controller module, and registers an event of interest into the Reactor controller module;
Step S102, a Reactor controller module acquires a registered specific event from an event processing module;
step S103, registering the event into the multiplexing controller module by the Reactor controller module;
In step S104, the multiplexing controller module is responsible for returning the registration event result.
After the event registration, the Reactor controller module calls an interface of the multiplexing manager module in an internal event monitoring loop to inquire whether an event occurs, if the monitored event source occurs at a certain moment, the multiplexing controller module returns an event 'activation' result, the Reactor controller module calls an event processing interface unified by the event processing module according to the result returned by the multiplexing controller module, the event processing responsibility is transferred to the event processing module, and the event processing module internally processes related events according to an event callback function defined during the initialization of the application layer module.
The method comprises an I/O event, a timer event and a signal event, and is designed to unify calling interfaces of the three events in order to simplify the calling of an application layer module, and a method for unifying the three events in a fusion way is designed in a Reactor controller module and a multiplexing manager module.
First, the unified method for fusing I/O event and timer event: the timer event registered in the multiplexing manager module is stored by using the small root pile data structure, the timing time length of the timer event is used as a Key (Key) value of the small root pile data structure, and in the time cycle of the Reactor controller module, the Key (Key) value with the minimum timing time length in the small root pile is acquired every cycle and used as the maximum timeout length of the I/O multiplexing select or poll interface. When system I/O multiplexing returns, all ready timer events are re-activated
Secondly, the method for fusing and unifying the I/O event and the signal event comprises the following steps: the signal event is a typical asynchronous event, in order to more naturally fuse the signal event into the I/O multiplexing mechanism of the system, a socket pair (socket pair) is created by using a message notification mechanism, and the socket pair comprises a read socket and a write socket, when the signal event occurs, a callback function of the signal event is not called immediately, but a message notification is initiated on the write socket, and a multiplexing module is called in an event loop of the Reactor controller module to monitor the readable I/O event on the read socket (socket) so as to realize the interception of the signal event.
The train-mounted safety computer is required to have quick response capability, and in order to improve the concurrent processing capability of the train-mounted safety computer network communication system, an event queue storage structure with priority is designed in a Reactor controller module in a Reactor model as shown in fig. 3. The storage structure is a double-linked list formed by one-dimensional arrays, the index of the double-linked list is event priority, and the array elements are a plurality of events with the same priority stored in the double-linked list; and introducing a thread pool mechanism into the event processing module, and processing callback functions associated with the occurred events by utilizing multithreading in the thread pool. In the event cycle of the Reactor controller module, a multiplexing manager module is utilized to judge whether an event occurs, the event occurrence is regarded as the event being activated, and the event is added into an activated event queue according to the priority of the event. When an activating event is added to the activated event queue, a monitoring thread in the event processing module is awakened, and the monitoring thread dispatches a working thread to process an event callback function according to the thread working state in the current thread pool.
The policy of the monitoring thread scheduling thread pool is as follows: ensuring that high priority events in the activated event queue are prioritized. Defining priority lists of different events, setting priority attributes of the working threads according to the priority of the activated events to be processed when the monitoring threads schedule the working threads, associating the event priorities with the priority attributes of the working threads, and guaranteeing that the high-priority working threads are scheduled preferentially by utilizing a preemptive scheduling strategy of a strong real-time operating system operated by a vehicle-mounted safety computer network communication system based on the priority, thereby guaranteeing that the high-priority events are processed preferentially.
This scenario is likely to occur due to the limited thread pool capacity in the event processing module: the low priority event is first activated to fill the worker thread in the thread pool, at which time if a higher priority event is activated, because the worker thread in the thread pool is already fully occupied, resulting in a temporary non-allocation of the high priority event to the worker thread. This scenario results in a reversal of priority, i.e., a high priority event needs to passively wait for a low priority event to be processed to yield worker thread resources before it can get idle worker thread resources.
In order to solve the problem of event priority reversal, the invention designs a thread pool capacity dynamic adjustment mechanism. As shown in fig. 4, the process of handling an activated event includes the steps of:
step S201, the monitoring thread of the event processing module waits for an activated event and has a timeout mechanism;
step S202, judging whether an activated event exists, if not, entering step S201; otherwise, step S203 is entered;
Step S203, judging whether an idle working thread exists in the thread pool, if so, allocating one idle working thread in the thread pool to process the activated event, and entering step S201; otherwise, go to step S204;
Step S204, judging whether the number of the working threads in the current thread pool is larger than the maximum capacity of the thread pool, if not, newly creating a working thread to be added into the thread pool, executing a callback function of an activated event, and entering step S201; otherwise, step S205 is entered;
step S205, judging whether the priority of the activating event to be processed is higher than the priority of all working threads in a busy state in a thread pool, if so, creating a working thread to be added into the thread pool, and executing a callback function of the activating event to be processed; otherwise, the process waits for an idle thread and advances to step S201.
The software is turned off or powered down and the process of handling the activated event ends.
As shown in fig. 5, which is a flow chart of a thread pool capacity dynamic reduction mechanism, the thread pool capacity dynamic reduction mechanism includes the following steps:
step S301, a monitoring thread of an event processing module waits for an activated event and is provided with a timeout mechanism;
Step S302, judging whether an activated event exists, if yes, processing the activated event; otherwise, when the timer has not timed out and has not been started, the step S303 is entered;
Step S303, judging whether an idle working thread exists in the current thread pool, if not, entering step S301 to wait for an activation event; otherwise, go to step S304;
step S304, judging whether the number of threads processed by the current thread Chi Zhonggong is larger than the maximum value of the capacity of the thread pool, if so, destroying the idle working threads, and entering step S301; otherwise, step S305 is entered;
step S305, judging whether the number of threads adopted by the current thread Chi Zhonggong is larger than the minimum value of the thread pool capacity, if not, entering step S301 to wait for an activated event; otherwise accumulating idle period values of idle working threads, and entering step S306;
Step S306, judging whether the idle period value of the working thread is larger than a set threshold value, if so, destroying the idle thread larger than the threshold value, and proceeding to step S301.
The process of closing the software or powering off the power supply and the dynamic reduction mechanism of the program pool capacity is finished.
The electronic device of the present invention includes a Central Processing Unit (CPU) that can perform various appropriate actions and processes according to computer program instructions stored in a Read Only Memory (ROM) or computer program instructions loaded from a storage unit into a Random Access Memory (RAM). In the RAM, various programs and data required for the operation of the device can also be stored. The CPU, ROM and RAM are connected to each other by a bus. An input/output (I/O) interface is also connected to the bus.
A plurality of components in a device are connected to an I/O interface, comprising: an input unit such as a keyboard, a mouse, etc.; an output unit such as various types of displays, speakers, and the like; a storage unit such as a magnetic disk, an optical disk, or the like; and communication units such as network cards, modems, wireless communication transceivers, and the like. The communication unit allows the device to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The processing unit executes the respective methods and processes described above, for example, the methods S1 to S8, S101 to S104, S201 to S205, and S301 to S306. For example, in some embodiments, the methods S1-S8, S101-S104, S201-S205, and S301-S306 may be implemented as computer software programs tangibly embodied on a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and/or installed onto the device via the ROM and/or the communication unit. When the computer program is loaded into RAM and executed by the CPU, one or more steps of the methods S1 to S8, S101 to S104, S201 to S205, and S301 to S306 described above may be performed. Alternatively, in other embodiments, the CPU may be configured to perform methods S1-S8, S101-S104, S201-S205, and S301-S306 by any other suitable means (e.g., by means of firmware).
The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: a Field Programmable Gate Array (FPGA), an Application Specific Integrated Circuit (ASIC), an Application Specific Standard Product (ASSP), a system on a chip (SOC), a Complex Programmable Logic Device (CPLD), and the like.
Program code for carrying out methods of the present invention may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
While the invention has been described with reference to certain preferred embodiments, it will be understood by those skilled in the art that various changes and substitutions of equivalents may be made and equivalents will be apparent to those skilled in the art without departing from the scope of the invention. Therefore, the protection scope of the invention is subject to the protection scope of the claims.

Claims (15)

1. The network communication method of the vehicle-mounted safety computer is characterized by being realized based on a Reactor model, wherein the Reactor model comprises an event source module, a Reactor controller module, a multiplexing manager module, an event processing module and an application layer module, and the method comprises the following steps of:
Step S1, an application layer module initializes a Reactor controller module to provide preparation work for a subsequent application layer module registration event;
Step S2, an application layer module initializes an event processing module, creates an event of interest and binds an event callback function;
step S3, the application layer module calls an event registration interface provided by the Reactor controller module to register the created event;
Step S4, the application layer module calls a main circulation interface of the Reactor controller module, and the step S5 is entered;
step S5, judging whether a registration event exists, if so, entering step S6; otherwise, ending;
step S6, judging whether a cycle end mark is set, if not, entering step S7; otherwise, ending;
step S7, the Reactor controller module monitors whether the registered event is activated or not by means of the multiplexing manager module, if yes, the step S8 is entered, and if not, the step S5 is entered;
step S8, the Reactor controller module informs the event processing module that the designated event is activated, and the event processing module processes the activated event after receiving the notification message, and then the step S5 is performed.
2. The network communication method of a vehicle-mounted security computer according to claim 1, wherein the multiplexing manager module is in communication connection with a Reactor controller module and an event source module, the Reactor controller module is in communication connection with an event processing module and an application layer module, and the application layer module is in communication connection with the event source module, the Reactor controller module and the event processing module.
3. The method for network communication of a vehicle-mounted security computer according to claim 2, wherein the event source module comprises a file descriptor, a socket, a timer and a signal source of the system;
The multiplexing manager module is a bridge between the Reactor controller module and the event source module and is used for monitoring whether an event in the event source is activated or not, and if the activation event is monitored, the Reactor controller module is notified;
The Reactor controller module monitors whether an event source is activated or not by means of the multiplexing manager module; when the event source is monitored to be activated, calling a callback function associated with the event source by means of the event processing module to process the event;
The event processing module comprises a monitoring thread and a thread pool, and processes the activated event appointed by the Reactor controller module through a working thread in the monitoring thread scheduling thread pool;
The application layer module is used for creating an event source of interest, binding a callback function of the event source, calling an event registration interface provided by the Reactor controller module and registering the event of interest into the Reactor model.
4. The network communication method of a vehicle-mounted safety computer according to claim 1, wherein the Reactor controller module uses one-dimensional array of stored events with priority, the index of the one-dimensional array is used as the event priority, and the array elements are in a doubly linked list structure and are used for storing a plurality of events with the same priority.
5. The network communication method of a vehicle-mounted security computer according to claim 1, wherein the event that the registration has been created comprises the steps of:
Step S101, an application layer module calls an event registration interface provided by a Reactor controller module, and registers an event of interest into the Reactor controller module;
Step S102, a Reactor controller module acquires a registered specific event from an event processing module;
step S103, registering the event into the multiplexing controller module by the Reactor controller module;
In step S104, the multiplexing controller module is responsible for returning the registration event result.
6. The network communication method of the vehicle-mounted security computer according to claim 1, wherein the events comprise an I/O event, a timer event and a signal event, and the process of fusing and unifying the three events comprises a process of fusing and unifying the I/O event and the timer event and a process of fusing and unifying the I/O event and the signal event.
7. The network communication method of the vehicle-mounted security computer according to claim 6, wherein the fusion unification process of the I/O event and the timer event specifically comprises: storing timer events registered in the multiplexing manager module by using the small root pile data structure, wherein the timing duration of the timer events is used as a key value of the small root pile data structure; in event loops of the Reactor controller module, acquiring a key value with the minimum timing duration in a small root pile data structure as the maximum timeout duration of an I/O multiplexing select or poll interface in each loop; when the system I/O multiplexing returns, all ready timer events are activated.
8. The network communication method of the vehicle-mounted security computer according to claim 6, wherein the fusion unification process of the I/O event and the signal event specifically comprises: a socket pair is created by utilizing a message notification mechanism, when a signal event occurs, a message notification is initiated on a write socket, and a multiplexing module is called in an event loop of a Reactor controller to monitor a readable I/O event on a read socket to monitor the occurrence of the signal event, wherein the socket pair comprises a read socket and a write socket.
9. The method according to claim 1, wherein the Reactor controller monitors whether the registered event is activated by means of the multiplex manager module, and the Reactor controller notifies the event processing module that the designated event is activated and processes the activated event into an asynchronous execution relationship after the event processing module receives the notification message.
10. The method for network communication of a vehicle-mounted security computer according to claim 1, wherein the processing of the activated event is implemented by an event processing module executing a callback function and a thread pool capacity dynamic capacity expansion mechanism of the activated event.
11. The network communication method of a vehicle-mounted security computer according to claim 10, wherein the process of processing the activated event comprises the steps of:
step S201, the monitoring thread of the event processing module waits for an activated event and has a timeout mechanism;
step S202, judging whether an activated event exists, if not, entering step S201; otherwise, step S203 is entered;
Step S203, judging whether an idle working thread exists in the thread pool, if so, allocating one idle working thread in the thread pool to process the activated event, and entering step S201; otherwise, go to step S204;
Step S204, judging whether the number of the working threads in the current thread pool is larger than the maximum capacity of the thread pool, if not, newly creating a working thread to be added into the thread pool, executing a callback function of an activated event, and entering step S201; otherwise, step S205 is entered;
step S205, judging whether the priority of the activating event to be processed is higher than the priority of all working threads in a busy state in a thread pool, if so, creating a working thread to be added into the thread pool, and executing a callback function of the activating event to be processed; otherwise, the process waits for an idle thread and advances to step S201.
12. The method for network communication of a vehicle security computer of claim 11, wherein the supervisory thread schedules the worker threads in the thread pool based on the priority of the activated events, and the high priority events are scheduled and processed preferentially.
13. The method of claim 10, wherein the event processing module further comprises a thread pool capacity dynamic reduction mechanism, the thread pool capacity dynamic reduction mechanism comprising the steps of:
step S301, a monitoring thread of an event processing module waits for an activated event and is provided with a timeout mechanism;
Step S302, judging whether an activated event exists, if yes, processing the activated event; otherwise, when the timer has not timed out and has not been started, the step S303 is entered;
Step S303, judging whether an idle working thread exists in the current thread pool, if not, entering step S301 to wait for an activation event; otherwise, go to step S304;
step S304, judging whether the number of threads processed by the current thread Chi Zhonggong is larger than the maximum value of the capacity of the thread pool, if so, destroying the idle working threads, and entering step S301; otherwise, step S305 is entered;
step S305, judging whether the number of threads adopted by the current thread Chi Zhonggong is larger than the minimum value of the thread pool capacity, if not, entering step S301 to wait for an activated event; otherwise accumulating idle period values of idle working threads, and entering step S306;
Step S306, judging whether the idle period value of the working thread is larger than a set threshold value, if so, destroying the idle thread larger than the threshold value, and proceeding to step S301.
14. An electronic device comprising a memory and a processor, the memory having stored thereon a computer program, characterized in that the processor, when executing the program, implements the method of any of claims 1-13.
15. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any one of claims 1-13.
CN202311794142.5A 2023-12-25 2023-12-25 Network communication method, device and medium of vehicle-mounted safety computer Pending CN118012638A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311794142.5A CN118012638A (en) 2023-12-25 2023-12-25 Network communication method, device and medium of vehicle-mounted safety computer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311794142.5A CN118012638A (en) 2023-12-25 2023-12-25 Network communication method, device and medium of vehicle-mounted safety computer

Publications (1)

Publication Number Publication Date
CN118012638A true CN118012638A (en) 2024-05-10

Family

ID=90943988

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311794142.5A Pending CN118012638A (en) 2023-12-25 2023-12-25 Network communication method, device and medium of vehicle-mounted safety computer

Country Status (1)

Country Link
CN (1) CN118012638A (en)

Similar Documents

Publication Publication Date Title
US9501319B2 (en) Method and apparatus for scheduling blocking tasks
JP3922070B2 (en) Distributed control method and apparatus
CN106293919B (en) A kind of the built-in tasks dispatching device and method of time trigger
CN102567111B (en) A kind of method of asynchronous procedure call, system and terminal device
CN107491346A (en) A kind of task processing method of application, apparatus and system
US11853792B2 (en) Baseline monitoring method and apparatus, readable medium, and electronic device
EP3306866B1 (en) Message processing method, device and system
EP4113299A2 (en) Task processing method and device, and electronic device
CN113179227B (en) AT instruction control method based on queue
CN102096603A (en) Task decomposition control method in MapReduce system and scheduling node equipment
CN113971519B (en) Robot scheduling method and device, electronic equipment and storage medium
CN114840318A (en) Scheduling method for preempting hardware key encryption and decryption resources through multiple processes
CN111176806A (en) Service processing method, device and computer readable storage medium
WO2021046932A1 (en) Message drive method and device based on real-time operating system
CN113658351B (en) Method and device for producing product, electronic equipment and storage medium
CN113268352B (en) Multi-instruction responsive task collaborative management method for universal service robot
CN118012638A (en) Network communication method, device and medium of vehicle-mounted safety computer
CN111897635A (en) Hard real-time and soft real-time task scheduling method based on time triggering
US20130185726A1 (en) Method for Synchronous Execution of Programs in a Redundant Automation System
CN101349975B (en) Method for implementing interrupt bottom semi-section mechanism in embedded operation system
RU2450330C2 (en) Hardware-implemented method of executing programs
CN111309494A (en) Multithreading event processing assembly
JP2002157279A (en) Data collecting device
CN112749020A (en) Microkernel optimization method of Internet of things operating system
CN106484536B (en) IO scheduling method, device and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination