From: <and...@us...> - 2013-12-09 13:41:38
|
Revision: 12828 http://sourceforge.net/p/plplot/code/12828 Author: andrewross Date: 2013-12-09 13:41:35 +0000 (Mon, 09 Dec 2013) Log Message: ----------- Replace calls to usleep in the C / C++ examples with nanosleep. usleep has been deprecated and removed from the newer POSIX specs in favour of nanosleep. Modified Paths: -------------- trunk/cmake/modules/plplot.cmake trunk/examples/c/x01c.c trunk/examples/c/x17c.c trunk/examples/c++/x01.cc trunk/examples/c++/x17.cc trunk/include/plConfig.h.in Modified: trunk/cmake/modules/plplot.cmake =================================================================== --- trunk/cmake/modules/plplot.cmake 2013-12-09 13:20:01 UTC (rev 12827) +++ trunk/cmake/modules/plplot.cmake 2013-12-09 13:41:35 UTC (rev 12828) @@ -252,6 +252,7 @@ include(CheckFunctionExists) check_function_exists(popen HAVE_POPEN) check_function_exists(usleep PL_HAVE_USLEEP) +check_function_exists(nanosleep PL_HAVE_NANOSLEEP) check_function_exists(mkstemp PL_HAVE_MKSTEMP) check_function_exists(mkdtemp PL_HAVE_MKDTEMP) check_function_exists(mkfifo PL_HAVE_MKFIFO) Modified: trunk/examples/c/x01c.c =================================================================== --- trunk/examples/c/x01c.c 2013-12-09 13:20:01 UTC (rev 12827) +++ trunk/examples/c/x01c.c 2013-12-09 13:41:35 UTC (rev 12828) @@ -24,6 +24,9 @@ #include "plcdemos.h" #include "plevent.h" +#ifdef PL_HAVE_NANOSLEEP +#include <time.h> +#endif #ifdef PL_HAVE_UNISTD_H # include <unistd.h> #endif @@ -270,15 +273,18 @@ if ( do_test && test_xor ) { -#ifdef PL_HAVE_USLEEP +#ifdef PL_HAVE_NANOSLEEP PLINT st; + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 50000000; plxormod( 1, &st ); // enter xor mode if ( st ) { for ( i = 0; i < 60; i++ ) { plpoin( 1, x + i, y + i, 9 ); // draw a point - usleep( 50000 ); // wait a little + nanosleep( &ts, NULL ); // wait a little plflush(); // force an update of the tk driver plpoin( 1, x + i, y + i, 9 ); // erase point } @@ -286,7 +292,7 @@ } #else printf( "The -xor command line option can only be exercised if your " - "system\nhas usleep(), which does not seem to happen.\n" ); + "system\nhas nanosleep(), which does not seem to happen.\n" ); #endif } } Modified: trunk/examples/c/x17c.c =================================================================== --- trunk/examples/c/x17c.c 2013-12-09 13:20:01 UTC (rev 12827) +++ trunk/examples/c/x17c.c 2013-12-09 13:41:35 UTC (rev 12828) @@ -5,6 +5,9 @@ #include "plcdemos.h" #include <stdlib.h> +#ifdef PL_HAVE_NANOSLEEP +# include <time.h> +#endif #ifdef PL_HAVE_UNISTD_H # include <unistd.h> #else @@ -32,6 +35,9 @@ PLFLT t, tmin, tmax, tjump, dt, noise; PLINT colbox, collab, colline[4], styline[4]; const char *legline[4]; +#ifdef PL_HAVE_NANOSLEEP + struct timespec ts; +#endif // plplot initialization // Parse and process command line arguments @@ -127,10 +133,14 @@ y1 = y2 = y3 = y4 = 0.0; dt = 0.1; +#ifdef PL_HAVE_NANOSLEEP + ts.tv_sec = 0; + ts.tv_nsec = 10000000; +#endif for ( n = 0; n < nsteps; n++ ) { -#ifdef PL_HAVE_USLEEP - usleep( 10000 ); // wait a little (10 ms) to simulate time elapsing +#ifdef PL_HAVE_NANOSLEEP + nanosleep( &ts, NULL); // wait a little (10 ms) to simulate time elapsing #else # ifdef PL_HAVE_POLL poll( 0, 0, 10 ); Modified: trunk/examples/c++/x01.cc =================================================================== --- trunk/examples/c++/x01.cc 2013-12-09 13:20:01 UTC (rev 12827) +++ trunk/examples/c++/x01.cc 2013-12-09 13:41:35 UTC (rev 12828) @@ -31,6 +31,10 @@ #include "plevent.h" #include <cctype> +#ifdef PL_HAVE_NANOSLEEP +#include <time.h> +#endif + #ifdef PL_HAVE_UNISTD_H #include <unistd.h> #endif @@ -274,22 +278,25 @@ if ( do_test && test_xor ) { -#ifdef PL_HAVE_USLEEP +#ifdef PL_HAVE_NANOLEEP bool st; + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 50000000; pls->xormod( true, &st ); // enter xor mode if ( st ) { for ( i = 0; i < 60; i++ ) { pls->poin( 1, x + i, y + i, 9 ); // draw a point - usleep( 50000 ); // wait a little + nanosleep( &ts, NULL ); // wait a little pls->flush(); // force an update of the tk driver pls->poin( 1, x + i, y + i, 9 ); // erase point } pls->xormod( false, &st ); // leave xor mode } #else - cout << "The -xor command line option can only be exercised if your system has usleep(), which does not seems to happen." << endl; + cout << "The -xor command line option can only be exercised if your system has nanosleep(), which does not seems to happen." << endl; #endif } Modified: trunk/examples/c++/x17.cc =================================================================== --- trunk/examples/c++/x17.cc 2013-12-09 13:20:01 UTC (rev 12827) +++ trunk/examples/c++/x17.cc 2013-12-09 13:41:35 UTC (rev 12828) @@ -27,6 +27,9 @@ //-------------------------------------------------------------------------- #include "plc++demos.h" +#ifdef PL_HAVE_NANOSLEEP +# include <time.h> +#endif #ifdef PL_HAVE_UNISTD_H # include <unistd.h> #else @@ -63,6 +66,9 @@ PLFLT t, tmin, tmax, tjump, dt, noise; PLINT colbox, collab, colline[4], styline[4]; const char *legline[4]; +#ifdef PL_HAVE_NANOSLEEP + struct timespec ts; +#endif // plplot initialization @@ -149,10 +155,14 @@ y1 = y2 = y3 = y4 = 0.0; dt = 0.1; +#ifdef PL_HAVE_NANOSLEEP + ts.tv_sec = 0; + ts.tv_nsec = 10000000; +#endif for ( n = 0; n < nsteps; n++ ) { -#ifdef PL_HAVE_USLEEP - usleep( 10000 ); // wait a little (10 ms) to simulate time elapsing +#ifdef PL_HAVE_NANOSLEEP + nanosleep( &ts, NULL ); // wait a little (10 ms) to simulate time elapsing #else # ifdef PL_HAVE_POLL poll( 0, 0, 10 ); Modified: trunk/include/plConfig.h.in =================================================================== --- trunk/include/plConfig.h.in 2013-12-09 13:20:01 UTC (rev 12827) +++ trunk/include/plConfig.h.in 2013-12-09 13:41:35 UTC (rev 12828) @@ -93,8 +93,8 @@ // Define to 1 if you have the <unistd.h> header file. #cmakedefine PL_HAVE_UNISTD_H 1 -// Define if usleep is available -#cmakedefine PL_HAVE_USLEEP +// Define if nanosleep is available +#cmakedefine PL_HAVE_NANOSLEEP // Define if you want PLplot's float type to be double #cmakedefine PL_DOUBLE This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |