emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 640fd9b594f 2/2: Sleep less in update-game-score


From: Paul Eggert
Subject: master 640fd9b594f 2/2: Sleep less in update-game-score
Date: Tue, 21 Mar 2023 17:42:26 -0400 (EDT)

branch: master
commit 640fd9b594fa376e6493efbe0cf083e1270ddd3f
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    Sleep less in update-game-score
    
    This is mostly to avoid interface hassles with time/srand/rand.
    * lib-src/update-game-score.c (main): Don’t use ‘srand’ or ‘time’.
    (lock_file): Don’t sleep if we unlocked the lock file.  When
    sleeping, always just sleep 1 s.  This avoids the need for calling
    ‘time’ and ‘rand’, the utility of which was dubious anyway.
---
 lib-src/update-game-score.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index 83167f59b8a..4592e14d1d6 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -185,8 +185,6 @@ main (int argc, char **argv)
   ptrdiff_t scorecount, scorealloc;
   ptrdiff_t max_scores = MAX_SCORES;
 
-  srand (time (0));
-
   while ((c = getopt (argc, argv, "hrm:d:")) != -1)
     switch (c)
       {
@@ -485,8 +483,8 @@ lock_file (const char *filename, void **state)
            return -1;
          attempts = 0;
        }
-
-      sleep ((rand () & 1) + 1);
+      else
+       sleep (1);
     }
 
   close (fd);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]