Household intelligent gateway and read-write lock control method

By recording and saving process identification in the home intelligent gateway and forcibly releasing the lock that has exited the process, the deadlock problem caused by abnormal process exit in the read and write lock mechanism is solved, and the stable operation and efficient work of the lock mechanism is achieved.

CN118897742APending Publication Date: 2024-11-05HISENSE BROADBAND MULTIMEDIA TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310501261.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-05
Publication Date
2024-11-05

AI Technical Summary

Technical Problem

In the home intelligent gateway, the process exits abnormally after acquiring the lock in the read and write lock mechanism, resulting in a deadlock and cannot run normally.

Method used

By recording and saving process identifiers in the shared memory area, traversing and judging and forcibly releasing the locks that have exited the process, setting the upper limit of read locks to limit the number of locks to ensure the working efficiency of the lock mechanism.

Benefits of technology

Automatically fix lock exception problem to ensure that the process can acquire the lock normally, improving the working efficiency and stability of the lock mechanism.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118897742A_ABST
    Figure CN118897742A_ABST
Patent Text Reader

Abstract

According to the home intelligent gateway and the read-write lock control method, the home intelligent gateway comprises a shared memory area, a lock state identifier, a read lock upper limit synchronization identifier, a read lock upper limit value, a read process state area and a write process state area are stored in the shared memory area, the read process state area comprises a process identifier corresponding to a process requesting to read a lock, and the write process state area comprises a process identifier corresponding to a process requesting to read a lock. The write process state area comprises a process identifier corresponding to a process requesting to write a lock; according to the method, the process identification of each process is recorded and stored, when the lock waiting time of the process is relatively long, the process identification can be traversed, whether the process corresponding to the process identification is quitted or not is judged, if the process corresponding to the process identification is quitted, the quitted process is forcibly enabled to release the corresponding lock, and then the current read process can obtain the read lock; meanwhile, the lock reading upper limit value is set, and the number of the read locks is limited, so that a lock data structure with a fixed size is realized, and the working efficiency of a lock mechanism is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of intelligent gateways, and in particular to a home intelligent gateway and a read-write lock control method. Background Art

[0002] In a home smart gateway, multiple processes can concurrently read or write resources in shared memory. The read-write lock mechanism can ensure the data security and consistency during multiple parallel operations.

[0003] In the read-write lock mechanism, after a process obtains a read lock or a write lock, the process enters the critical section and reads or writes shared memory by holding the lock in the critical section. The "critical section" refers to a section of program code in the process that requires exclusive execution to access shared memory. The lock states of the critical section include: read lock sharing state, write lock exclusive state and unlocked state; among them, the read lock sharing state means: if a read process adds a read lock to the critical section, other read processes can share the read lock, and any write process will be blocked, that is, in the read lock sharing state, multiple read processes can concurrently read resources in the shared memory, but no process is allowed to write or modify resources in the shared memory. The write lock exclusive state means: after a write process adds a write lock to the critical section, before the write lock is released, other write processes and all read processes are blocked.

[0004] In the above read-write lock mechanism, when a lock is used to access shared memory in a critical section, after a process obtains the lock, if it exits abnormally without releasing the lock, such as if the user actively kills the process or other threads of the process abnormally cause the entire process to exit, other processes will no longer be able to obtain the lock, enter a deadlock state, and cannot run normally. Summary of the invention

[0005] The embodiments of the present application provide a home smart gateway and a read-write lock control method to repair the lock abnormality problem in the process of using the read-write lock mechanism.

[0006] The home smart gateway provided by this application includes:

[0007] A shared memory area, which internally stores a lock status identifier, a read lock upper limit synchronization identifier, a read lock upper limit value, a read process status area, and a write process status area, wherein the read process status area includes a process identifier corresponding to a process requesting a read lock, and the write process status area includes a process identifier corresponding to a process requesting a write lock;

[0008] The processor is configured as:

[0009] The process that issues the lock request is a read process. When the lock status identifier is the third identifier and the read lock upper limit synchronization identifier is the first synchronization identifier, if the current read process waits for the lock time to exceed the preset time, each process identifier in the read process status area is traversed, and it is determined whether the process corresponding to each process identifier has exited; wherein the third identifier indicates that the number of occupied read locks exceeds the read lock upper limit value, and the first synchronization identifier indicates that when the number of read lock processes is greater than the read lock upper limit value, the read lock upper limit value is not modified in real time;

[0010] If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set to the preset identifier in the read process status area so that the exited process releases the read lock;

[0011] The process that issues the lock request is a read process. When the lock status identifier is the fourth identifier, if the current read process waits for the lock time beyond the preset time, each process identifier in the write process status area is traversed, and it is determined whether the process corresponding to each process identifier has exited; wherein the fourth identifier indicates that the write lock is occupied;

[0012] If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set to a preset identifier in the write process status area so that the exited process releases the write lock.

