TimingUtilities 1.0.12
A small compiled library for C timing with greater precision than default time.h library.
|
This is a small compiled library for C
timing functions with higher precision than time.h
This is primarily used for generating "clock threads." That can help add interrupts with arbitrary precision for example while running some timed state within a larger state machine multi-threaded or networked application.
Consider the following basic application, which just creates a thread and then sleeps a bit, stops the thread, and then prints out the number of tick cycles and total time elapsed based on the system time differences:
Note how the data is shared in this thread. We can access the shared data structure safely using pthread_mutex_lock(&mutex);
to ensure synchronization in case we want to share this data structure with other threads.
To re-compile the static link library (.lib
), use the following command:
Assume we have the following project folder structure:
To compile, you would use the following command:
Note that to use gcc
on a Windows 64-bit architecture, the simplest way is to download msys2
, which will allow you to use pacman
from an msys2
terminal. You can first check to see if you already have gcc
installed:
If you see anything in the terminal following this command, it means you already have gcc
. Otherwise, you need to install it (and probably the rest of the toolchain, such as a linker etc.):
This will give several options for what you can install. If you are unsure what to do, just install all of them.
Finally, you may also want a toolchain for compiling 32-bit applications from your 64-bit Windows operating system. In that case, you can try:
The last step is to make sure the folder with the correct binaries are on your PATH
environment variable. Probably the best strategy here, on a Windows device, is as follows:
MINGW_PATH
. If you installed msys2
in the default location, then go to C:/mingw64
. You will be looking for the sub-folder containing binaries. In my install, that is located at C:\msys64\mingw64\bin
– so that is my MINGW_PATH
environment variable. Path
. Click Edit...
with Path
selected. New
to add a new Path
value. Enter MINGW_PATH
(note that in Windows, you need a % sign on either side of the environment variable while in other OS you typically use $ leading the environment variable). Now, you can add or remove MINGW_PATH
from the user Path
variable depending on what compiler needs you have. Click on the newly added value, and click Move Up
until it is at the top of the list. This ensures we don't accidentally find gcc
somewhere else and use a different unintended version. Note that if you want to switch between i.e. C:\msys64\mingw32\bin
and C:\msys64\mingw64\bin
it might just be easiest to change the value of MINGW_PATH
environment variable.