In my application I would like to implement an efficient data logger that would print traces to a file. The application runs on Beaglebone Black and there are some soft time critical spots. That's why I wouldn't like to simply print traces on the go as that would slow down the application. I was wondering about creating a singleton datalogger class that would do this. Now I am wondering about saving traces to string variables that are pushed to a list. Items are then taken from the list in a separate thread and saved to file.
Now the way I know how to do it is to check either the list length is bigger than 0 in that separate thread every couple of ms, ie every 100ms using sleep. The thing is that the more frequently I check, the more processor power is going to be consumed. I know that there are Linux mechanisms like watchers that can watch for a change in a file. I was wondering does such mechanism exists for a variable? For example, I would increment an integer variable each time I put an item to the list, the saving to file thread could then trigger as the watched variable changed.
I'm not even sure either this mechanism is the best approach for the application, its just something I thought of.