[0013] In the home smart gateway and read-write lock control method provided by the present application, the home smart gateway includes a shared memory area, and the shared memory area internally stores a lock status identifier, a read lock upper limit synchronization identifier, a read lock upper limit value, a read process status area and a write process status area, the read process status area includes a process identifier corresponding to the process requesting a read lock, and the write process status area includes a process identifier corresponding to the process requesting a write lock; the lock status identifier includes a third identifier and a fourth identifier, the third identifier indicates that the number of occupied read locks exceeds the read lock upper limit value, and the fourth identifier indicates that the write lock is occupied; the read lock upper limit synchronization identifier includes a first synchronization identifier, and the first synchronization identifier indicates that when the number of read lock processes is greater than the read lock upper limit value, the read lock upper limit value is not modified in real time. In the present application, when the process that issues a lock request is a read process, the lock status identifier is obtained. If the lock status identifier is the third identifier at this time, the read lock upper limit synchronization identifier is the first synchronization identifier, and it is determined whether the current read process waiting for the lock time exceeds the preset time. If the current read process waiting for the lock time exceeds the preset time, the process identifiers in the read process status area are traversed, and it is determined whether the process corresponding to each process identifier has exited. If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set to the preset identifier in the read process status area, and the read lock occupied by the exited process is forcibly released, so that when The previous read process obtains the read lock; when the process that issues the lock request is a write process, the lock status identifier is obtained. If the lock status identifier is the fourth identifier at this time, it is determined whether the current read process waits for the lock for more than the preset time. If the current read process waits for the lock for more than the preset time, each process identifier in the write process status area is traversed, and it is determined whether the process corresponding to each process identifier has exited. If the process corresponding to the process identifier has exited, the process identifier corresponding to the proposed process is set to the preset identifier in the write process status area, and the write lock occupied by the exited process is forcibly released, so that the current read process obtains the read lock. This application records and saves the process identifier of each process. When a process waits for a long time to wait for the lock, it can traverse the process identifier and determine whether the process corresponding to the process identifier has exited. If the process corresponding to the process identifier has exited, the exited process is forced to release the corresponding lock, automatically repairing the abnormal problem of the read lock, and then the current read process can obtain the read lock; at the same time, this application sets the upper limit of the read lock to limit the number of read locks, thereby realizing a fixed-size lock data structure, thereby ensuring the working efficiency of the lock mechanism. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] In order to more clearly illustrate the technical solutions in the present disclosure, the following briefly introduces the drawings required to be used in some embodiments of the present disclosure. Obviously, the drawings described below are only drawings of some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can also be obtained based on these drawings. In addition, the drawings described below can be regarded as schematic diagrams, and are not limitations on the actual size of the product involved in the embodiments of the present disclosure, the actual process of the method, the actual timing of the signal, etc.

[0015] Figure 1 A diagram of an application scenario of a home smart gateway provided according to some embodiments of the present application;

[0016] Figure 2 A structural diagram of a shared memory area of ​​a home smart gateway provided according to some embodiments of the present application;

[0017] Figure 3 A structural diagram of a read process status area provided according to some embodiments of the present application;

[0018] Figure 4 A structural diagram of a write process status area provided according to some embodiments of the present application;

[0019] Figure 5 A structural diagram of a historical process status area provided according to some embodiments of the present application;

[0020] Figure 6 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 1 ;

[0021] Figure 7 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 2 ;

[0022] Figure 8 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 3 ;

[0023] Fig. 9 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 4 ;

[0024] Fig.10 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 5 . DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.

[0026] Figure 1FIG. 1 is a diagram of a home smart gateway application scenario provided according to some embodiments of the present application. Figure 1 As shown, the user terminal 1000 submits access information. The home smart gateway 2000 includes a router, which selects a message path according to routing, bridging or other business rules and connects to the external server 3000. The external server 3000 responds to the access information and sends a response message. The router receives the response message and forwards the response message to the user terminal.

[0027] The router has a shared memory area inside, which stores shared resources for parallel access by read and write processes. Each process usually accesses the shared memory through a read-write lock mechanism. After the process obtains the read lock or write lock, the process enters the critical section and reads or writes the shared memory by holding the lock in the critical section. The "critical section" refers to a section of program code in the process that accesses the shared memory and requires mutually exclusive execution.

[0028] In the current read-write lock mechanism, when a lock is used to access shared memory in a critical section, if a process obtains the lock and then exits abnormally without releasing the lock, such as if the user actively kills the process or other threads of the process abnormally cause the entire process to exit, other processes will no longer be able to obtain the lock, enter a deadlock state, and cannot operate normally.

[0029] To this end, the present application records and saves the process ID of each process. When a process waits for a long time to wait for a lock, the present application can traverse the process ID and determine whether the process corresponding to the process ID has exited. If the process corresponding to the process ID has exited, the exited process is forced to release the corresponding lock, so that the current read process can obtain the read lock. At the same time, the present application sets an upper limit on the read lock to limit the number of read locks, thereby realizing a fixed-size lock data structure, thereby ensuring the working efficiency of the lock mechanism.

[0030] Figure 2 FIG. 1 is a structural diagram of a shared memory area of ​​a home smart gateway provided according to some embodiments of the present application. Figure 2 As shown, in the present application, some parameters are recorded and stored in the shared memory area to compulsorily release the lock when a lock abnormality problem occurs later; these parameters include: lock status identification, read process status area, write process status area, historical process status area, read lock upper limit value, historical simultaneous read lock count, read lock upper limit synchronization identification, etc. Exemplarily, corresponding registers are set in the shared memory area to store these parameters.

