Podrobná bibliografie
| Název: |
LOCK-FREE RING BUFFER |
| Document Number: |
20220327056 |
| Datum vydání: |
October 13, 2022 |
| Appl. No: |
17/454475 |
| Application Filed: |
November 10, 2021 |
| Abstrakt: |
According to at least one embodiment, a method for writing, by a computing thread, data to a ring buffer is disclosed. The method includes determining whether the ring buffer is full. If the ring buffer is not full, the method further includes: reserving an element of the ring buffer for writing the data, wherein reserving the element includes incrementing a size variable corresponding to a number of stored elements in the ring buffer; reserving a portion of the ring buffer at which the data is to be written; and determining whether a state of the portion of the ring buffer is in change by at least one other computing thread. If the state is not in change, the method further includes: marking the state of the portion of the ring buffer as being in change by the computing thread; and writing the data to the portion of the ring buffer. |
| Assignees: |
DreamWorks Animation LLC (Glendale, CA, US) |
| Claim: |
1. A method for writing, by a computing thread, data to a ring buffer, the method comprising: determining whether the ring buffer is full; and in response to determining that the ring buffer is not full: reserving an element of the ring buffer for writing the data, wherein reserving the element comprises incrementing a size variable corresponding to a number of stored elements in the ring buffer; reserving a portion of the ring buffer at which the data is to be written; determining whether a state of the portion of the ring buffer is in change by at least one other computing thread; and in response to determining that the state of the portion of the ring buffer is not in change by the at least one other computing thread: marking the state of the portion of the ring buffer as being in change by the computing thread; and writing the data to the portion of the ring buffer. |
| Claim: |
2. The method of claim 1, wherein determining whether the ring buffer is full is based on an atomic variable that represents the number of stored elements in the ring buffer. |
| Claim: |
3. The method of claim 1, wherein: the portion of the ring buffer comprises a plurality of elements associated with the ring buffer; and reserving the portion of the ring buffer comprises reserving each element of the plurality of elements such that each element corresponds to a different index of the ring buffer. |
| Claim: |
4. The method of claim 3, wherein determining whether the state of the portion is in change by the at least one other computing thread comprises determining whether a state of each element of the plurality of elements is in change by at least one other computer thread. |
| Claim: |
5. The method of claim 1, wherein determining whether the state of the portion of the ring buffer is in change by the at least one other computing thread is based on a state variable having one of at least three values. |
| Claim: |
6. The method of claim 5, wherein: a first value of the state variable corresponds to an unoccupied state; a second value of the state variable corresponds to an in-transition state; and a third value of the state variable corresponds to an occupied state. |
| Claim: |
7. The method of claim 6, wherein marking the state of the portion of the ring buffer as being in change by the computing thread comprises marking (updating) the state variable to have the second value. |
| Claim: |
8. The method of claim 6, wherein: the portion of the ring buffer comprises a plurality of elements associated with the ring buffer; and marking the state of the portion of the ring buffer as being in change by the computing thread comprises marking (updating) the state variable of a corresponding at least one element of the plurality of elements to have the second value. |
| Claim: |
9. The method of claim 8, wherein writing the data to the portion of the ring buffer comprises writing a respective subset of the data to the corresponding at least one element of the plurality of elements. |
| Claim: |
10. The method of claim 6, further comprising: in response to writing the data to the portion of the ring buffer, marking (updating) the state variable to have the third value. |
| Claim: |
11. A machine-readable non-transitory medium having stored thereon machine-executable instructions for writing, by a computing thread, data to a ring buffer, the instructions comprising: determining whether the ring buffer is full; and in response to determining that the ring buffer is not full: reserving an element of the ring buffer for writing the data, wherein reserving the element comprises incrementing a size variable corresponding to a number of stored elements in the ring buffer; reserving a portion of the ring buffer at which the data is to be written; determining whether a state of the portion of the ring buffer is in change by at least one other computing thread; and in response to determining that the state of the portion of the ring buffer is not in change by the at least one other computing thread: marking the state of the portion of the ring buffer as being in change by the computing thread; and writing the data to the portion of the ring buffer. |
| Claim: |
12. The machine-readable non-transitory medium of claim 11, wherein determining whether the ring buffer is full is based on an atomic variable that represents the number of stored elements in the ring buffer. |
| Claim: |
13. The machine-readable non-transitory medium of claim 11, wherein: the portion of the ring buffer comprises a plurality of elements associated with the ring buffer; and reserving the portion of the ring buffer comprises reserving each element of the plurality of elements such that each element corresponds to a different index of the ring buffer. |
| Claim: |
14. The machine-readable non-transitory medium of claim 13, wherein determining whether the state of the portion is in change by the at least one other computing thread comprises determining whether a state of each element of the plurality of elements is in change by at least one other computer thread. |
| Claim: |
15. The machine-readable non-transitory medium of claim 11, wherein determining whether the state of the portion of the ring buffer is in change by the at least one other computing thread is based on a state variable having one of at least three values. |
| Claim: |
16. The machine-readable non-transitory medium of claim 15, wherein: a first value of the state variable corresponds to an unoccupied state; a second value of the state variable corresponds to an in-transition state; and a third value of the state variable corresponds to an occupied state. |
| Claim: |
17. The machine-readable non-transitory medium of claim 16, wherein marking the state of the portion of the ring buffer as being in change by the computing thread comprises marking (updating) the state variable to have the second value. |
| Claim: |
18. The machine-readable non-transitory medium of claim 16, wherein: the portion of the ring buffer comprises a plurality of elements associated with the ring buffer; marking the state of the portion of the ring buffer as being in change by the computing thread comprises marking (updating) the state variable of a corresponding at least one element of the plurality of elements to have the second value; and writing the data to the portion of the ring buffer comprises writing a respective subset of the data to the corresponding at least one element of the plurality of elements. |
| Claim: |
19. The machine-readable non-transitory medium of claim 16, further comprising: in response to writing the data to the portion of the ring buffer, marking (updating) the state variable to have the third value. |
| Claim: |
20. A method for reading data from a ring buffer by a computing thread, the method comprising: determining whether the ring buffer is empty; in response to determining that the ring buffer is not empty: clearing an element of the ring buffer storing the data, wherein clearing the element comprises decrementing a size variable corresponding to a number of stored elements in the ring buffer; identifying a portion of the ring buffer from which the data is to be read; determining whether a state of the portion of the ring buffer is in change by at least one other computing thread; and in response to determining that the state of the portion is not in change by the at least one other computing thread: marking the state of the portion of the ring buffer as being in change by the computing thread; reading the data from the portion of the ring buffer; and destroying the data in the portion of the ring buffer. |
| Current International Class: |
06; 06 |
| Přístupové číslo: |
edspap.20220327056 |
| Databáze: |
USPTO Patent Applications |