#174963 - shotgunninja - Tue Aug 10, 2010 5:43 pm
Hello, my name is Nick Iannone, and I've recently started working on an engine for the Nintendo DS, using libnds. I'm posting this here, because (1) it's more about C++ than anything else, and (2) because it applies to both GBA and NDS development.
I'm currently working on a set of basic, interrupt-safe nonblocking data structures for GBA/DS development. They are based loosely on the works of Timothy Harris, et al. of the University of Cambridge. The purpose and use of these data structures is to allow safe, nonblocking data structure access from both the main program and from interrupt service routines, without disturbing the natural flow of the program.
Since there is no atomic Compare-and-Store instruction on the ARM9 (that I know of), I use a Monitor-Object-like dummy-lock system which stores the future value of a property in the lock, does what it has to, then overwrites the property and clears the lock. If a method is called in the interrupt while the lock is active in the main program, it uses the states of the lock and the property to determine the stage of the method in the main program, and adjust the stored values as necessary.
Since all values are sampled and tested as conditions for the lock, there is a small risk that (if the interrupt occurs between the load and compare operations) this value will be invalid, but since this is interrupt-based, not thread-based, the operation will complete and unlock in the interrupt before this becomes an issue in the main program.
I have yet to do some testing on some situations, but I have completed initial coding of the Interrupt-Safe Stack, and I will post code for it shortly. Please let me know what you think, and if there is any way to improve upon this.
I'm currently working on a set of basic, interrupt-safe nonblocking data structures for GBA/DS development. They are based loosely on the works of Timothy Harris, et al. of the University of Cambridge. The purpose and use of these data structures is to allow safe, nonblocking data structure access from both the main program and from interrupt service routines, without disturbing the natural flow of the program.
Since there is no atomic Compare-and-Store instruction on the ARM9 (that I know of), I use a Monitor-Object-like dummy-lock system which stores the future value of a property in the lock, does what it has to, then overwrites the property and clears the lock. If a method is called in the interrupt while the lock is active in the main program, it uses the states of the lock and the property to determine the stage of the method in the main program, and adjust the stored values as necessary.
Since all values are sampled and tested as conditions for the lock, there is a small risk that (if the interrupt occurs between the load and compare operations) this value will be invalid, but since this is interrupt-based, not thread-based, the operation will complete and unlock in the interrupt before this becomes an issue in the main program.
I have yet to do some testing on some situations, but I have completed initial coding of the Interrupt-Safe Stack, and I will post code for it shortly. Please let me know what you think, and if there is any way to improve upon this.