[0031] In some embodiments, a lock status identifier is stored in the shared memory area, and the lock status identifier is used to characterize the status of each lock in the critical area. In some embodiments, the lock status identifier includes a first identifier, a second identifier, a third identifier, and a fourth identifier. When the lock status identifier is the first identifier, it indicates that both the read lock and the write lock are not occupied; when the lock status identifier is the second identifier, it indicates that the read lock is occupied and the number of occupied read locks does not exceed the upper limit of the read lock; when the lock status identifier is the third identifier, it indicates that the number of occupied read locks exceeds the upper limit of the read lock; when the lock status identifier is the fourth identifier, the fourth identifier indicates that the write lock is occupied. Exemplarily, the first identifier is set to 0, the second identifier is set to 1, the third identifier is set to 2, and the fourth identifier is set to 3.

[0032] In some embodiments, a read process status area and a write process status area are stored in the shared memory area; wherein, the read process status area includes the process identifier corresponding to the process requesting a read lock, and the write process status area includes the process identifier corresponding to the process requesting a write lock; by recording and saving the process identifier of each process, when a process waits for a lock for a long time, the process identifiers can be traversed to determine whether the process corresponding to the process identifier has exited. If the process corresponding to the process identifier has exited, the exited process is forced to release the corresponding lock, and the current process obtains the lock.

[0033] Figure 3 FIG. 1 is a structural diagram of a read process status area provided according to some embodiments of the present application. Figure 3 As shown, the status of all current read processes is saved in the read process status area; the initial status of the read process status area is empty; the read process status area includes some process status entries, and a process status entry records the process ID, process name and current time corresponding to the lock acquired corresponding to the current process; the lock occupation time can be calculated according to the current time corresponding to the lock acquired, and when the lock occupation time exceeds a certain time, a reminder can be issued to the terminal to remind the user to check; when the read process acquires the read lock, the process status entries in the read process status area are traversed to find the first unoccupied entry, that is, the entry with an empty process ID, and information is recorded and saved on the entry, and the recorded and saved information includes the process ID, process name and current time corresponding to the lock acquired corresponding to the current process.

[0034] It can be understood that the process identifier corresponding to the current process is automatically assigned to the current process by the system when the process is started, and is a unique attribute value of the current process.

[0035] Figure 4 FIG. 1 is a structural diagram of a write process status area provided according to some embodiments of the present application. Figure 4As shown, the write process status area includes a write process status entry, which includes the process ID, process name and current time corresponding to the write process; the lock occupation time can be calculated according to the current time corresponding to the lock. When the lock occupation time exceeds a certain time, a reminder can be issued to the terminal to remind the user to check.

[0036] In some embodiments, a read lock upper limit value is stored in the shared memory; the read lock upper limit value is the maximum number of read locks provided; by setting the read lock upper limit value, the number of read locks can be limited, so that a fixed-size memory area can be predicted and allocated in advance to save the process identifiers corresponding to each read process, thereby improving the storage efficiency. Therefore, this application sets the read lock upper limit value to limit the number of read locks, thereby realizing a fixed-size lock data structure, thereby ensuring the working efficiency of the lock mechanism.

[0037] In some embodiments, if the read lock upper limit is not set in the shared memory, the process ID needs to be saved indefinitely. Since the number of process IDs changes dynamically, it is impossible to predict in advance and allocate a fixed-size memory area to save the process IDs corresponding to each reading process. The only option is to continuously request and release the saved area in a dynamic manner, thereby reducing the saving efficiency.

[0038] In some embodiments, the read lock upper limit value is set by a dynamic upper limit; exemplarily, the router includes a memory, such as a flash memory, in which an initial read lock upper limit value and an initial write lock value are stored; the first read process requesting the lock reads and saves the initial read lock upper limit value from the flash memory, and requests the read process status area according to the initial read lock upper limit value; the subsequent read processes requesting the lock dynamically modify the read lock upper limit value each time according to the number of processes currently occupying the read lock and the historical simultaneous read lock count; exemplarily, the historical simultaneous read lock count is stored in a shared memory, and the historical simultaneous read lock count represents the maximum count of historical synchronous acquisition of locks; the read lock upper limit value can be dynamically revised through the historical simultaneous read lock count. Exemplarily, according to the read-write lock mechanism, the initial write lock value is 1.

[0039] When the number of processes currently occupying the read lock is greater than the historical simultaneous read lock count, the historical simultaneous read lock count and the read lock upper limit are synchronously modified according to the number of processes currently occupying the read lock, that is, the number of processes currently occupying the read lock is set to the historical simultaneous read lock count, and synchronously, the number of processes currently occupying the read lock is set to the read lock upper limit; when the number of processes currently occupying the read lock is less than the historical simultaneous read lock count, the historical simultaneous read lock count and the read lock upper limit remain unchanged.

[0040] In some embodiments, when the read lock upper limit value changes, it is necessary to re-request a new read process status area; illustratively, when the read lock upper limit value increases, it is necessary to request a read process status area with a larger memory, and copy and save the information in the read process status area corresponding to the read lock upper limit value before the read lock upper limit value changes to the larger read process status area requested at this time, and at the same time release the memory of the read process status area corresponding to the read lock upper limit value before the read lock upper limit value changes.

