JvanKatwijk / eti-stuff

experimental software for creating and interpreting eti frames
GNU General Public License v2.0
21 stars 12 forks source link

Increase 'sleep' stability #55

Closed kkubicki closed 1 year ago

kkubicki commented 1 year ago

Standard 'sleep' function can be interrupted by a signal, which leads to instability of recordTime counter (and possible other time-dependent tasks too). Observed anomaly here on RPI: https://asciinema.org/a/yopUpkTPTG2OHxM1R1jjaItSY

This change switches globally 'sleep' from <unistd.h> to more stable 'sleep_for' from <thread>.

JvanKatwijk commented 1 year ago

Thanks

kkubicki commented 1 year ago

My pleasure!

andimik commented 1 year ago

dear @kkubicki

I get an error when I compile for rawfiles:

[ 96%] Building CXX object CMakeFiles/eti-cmdline-rawfiles.dir/devices/rawfile-handler/rawfile-handler.cpp.o
/home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp: In member function ‘void rawfileHandler::runRead()’:
/home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp:136:22: error: call of overloaded ‘usleep(int64_t)’ is ambiguous
  136 |               usleep (nextStop - getMyTime ());
      |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/andreas/apps/eti-stuff/eti-cmdline/./includes/dab-constants.h:42,
                 from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.h:29,
                 from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp:26:
/usr/include/unistd.h:480:12: note: candidate: ‘int usleep(__useconds_t)’
  480 | extern int usleep (__useconds_t __useconds);
      |            ^~~~~~
In file included from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.h:29,
                 from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp:26:
/home/andreas/apps/eti-stuff/eti-cmdline/./includes/dab-constants.h:48:20: note: candidate: ‘void usleep(int)’
   48 | static inline void usleep(int u) { std::this_thread::sleep_for(std::chrono::microseconds(u)); }
      |                    ^~~~~~
make[2]: *** [CMakeFiles/eti-cmdline-rawfiles.dir/build.make:398: CMakeFiles/eti-cmdline-rawfiles.dir/devices/rawfile-handler/rawfile-handler.cpp.o] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/eti-cmdline-rawfiles.dir/all] Fehler 2
make: *** [Makefile:136: all] Fehler 2

For rdlsdr it worked, on the other hand ...

[ 96%] Building CXX object CMakeFiles/eti-cmdline-rtlsdr.dir/devices/rtlsdr-handler/rtlsdr-handler.cpp.o
[100%] Linking CXX executable eti-cmdline-rtlsdr
[100%] Built target eti-cmdline-rtlsdr

For airspy as well:

[ 96%] Building CXX object CMakeFiles/eti-cmdline-airspy.dir/devices/airspy-handler/airspy-handler.cpp.o
[100%] Linking CXX executable eti-cmdline-airspy
[100%] Built target eti-cmdline-airspy

And for rtl_tcp:

[100%] Linking CXX executable eti-cmdline-rtl_tcp
[100%] Built target eti-cmdline-rtl_tcp
JvanKatwijk commented 1 year ago

Makes sense since the usleep and sleep were locally defined and now locally and globally included

I renamed the redefined sleep and usleep into "special_xxx" and it compiled fine now

That it works for rtlsdr is no coincidence, the driver for rtlsdr doe not reference sleep lile functions

Op za 10 dec. 2022 om 11:15 schreef andimik @.***>:

dear @kkubicki https://github.com/kkubicki

I get an error when I compile for rawfiles:

[ 96%] Building CXX object CMakeFiles/eti-cmdline-rawfiles.dir/devices/rawfile-handler/rawfile-handler.cpp.o

/home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp: In member function ‘void rawfileHandler::runRead()’:

/home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp:136:22: error: call of overloaded ‘usleep(int64_t)’ is ambiguous

136 | usleep (nextStop - getMyTime ());

  |               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

In file included from /home/andreas/apps/eti-stuff/eti-cmdline/./includes/dab-constants.h:42,

             from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.h:29,

             from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp:26:

/usr/include/unistd.h:480:12: note: candidate: ‘int usleep(__useconds_t)’

480 | extern int usleep (__useconds_t __useconds);

  |            ^~~~~~

In file included from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.h:29,

             from /home/andreas/apps/eti-stuff/eti-cmdline/devices/rawfile-handler/rawfile-handler.cpp:26:

/home/andreas/apps/eti-stuff/eti-cmdline/./includes/dab-constants.h:48:20: note: candidate: ‘void usleep(int)’

48 | static inline void usleep(int u) { std::this_thread::sleep_for(std::chrono::microseconds(u)); }

  |                    ^~~~~~

make[2]: *** [CMakeFiles/eti-cmdline-rawfiles.dir/build.make:398: CMakeFiles/eti-cmdline-rawfiles.dir/devices/rawfile-handler/rawfile-handler.cpp.o] Fehler 1

make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/eti-cmdline-rawfiles.dir/all] Fehler 2

make: *** [Makefile:136: all] Fehler 2

For rdlsdr it worked, on the other hand ...

— Reply to this email directly, view it on GitHub https://github.com/JvanKatwijk/eti-stuff/pull/55#issuecomment-1345214560, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCPHQFIPUKNMQDTUFDZAT3WMRJ5BANCNFSM6AAAAAASX6N3SM . You are receiving this because you modified the open/close state.Message ID: @.***>

-- Jan van Katwijk

andimik commented 1 year ago

@JvanKatwijk

Many thanks! Yes, confirmed, this is now working.

[100%] Linking CXX executable eti-cmdline-rawfiles
[100%] Built target eti-cmdline-rawfiles
kkubicki commented 1 year ago

@andimik Sorry, I missed that! @JvanKatwijk Could be ridding #include a solution here? Both from rawfile-handler and dab-constants? If it is only included for sleep and usleep then maybe this is the 'nicest' solution? Unfortunately I cannot compile for all the possible devices because of lack of some drivers, but for RAWFILES, RTL_TCP and RTLSDR seem OK.

JvanKatwijk commented 1 year ago

I'll just make a walk through the code and change the occurrences of usleep/sleep to their "new" name no problem

Op za 10 dec. 2022 om 12:31 schreef Krzysztof Kubicki < @.***>:

@andimik https://github.com/andimik Sorry, I missed that! @JvanKatwijk https://github.com/JvanKatwijk Could be ridding *#include

* a solution here? Both from rawfile-handler and dab-constants? If it is only included for *sleep* and *usleep* then maybe this is the 'nicest' solution? Unfortunately I cannot compile for all the possible devices because of lack of some drivers... — Reply to this email directly, view it on GitHub , or unsubscribe . You are receiving this because you were mentioned.Message ID: ***@***.***>

-- Jan van Katwijk