home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / utilities / countervar_2 / CounterMsg < prev    next >
Text File  |  1997-03-05  |  2KB  |  29 lines

  1. © Copyright Nicholas Clark 1997
  2. Based on the code variable example in the PRM
  3.  
  4. CounterVar is a short (140 bytes) utility to create an OS variable which acts as a counter. Every time this variable is read, its value is automatically incremented. It is designed to be replace parts of code that currently read, increment and write a conventional environment variable (eg the UnixLib pipe counter)
  5.  
  6. The utility is able to create any number of counter variables - call it once for each counter to create. The name of the variable to create is supplied as the first parameter, the optional second parameter is the initial value (defaults to zero)
  7.  
  8. Syntax: CounterVar <Name> [<Initial Value>]
  9.  
  10. CounterHex counts in hexadecimal rather than decimal (and always generates exactly 8 character output.)
  11.  
  12. The counter variable is implemented as a code variable - the advantages of this method over reading, modifying and writing a conventional variable from inside your code are:
  13.  
  14. 0: The code variable method is almost certainly more compact.
  15. 1: This method will be faster - only one SWI call to read the variable, none to
  16.    write it back
  17. 2: [As long as you aren't trying to read the counter under interrupts] you can't
  18.    accidentally read the same value twice.
  19.    Using a conventional variable, two programs running in task windows can, if
  20.    one is unlucky enough to read the value just after a second program has read
  21.    it, but just before the second program writes back the incremented value.
  22.  
  23. Currently you can write back to the variable to set the counter to that value - I'm not sure if this is a good thing, but it does allow programs that are not aware of the auto-increment to treat this variable as if it were nothing special.
  24.  
  25. Hopefully the source serves as an example of how to write a transient utility, and how to write a code variable.
  26.  
  27. I would prefer it it if you distribute the source with the executable
  28. Feel free to use this in anything free. Feel free to modify/improve it.
  29. Feel obliged to send me any bug fixes at <nickc@done.net>