[0041] In some embodiments, if there is no read process status area in the shared memory, an initial read lock upper limit value is obtained from the flash memory, and then a request is made in the shared memory to obtain the read process status area according to the initial read lock upper limit value, and the initial read lock upper limit value is saved in the read process status area as the read lock upper limit value; correspondingly, if there is no write process status area in the shared memory, a request is made in the shared memory to obtain the write process status area according to the initial write lock value.

[0042] In some embodiments, a read lock upper limit synchronization mark is stored in the shared memory area, and the read lock upper limit synchronization mark is used to indicate whether the read lock upper limit value is modified in real time when the number of occupied read locks exceeds the read lock upper limit value; illustratively, the read lock upper limit synchronization mark includes a first synchronization mark and a second synchronization mark, and the first synchronization mark indicates that when the number of occupied read locks is greater than the read lock upper limit value, the read lock upper limit value is not modified in real time; the second synchronization mark indicates that when the number of occupied read locks is less than the read lock upper limit value, the read lock upper limit value is modified in real time. In some scenarios, when the number of occupied read locks exceeds the read lock upper limit value, the read lock upper limit value can be modified synchronously, and the current number of occupied read locks is modified in real time to the read lock upper limit value, and then the corresponding read process status area is requested according to the real-time modified read lock upper limit value; in some scenarios, when the number of occupied read locks exceeds the read lock upper limit value, the read lock upper limit value is not modified synchronously, and the memory corresponding to the read process status area at this time also remains unchanged; the initial read lock upper limit value in the flash memory is modified by the historical simultaneous read lock count, and the read lock upper limit value and the corresponding read process status area in the shared memory are reset when the system is started next time.

[0043] Figure 5 FIG. 1 is a structural diagram of a historical process status area provided according to some embodiments of the present application. Figure 5 As shown, in some embodiments, a historical process status area is also stored in the shared memory area; the historical process status area includes each read process status parameter and each write process status parameter that have occurred, and each process can be saved in the historical process status area in the order of occurrence; illustratively, the historical process status area stores the historical maximum occupied time of each read lock and the historical maximum occupied time of each write lock.

[0044] In some embodiments, the maximum historical occupied time of the read lock corresponds to the process name, and the first read process lock occupied time corresponding to the process name is saved in the historical process status area, and the lock occupied time is named the initial lock occupied time. If the subsequent read process lock occupied time corresponding to the process name is greater than the initial lock occupied time, the maximum historical occupied time of the read lock under the process name in the historical process status area is updated to the lock occupied time of the current process, otherwise, the initial lock occupied time is still maintained; the maximum historical occupied time of the read lock is iteratively updated in sequence subsequently. The same is true for the maximum historical occupied time of the write lock.

[0045] In the present application, by obtaining the above parameters, when a lock exception problem occurs, corresponding measures are taken to automatically repair the lock exception problem, so that the current process obtains the corresponding lock.

[0046] In some embodiments, when the current read process issues a lock request, if the number of currently occupied read locks exceeds the read lock upper limit, or the write lock is occupied, the current read process will not be able to obtain the corresponding read lock.

[0047] Figure 6 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 1 .like Figure 6 As shown, in some embodiments, the read-write lock control method includes:

[0048] S110: The process that issues the lock request is a read process, the lock state identifier is the third identifier, and the read lock upper limit synchronization identifier is the first synchronization identifier.

[0049] S120: Determine whether the waiting lock time of the current reading process exceeds the preset time.

[0050] S130: If the waiting lock time of the current reading process exceeds the preset time, each process identifier in the reading process status area is traversed, and it is determined whether the process corresponding to each process identifier has exited.

[0051] S140: If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set as a preset identifier in the read process status area.

[0052] In some embodiments, the process that issues the lock request is a read process, and a lock status identifier is obtained; when the lock status identifier is the third identifier and the read lock upper limit synchronization identifier is the first synchronization identifier, it is determined whether the current read process waiting lock time exceeds the preset time.

[0053] If the current read process waits for the lock for longer than the preset time, the process identifiers in the read process status area are traversed to determine whether the processes corresponding to each process identifier have exited; if the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set to the preset identifier in the read process status area to allow the exited process to release the read lock.

[0054] The process that issues the lock request is the read process. It reads the lock status identifier from the shared memory area. If the lock status identifier is the third identifier, it indicates that the number of currently occupied read locks exceeds the read lock upper limit. At the same time, it reads the read lock upper limit synchronization identifier from the shared memory. If the read lock upper limit synchronization identifier is the first synchronization identifier, it indicates that the number of read locks provided remains unchanged, which means that the current read process is likely to be unable to obtain the corresponding read lock.

[0055] By determining whether the current read process has obtained the corresponding read lock, it is determined whether the lock waiting time exceeds the preset time. Exemplarily, the setting of the preset time includes: setting a default timeout, such as 5s; obtaining the maximum occupied time of the read lock history corresponding to the current process name, and then multiplying the maximum occupied time of the read lock history by a coefficient, such as 10, to obtain a value; comparing the value with the default timeout, and setting the maximum of the two as the preset time.

[0056] If the current read process waits for the lock for longer than the preset time, the process identifiers in the read process status area are traversed, and the interface function is called to determine whether the process corresponding to the process identifier has exited. If there is a process that has exited, the process identifier corresponding to the process is set to a preset identifier, such as 0; that is, by setting the process identifier corresponding to the exited process to 0, the read lock occupied by the process is forcibly released, thereby enabling the process to acquire the read lock.

