The present disclosure relates to a semaphore setting device and a method for setting a semaphore, especially to a semaphore setting device and a method for setting a semaphore that adopts an address mapping manner.
In resource operation applications, semaphores can be utilized for mutual exclusion protection among processes. However, in multi-core processor applications, if each core has multiple processes, and each process can compete for the same semaphore, users will be unable to know which process competes for and utilizes the above-mentioned semaphore.
For determining whether the semaphore is occupied, the value of the corresponding register associated with the semaphore should be read first to determine whether the above-mentioned semaphore is occupied. If the above-mentioned semaphore is unoccupied, multiple processes will compete for the above-mentioned semaphore. Additionally, to identify which process has competed for and utilized the above-mentioned semaphore, the value of the corresponding register associated with the above-mentioned semaphore should be read again. Consequently, the operation needs to read the above-mentioned semaphore repeatedly, such that the efficiency of the operation is low. In addition, the real-time performance of the operation is low, and it is hard to obtain real-time information of occupation status of the above-mentioned semaphore effectively.
In some aspects, an object of the present disclosure is to, but not limited to, provides a semaphore setting device and a method for setting a semaphore that makes an improvement to the prior art.
An embodiment of a semaphore setting device of the present disclosure includes a mapping circuit and a read setting circuit. The mapping circuit is configured to map at least one semaphore of a plurality of semaphores to at least one address of a plurality of addresses. The read setting circuit is coupled to the mapping circuit and configured to determine whether the at least one semaphore is occupied according to the at least one address when receiving a read request. If the read setting circuit determines that the at least one semaphore is unoccupied, the read setting circuit returns an unoccupied signal and sets the at least one semaphore to be occupied.
An embodiment of a method for setting a semaphore of the present disclosure includes: mapping at least one semaphore of a plurality of semaphores to at least one address of a plurality of addresses by a mapping circuit; determining whether the at least one semaphore is occupied according to the at least one address when receiving a read request by a read setting circuit; and if the read setting circuit determines that the at least one semaphore is unoccupied, returning an unoccupied signal and setting the at least one semaphore to be occupied by the read setting circuit.
Technical features of some embodiments of the present disclosure make an improvement to the prior art. Compared to the prior art, the semaphore setting device and the method for setting the semaphore of the present disclosure enhance operation efficiency of the semaphore and obtain real-time information of occupation status of the semaphore effectively.
These and other objectives of the present invention will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiments that are illustrated in the various figures and drawings.
The present disclosure adopts semaphores to be mutual exclusion protection among processes, such that the resource can be exclusively utilized at the same time. Furthermore, for enhancing the operation efficiency of the semaphores and obtain real-time information of occupation status of the semaphores effectively, the present disclosure adopts the mapping circuit 110 to map a plurality of semaphores to a plurality of addresses, such that the operation efficiency of the semaphores can be enhanced through reading corresponding addresses of the semaphores, which will be explained in detail as below.
For facilitating the understanding of the mapping manner between semaphores and addresses, reference is now made to both
In some embodiments, the read setting circuit 120 is configured to determine whether the semaphore is occupied according to corresponding address of the semaphore when receiving a read request. If the read setting circuit 120 determines that the semaphore is unoccupied, the read setting circuit 120 returns an unoccupied signal, and sets the semaphore to be occupied. For example, the read setting circuit 120 determines whether the semaphore S0 is occupied according to the corresponding addresses B0˜B31 of the semaphore S0 when receiving the read request of the semaphore S0. If the read setting circuit 120 determines that the semaphore S0 is unoccupied, the read setting circuit 120 returns the unoccupied signal (e.g., returning 0) to the sender of the read request, and the semaphore S0 can be preset to be occupied to ensure that the sender of the read request can compete for and utilize the semaphore S0.
After determining whether the semaphore of the prior art is occupied by reading the semaphore, the semaphore of the prior art should be read again to identify whether the semaphore is competed for and utilized. Compared to the prior art, the semaphore setting device 100 of the present disclosure adopts the mapping circuit 110 to map the status of the semaphore to the corresponding address, and adopts the read setting circuit 120 to read the corresponding address to obtain real-time information of occupation status of the semaphore for knowing whether the semaphore can be obtained or not. As a result, the semaphore setting device 100 of the present disclosure does not need to read the status of the semaphore repeatedly, such that the operation efficiency of the semaphore setting device 100 can be enhanced.
In some embodiments, for presetting the semaphore to be occupied to ensure that the sender of the read request can compete for and utilize the semaphore, the read setting circuit 120 can set a setting value of the corresponding address to be a high level value to set the semaphore to be occupied. For example, the read setting circuit 120 can set the setting value of the corresponding addresses B0˜B31 of the semaphore S0 to be 1 to set the semaphore S0 to be occupied, such that the semaphore S0 cannot be occupied by other processes to ensure the sender of the read request can compete for and utilize the semaphore S0.
In some embodiments, the read setting circuit 120 reads a setting value of the corresponding address to determine whether the semaphore is occupied when receiving the read request. If the setting value of the address includes a low level value, the read setting circuit 120 determines that the semaphore is unoccupied, and returns an unoccupied signal. For example, the read setting circuit 120 reads the setting value of the corresponding addresses B0˜B31 of the semaphore S0 to determine whether the semaphore S0 is occupied when receiving a read request of the semaphore S0. If the setting value of the corresponding addresses B0˜B31 is 0, the read setting circuit 120 determines that the semaphore S0 is unoccupied, and returns an unoccupied signal (e.g., returning 0) to the sender of the read request.
In some embodiments, if the read setting circuit 120 determines that the semaphore (e.g., the semaphore S0) is occupied, the read setting circuit 120 returns an occupied signal (e.g., returning 1) to the sender of the read request.
In some embodiments, the read setting circuit 120 reads a setting value of the corresponding address to determine whether the semaphore is occupied when receiving the read request. If the setting value of the corresponding address includes a high level value, the read setting circuit 120 determines that the semaphore is occupied, and returns an occupied signal to the sender of the read request. For example, the read setting circuit 120 reads the setting value of the corresponding addresses B0˜B31 of the semaphore S0 to determine whether the semaphore S0 is occupied when receiving the read request of the semaphore S0. If the setting value of the corresponding addresses B0˜B31 is 1, the read setting circuit 120 determines that the semaphore S0 is occupied, and returns the occupied signal (e.g., returning 1) to the sender of the read request.
In some embodiments, the write setting circuit 130 is configured to set the semaphore to be unoccupied according to the corresponding address when receiving a write request. For example, when releasing the semaphore S0, the write setting circuit 130 sets the semaphore S0 to be unoccupied according to the corresponding addresses B0˜B31 of the semaphore S0 when receiving the write request of the semaphore S0. Furthermore, when the write setting circuit 130 receives the write request of the semaphore S0, the write setting circuit 130 writes 0 to the corresponding addresses B0˜B31 of the semaphore S0 to set the semaphore S0 to be unoccupied for releasing the semaphore S0.
In some embodiments, the status query circuit 140 is configured to query whether the semaphore is occupied according to a temporary storage value of the corresponding semaphore. If the status query circuit 140 determines that the semaphore is unoccupied, the status query circuit 140 returns an unoccupied signal. If the status query circuit 140 determines that the semaphore is occupied, the status query circuit 140 returns the occupied signal. For example, the status query circuit 140 can be implemented by registers. For example, the status query circuit 140 may consist of two 32-bit registers for storing 64 semaphores S0˜S63 correspondingly. When querying the occupation status of the semaphores S0˜S63, real-time information of the occupation status of the semaphores S0˜S63 can be obtained effectively through the temporary storage value of the registers in the status query circuit 140.
It is noted that the present disclosure is not limited to the embodiments as shown in
In step 310, mapping at least one semaphore of a plurality of semaphores to at least one address of a plurality of addresses by a mapping circuit 110. For example, the mapping circuit 110 can be utilized to map the semaphore S0 of a plurality of semaphores S0˜S63 to a plurality of addresses B0˜B31 of the address space, map the semaphore S1 of the plurality of semaphores S0˜S63 to the plurality of addresses B0˜B31 of the address space, and so on, until all semaphores S0˜S63 are mapped to the corresponding addresses of the address space.
In step 320, determining whether the at least one semaphore is occupied according to the at least one address when receiving a read request by a read setting circuit 120. For example, when the read setting circuit 120 receives the read request of the semaphore S0, the read setting circuit 120 determines whether the semaphore S0 is occupied according to the corresponding addresses B0˜B31 of the semaphore S0.
In step 330, if the read setting circuit 120 determines that the at least one semaphore is unoccupied, returning an unoccupied signal to the sender of the read request and setting the at least one semaphore to be occupied by the read setting circuit 120. For example, if the read setting circuit 120 determines that the semaphore S0 is unoccupied, the read setting circuit 120 returns the unoccupied signal (e.g., returning 0) to the sender of the read request, and presets the semaphore S0 to be occupied to ensure that the sender of the read request can compete for and utilize the semaphore S0.
In some embodiments, referring to step 320, the method 300 for setting the semaphore can further utilize the read setting circuit 120 to read the setting value of the corresponding addresses B0˜B31 of the semaphore S0 to determine whether the semaphore S0 is occupied when the read setting circuit 120 receives the read request of the semaphore S0. If the setting value of the corresponding addresses B0˜B31 is 0, the read setting circuit 120 determines that the semaphore S0 is unoccupied, and returns the unoccupied signal (e.g., returning 0) to the sender of the read request.
In some embodiments, referring to step 330, the method 300 for setting the semaphore can further utilize the read setting circuit 120 to set the setting value of the corresponding addresses B0˜B31 of the semaphore S0 to be 1 to set the semaphore S0 to be occupied, such that the semaphore S0 cannot be occupied by other processes to ensure the sender of the read request can compete for and utilize the semaphore S0.
In some embodiments, the method 300 for setting the semaphore further includes the following step. If the read setting circuit 120 determines that the semaphore S0 is occupied, the read setting circuit 120 returns the occupied signal to the sender of the read request. For example, the read setting circuit 120 reads the setting value of the corresponding addresses B0˜B31 of the semaphore S0 to determine whether the semaphore S0 is occupied when receiving the read request of the semaphore S0. If the setting value of the corresponding addresses B0˜B31 is 1, the read setting circuit 120 determines that the semaphore S0 is occupied, and returns the occupied signal (e.g., returning 1) to the sender of the read request.
In some embodiments, the method 300 for setting the semaphore further includes the following step. When releasing the semaphore S0, the write setting circuit 130 sets the semaphore S0 to be unoccupied according to the corresponding addresses B0˜B31 of the semaphore S0 when receiving the write request of the semaphore S0. Furthermore, when the write setting circuit 130 receives the write request of the semaphore S0, the write setting circuit 130 writes 0 to the corresponding addresses B0˜B31 of the semaphore S0 to set the semaphore S0 to be unoccupied for releasing the semaphore S0.
In some embodiments, the method 300 for setting the semaphore further includes the following step. The status query circuit 140 can be utilized to query whether the semaphore is occupied according to a temporary storage value of the corresponding semaphore efficiently. If the status query circuit 140 determines that the semaphore is unoccupied, the status query circuit 140 returns the unoccupied signal (e.g., returning 0). If the status query circuit 140 determines that the semaphore is occupied, the status query circuit 140 returns the occupied signal (e.g., returning 1).
It is noted that the present disclosure is not limited to the embodiments as shown in
As described above, technical features of some embodiments of the present disclosure make an improvement to the prior art. After determining whether the semaphore of the prior art is occupied by reading the semaphore, the semaphore of the prior art should be read again to identify whether the semaphore is competed for and utilized. Compared to the prior art, the semaphore setting device 100 and the method 300 for setting the semaphore of the present disclosure adopt the mapping circuit 110 to map the status of the semaphore to the corresponding address, and adopt the read setting circuit 120 to read the corresponding address to obtain real-time information of occupation status of the semaphore for knowing whether the semaphore can be obtained or not. As a result, the semaphore setting device 100 and the method 300 for setting the semaphore of the present disclosure do not need to read the status of the semaphore repeatedly, such that the operation efficiency of the semaphore setting device 100 and the method 300 for setting the semaphore can be enhanced. When querying the occupation status of the semaphore, the semaphore setting device 100 and the method 300 for setting the semaphore of the present disclosure obtain real-time information of the occupation status of the semaphore effectively through the temporary storage value of the registers in the status query circuit 140.
It is noted that people having ordinary skill in the art can selectively use some or all of the features of any embodiment in this specification or selectively use some or all of the features of multiple embodiments in this specification to implement the present invention as long as such implementation is practicable; in other words, the way to implement the present invention can be flexible based on the present disclosure.
The aforementioned descriptions represent merely the preferred embodiments of the present invention, without any intention to limit the scope of the present invention thereto. Various equivalent changes, alterations, or modifications based on the claims of the present invention are all consequently viewed as being embraced by the scope of the present invention.
Number | Date | Country | Kind |
---|---|---|---|
202311545079.1 | Nov 2023 | CN | national |