[0057] Exemplarily, when determining whether the process corresponding to the process ID has exited by calling an interface function, each process ID is carried and a request is made to call the interface function. The interface function then feeds back the exited process. The feedback information also includes the process ID corresponding to the exited process. Then, by setting the process ID corresponding to the exited process to 0, the read lock occupied by the process is forcibly released, thereby enabling the process to acquire the read lock.

[0058] In some embodiments, a repair state identifier is also stored in the flash memory; the repair state identifier includes a first repair state identifier and a second repair state identifier, the first repair state identifier indicates that the read lock is allowed to be forcibly released, and the second repair state identifier indicates that the read lock is not allowed to be forcibly released; illustratively, the first repair state identifier is 1, and the second repair state identifier is 2. That is, in some scenarios, it is allowed to forcibly set the process identifier corresponding to the exited read process to 0, and in some scenarios, it is not allowed to forcibly set the process identifier corresponding to the exited read process to 0; therefore, when the exited read process is obtained, the repair state identifier is obtained from the flash memory, and if the repair state identifier is 1, the process identifier corresponding to the exited read process can be set to 0; if the repair state identifier is 2, the process identifier corresponding to the exited read process cannot be set to 0 at this time, and an alarm message can be sent to the terminal to prompt the user to process the process.

[0059] Figure 7 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 2 .like Figure 7 As shown, in some embodiments, the read-write lock control method includes:

[0060] S210: The process that issues the lock request is a read process, and the lock state identifier is the fourth identifier.

[0061] S220: Determine whether the waiting lock time of the current reading process exceeds the preset time.

[0062] S230: If the current read process waits for a lock time that exceeds a preset time, traverse each process ID in the write process status area, and determine whether the process corresponding to each process ID has exited.

[0063] S240: If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set as a preset identifier in the write process status area.

[0064] In some embodiments, the process that issues a lock request is a read process, and a lock status identifier is obtained; when the lock status identifier is the fourth identifier, if the current read process waiting lock time exceeds a preset time, each process identifier in the write process status area is traversed, and it is determined whether the process corresponding to each process identifier has exited; if the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set to the preset identifier in the write process status area to allow the exited process to release the write lock.

[0065] Since in the read-write lock mechanism, the read and write processes are mutually exclusive, if the current process is a write process, it means that the read process cannot obtain the read lock; therefore, when the lock status is identified as the fourth identifier, the fourth identifier indicates that the current write lock is occupied. If the process that issues the lock request next is a read process, the current read process is likely to be unable to obtain the read lock.

[0066] By judging whether the waiting time of the current read process exceeds the preset time, it is confirmed whether the current read process has obtained the read lock; if the waiting time of the current read process exceeds the preset time, it indicates that the current read process has not obtained the read lock. Exemplarily, the setting of the preset time includes: setting a default timeout, such as 5s; obtaining the maximum occupied time of the read lock history corresponding to the current process name, and then multiplying the maximum occupied time of the read lock history by a coefficient, such as 10, to obtain a value; comparing the value with the default timeout, and setting the maximum of the two as the preset time.

[0067] If the current read process waits for the lock for longer than the preset time, indicating that the current read process has not obtained the read lock, the process identifiers in the write process status area are traversed, and the interface function is called to determine whether the process corresponding to each process identifier has exited; if the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set to a preset identifier, such as 0, in the write process status area. That is, by setting the process identifier corresponding to the exited process to 0, the read lock occupied by the process is forcibly released, thereby enabling the process to obtain the read lock.

[0068] Exemplarily, when determining whether the write process corresponding to the process ID has exited by calling an interface function, each process ID is carried and a request is made to call the interface function. The interface function then feeds back the exited process. The feedback information also includes the process ID corresponding to the exited process. Then, by setting the process ID corresponding to the exited process to 0, the write lock occupied by the exited write process is forcibly released, thereby enabling the current read process to obtain the read lock.

[0069] Figure 8 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 3 .like Figure 8 As shown, in some embodiments, the read-write lock control method includes:

[0070] S310: The process that issues the lock request is a read process, and when the lock status identifier is the first identifier or the second identifier, the number of current read lock processes is obtained.

[0071] S320: When the number of current read lock processes is less than the read lock upper limit, the lock status identifier is set to the second identifier so that the current process acquires the read lock, and the process name and current time of the current read process are saved in the read process status area.

[0072] The current time is the current time corresponding to when the lock is acquired.

[0073] S330: When the number of current read lock processes is greater than the read lock upper limit, the lock status identifier is set to the third identifier so that the current process acquires the read lock, and the process name and current time of the current read process are saved in the read process status area.

[0074] The current time is the current time corresponding to when the lock is acquired.

[0075] In some embodiments, the process that issues a lock request is a read process, which obtains a lock status identifier; when the lock status identifier is the first identifier or the second identifier, since the lock status identifier is the first identifier, it indicates that both the read lock and the write lock are not occupied; when the lock status identifier is the second identifier, it indicates that the read lock is occupied and the number of occupied read locks does not exceed the upper limit of the read lock, which indicates that when the lock status identifier is the first identifier or the second identifier, the current read process can obtain the corresponding read lock.

[0076] In some embodiments, when the lock status identifier is the first identifier or the second identifier, the current number of read lock processes is obtained; when the current number of read lock processes is less than the read lock upper limit value, the lock status identifier is set to the second identifier so that the current process acquires the read lock; exemplarily, if the lock status identifier is the first identifier, then when the current number of read lock processes is less than the read lock upper limit value, the lock status identifier is modified from the first identifier to the second identifier, indicating that the read lock is occupied and the number of occupied read locks does not exceed the read lock upper limit value; if the lock status identifier is the second identifier, then when the current number of read lock processes is less than the read lock upper limit value, the lock status identifier is kept as the second identifier. In actual application, even if the current lock status identifier is the second identifier, the lock status identifier is still set to the second identifier at the lock status identifier position; in this application, the lock status identifier is modified so that the current process acquires the read lock.

[0077] In some embodiments, after the lock status identifier is modified, the first blank process identifier in the read process status area is set as the current process identifier, and the process name and current time corresponding to the current process are obtained, and the process name and current time corresponding to the current process are saved in the read process status area. Exemplarily, the current time is the time corresponding to the acquisition of the read lock, and the current time corresponding to the acquisition of the read lock is called the first current time, and the current time corresponding to the release of the lock is called the second current time. The lock occupation time can be obtained by making a difference between the first current time and the second current time, and then the lock occupation time is compared with the historical maximum occupied time corresponding to the process name in the historical process status area to determine whether to iteratively update the historical maximum occupied time under the process name in the historical process status area.

[0078] In some embodiments, when the lock status identifier is the first identifier or the second identifier, the current number of read lock processes is obtained, and when the current number of read lock processes is greater than the read lock upper limit value, the lock status identifier is set to the third identifier so that the current process obtains the read lock; exemplarily, if the lock status identifier is the first identifier, then when the current number of read lock processes is greater than the read lock upper limit value, the read lock is full at this time, and the lock status identifier is modified from the first identifier to the third identifier, indicating that the read lock is full; if the lock status identifier is the second identifier, then when the current number of read lock processes is greater than the read lock upper limit value, the read lock is full at this time, and the lock status identifier is modified from the second identifier to the third identifier; in this application, the lock status identifier is modified so that the current process obtains the read lock.

[0079] In some embodiments, after the lock status identifier is modified, the first blank process identifier in the read process status area is set as the current process identifier, and the process name and current time corresponding to the current process are obtained, and the process name and current time corresponding to the current process are saved in the read process status area. Exemplarily, the current time is the time corresponding to the write lock is obtained; the time the current process occupies the write lock can be obtained through the saved current time.

[0080] In some embodiments, when it is determined that there is a read process that has exited, the current process identifier is set to a preset identifier, such as 0, so that the current process releases the read lock; after releasing the read lock, the current number of read lock processes is obtained, and the lock status identifier is modified; if the current number of read lock processes is greater than 0, the lock status identifier is set to the second identifier; if the current number of read lock processes is greater than 0, and the lock status identifier is the third identifier at this time, the lock status identifier is changed from the third identifier to the second identifier.

[0081] The above are measures taken to automatically repair the lock exception problem when the process issuing the lock request is a read process; the following are measures that can be taken to automatically repair the lock exception problem when the process issuing the lock request is a write process in some embodiments.

[0082] Fig. 9 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 4 .like Fig. 9 As shown, in some embodiments, the read-write lock control method includes:

[0083] S410: The process that issues the lock request is a write process, and if the lock status identifier is the first identifier.

[0084] S420: Set the process ID in the write process status area as the current process ID so that the current write process acquires the write lock, and save the process name and current time corresponding to the current write process to the write process status area.

[0085] S430: Setting the current process identifier to a preset identifier so that the current writing process releases the write lock.

[0086] In some embodiments, the process that issues the lock request is a write process, and a lock status identifier is obtained. If the lock status identifier is a first identifier, since the lock status identifier is the first identifier, indicating that both the read lock and the write lock are not occupied, the process identifier in the write process status area is set to the current process identifier, so that the current write process obtains the write lock, and the process name and current time corresponding to the current write process are saved in the write process status area. In this application, the current process identifier is set so that the current process obtains the write lock.

[0087] In some embodiments, when the current writing process releases the lock normally, the current process identifier of the current writing process may be set to a preset identifier, such as 0, so that the current writing process releases the write lock.

[0088] Fig.10 A method for controlling a home smart gateway read-write lock according to some embodiments of the present application is provided. Figure 5 .like Fig.10 As shown, in some embodiments, the read-write lock control method includes:

[0089] S510: The process that issues the lock request is a write process, and the lock status identifier is a non-first identifier.

[0090] S520: Determine whether the waiting lock time of the current writing process exceeds the preset time.

[0091] S530: If the current write process wait lock time exceeds the preset time, then traverse each process identifier in the read process status area and each process identifier in the write process status area, and determine whether the process corresponding to each process identifier has exited.

[0092] S540: If the read process or write process corresponding to the process identifier has exited, the process identifier corresponding to the exited process in the read process status area is set to the preset identifier, or the process identifier corresponding to the exited process in the write process status area is set to the preset identifier.

[0093] In some embodiments, the process that issues the lock request is a write process. If the lock status identifier is not the first identifier, such as the lock status identifier is the second identifier, or the third identifier, or the fourth identifier, it is determined whether the current write process wait lock time exceeds the preset time.

[0094] If the current write process waits for a lock time that exceeds a preset time, each process identifier in the read process status area and each process identifier in the write process status area are traversed, and it is determined whether the process corresponding to each process identifier has exited.

[0095] If a read process corresponding to a process ID has exited, the process ID corresponding to the read process is set to a preset ID, such as 0, so that the current read process releases the read lock; then an attempt is made to acquire the write lock until the write lock is acquired.

[0096] If the writing process corresponding to the process ID has exited, the process ID corresponding to the exited process in the writing process status area is set to a preset ID, such as 0, so that the current writing process releases the writing lock; then try to acquire the writing lock.

[0097] In some embodiments, if the read lock is processed, a repair state identifier is also stored in the flash memory; the repair state identifier includes a first repair state identifier and a second repair state identifier, the first repair state identifier indicates that the write lock is allowed to be forcibly released, and the second repair state identifier indicates that the write lock is not allowed to be forcibly released; illustratively, the first repair state identifier is 1, and the second repair state identifier is 2. That is, in some scenarios, it is allowed to forcibly set the process identifier corresponding to the exited write process to 0, and in some scenarios, it is not allowed to forcibly set the process identifier corresponding to the exited write process to 0; therefore, when the exited write process is obtained, the repair state identifier is obtained from the flash memory, and if the repair state identifier is 1, the process identifier corresponding to the exited write process can be set to 0; if the repair state identifier is 2, the process identifier corresponding to the exited write process cannot be set to 0 at this time, and an alarm message can be sent to the terminal to prompt the user to process the process.

[0098] In the home smart gateway and read-write lock control method provided by the present application, by recording and saving the process ID of each process, when a process waits for a lock for a long time, the process ID can be traversed to determine whether the process corresponding to the process ID has exited. If the process corresponding to the process ID has exited, the exited process is forced to release the corresponding lock, and the abnormal read lock problem is automatically corrected, so that the current read process can obtain the read lock; at the same time, the present application sets the read lock upper limit value to limit the number of read locks, thereby realizing a fixed-size lock data structure, thereby ensuring the working efficiency of the lock mechanism.

[0099] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A home smart gateway, characterized in that: include: A shared memory area, which internally stores a lock status identifier, a read lock upper limit synchronization identifier, a read lock upper limit value, a read process status area, and a write process status area, wherein the read process status area includes a process identifier corresponding to a process requesting a read lock, and the write process status area includes a process identifier corresponding to a process requesting a write lock; The processor is configured as: The process that issues the lock request is a read process, and when the lock status identifier is the third identifier and the read lock upper limit synchronization identifier is the first synchronization identifier, if the current read process waits for the lock time to exceed the preset time, then the process identifiers in the read process status area are traversed, and it is determined whether the process corresponding to each process identifier has exited; wherein the third identifier indicates that the number of occupied read locks exceeds the read lock upper limit value, and the first synchronization identifier indicates that when the number of occupied read locks is greater than the read lock upper limit value, the read lock upper limit value is not modified in real time; If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set as a preset identifier in the read process status area, so that the exited process releases the read lock; The process that issues the lock request is a read process. When the lock status identifier is the fourth identifier, if the current read process waits for the lock time beyond the preset time, each process identifier in the write process status area is traversed, and it is determined whether the process corresponding to each process identifier has exited; wherein the fourth identifier indicates that the write lock is occupied; If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set as a preset identifier in the write process status area, so that the exited process releases the write lock.

2. The home smart gateway according to claim 1, characterized in that: The processor is configured to: The process that issues the lock request is a write process. If the lock status identifier is the first identifier, the process identifier in the write process status area is set as the current process identifier, so that the current write process obtains the write lock, and the process name and current time corresponding to the current write process are saved in the write process status area; wherein the first identifier indicates that both the read lock and the write lock are not occupied; The current process identifier is set to a preset identifier so that the current writing process releases the write lock; The process that issues the lock request is a writing process, and if the lock status identifier is not the first identifier, determining whether the current writing process waits for the lock time to exceed a preset time; If the current write process wait lock time exceeds the preset time, then traverse each process identifier in the read process status area and each process identifier in the write process status area, and determine whether the process corresponding to each process identifier has exited; If there is a reading process corresponding to the process identifier that has been exited, the process identifier corresponding to the exited process in the reading process status area is set as a preset identifier; If there is a writing process corresponding to the process identifier that has been exited, the process identifier corresponding to the exited process in the writing process status area is set as a preset identifier.

3. The home smart gateway according to claim 2, characterized in that: The lock status identifier also includes a second identifier, which indicates that the read lock is occupied and the number of occupied read locks does not exceed the upper limit of the read lock; The processor is configured to: The process that issues the lock request is a read process, and when the lock state identifier is the first identifier or the second identifier, the number of current read lock processes is obtained; When the number of current read lock processes is less than the read lock upper limit, the lock state identifier is set to the second identifier so that the current process acquires the read lock; and setting the first blank process identifier in the read process status area as the current process identifier; When the number of current read lock processes is greater than the read lock upper limit, the lock state identifier is set to a third identifier so that the current process acquires the read lock; and setting the first blank process identifier in the read process status area as the current process identifier; When the first blank process identifier in the read process status area is set as the current process identifier, the process name and current time corresponding to the current process are obtained, and the process name and current time corresponding to the current process are saved in the read process status area.

4. The home smart gateway according to claim 3, characterized in that: The processor is configured to: Set the current process ID to the preset ID so that the current process releases the read lock; Get the current number of read lock processes; When the number of current lock reading processes is greater than 0 and the lock status identifier is the second identifier, the lock status identifier is not modified or is set to the second identifier; When the current number of read lock processes is greater than 0 and the lock state identifier is the third identifier, the lock state identifier is set to the second identifier.

5. The home smart gateway according to claim 1, characterized in that: The processor is configured to: When the lock state identifier is the third identifier, the historical simultaneous read lock count is incremented by 1, and the read lock upper limit synchronization identifier is obtained; If the read lock upper limit synchronization identifier is the second synchronization identifier, then requesting to update the read process status area in the shared memory according to the incremented historical simultaneous read lock count; wherein the historical simultaneous read lock count is stored in the shared memory, and the second synchronization identifier indicates that when the number of occupied read locks is greater than the read lock upper limit value, the read lock upper limit value is modified in real time; Saving the information in the read process status area to the updated read process status area; The value corresponding to the incremented historical simultaneous read lock count is set as the read lock upper limit.

6. The home smart gateway according to claim 1, characterized in that: The home intelligent gateway also includes a memory; The memory stores an initial read lock upper limit value and an initial write lock value; When there is no read process status area in the shared memory, requesting in the shared memory according to the initial read lock upper limit value to obtain the read process status area, and saving the initial read lock upper limit value as the read lock upper limit value in the read process status area; When the shared memory does not have a write process status area, a request is made in the shared memory according to the initial write lock value to obtain the write process status area.

7. The home smart gateway according to claim 3, characterized in that: The shared memory includes a historical process status area, and the historical process status area stores the maximum historical occupied time of the read lock corresponding to each process name and the maximum historical occupied time of the write lock corresponding to each process name; The processor is configured to: determine whether the waiting lock time of the current read process exceeds a preset time; Determine whether the current read process wait lock time exceeds the preset time, including: Set the default timeout period; Get the maximum historical occupied time of the read lock corresponding to the current process name; Obtaining the preset time according to the default timeout time and the maximum occupied time of the read lock history; Determine whether the waiting time for the current read process is greater than the preset time; The processor is configured to: determine whether the current write process waiting lock time exceeds a preset time; Determine whether the current write process lock time exceeds the preset time, including: Set the default timeout period; Get the maximum historical occupied time of the write lock corresponding to the current process name; Obtaining the preset time according to the default timeout time and the maximum occupied time of the write lock history; Determine whether the lock waiting time of the current writing process is greater than the preset time.

8. The home smart gateway according to claim 6, characterized in that: The memory includes a repair state identifier, the repair state identifier includes a first repair state identifier and a second repair state identifier, the first repair state identifier indicates that forced release of the lock is allowed, and the second repair state identifier indicates that forced release of the lock is not allowed; The processor is configured to: Traversing each process identifier in the read process status area, and determining whether the process corresponding to each process identifier has exited; If the process corresponding to the process identifier has exited, obtaining the repair status identifier; If the repair status identifier is the first repair status identifier, setting the process identifier corresponding to the exited process in the read process status area to a preset identifier; If the repair status identifier is the second repair status identifier, an alarm message is sent to the terminal.

9. The home smart gateway according to claim 8, characterized in that: The processor is configured to: Traversing each process identifier in the write process status area, and determining whether the process corresponding to each process identifier has exited; If the process corresponding to the process identifier has exited, obtaining the repair status identifier; If the repair status identifier is the first repair status identifier, setting the process identifier corresponding to the exited process in the write process status area to a preset identifier; If the repair status identifier is the second repair status identifier, an alarm message is sent to the terminal.

10. A method for controlling a home smart gateway read-write lock, characterized in that: The home smart gateway includes a shared memory area, wherein the shared memory area stores a lock status identifier, a read lock upper limit synchronization identifier, a read lock upper limit value, a read process status area, and a write process status area, wherein the read process status area includes a process identifier corresponding to a process requesting a read lock; the write process status area includes a process identifier corresponding to a process requesting a write lock; and the method includes: The process that issues the lock request is a read process, and when the lock status identifier is the third identifier and the read lock upper limit synchronization identifier is the first synchronization identifier, if the current read process waits for the lock time to exceed the preset time, then the process identifiers in the read process status area are traversed, and it is determined whether the process corresponding to each process identifier has exited; wherein the third identifier indicates that the number of occupied read locks exceeds the read lock upper limit value, and the first synchronization identifier indicates that when the number of occupied read locks is greater than the read lock upper limit value, the read lock upper limit value is not modified in real time; If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set as a preset identifier in the read process status area, so that the exited process releases the read lock; The process that issues the lock request is a read process. When the lock status identifier is the fourth identifier, if the current read process waits for the lock time beyond the preset time, each process identifier in the write process status area is traversed, and it is determined whether the process corresponding to each process identifier has exited; wherein the fourth identifier indicates that the write lock is occupied; If the process corresponding to the process identifier has exited, the process identifier corresponding to the exited process is set as a preset identifier in the write process status area, so that the exited process releases the write lock.