added exact timing semantics on blocking locks
authorAndrew Tridgell <tridge@samba.org>
Sun, 18 Aug 2002 20:09:02 +0000 (20:09 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 18 Aug 2002 20:09:02 +0000 (20:09 +0000)
(This used to be commit aed32eb412cab7f6d0959f9faaaebdb320b2b6a8)

source3/smbd/blocking.c
source3/smbd/process.c

index 72cf3e59b6bf4b7b007ae17b59b1431340cc517f..9d411711cb95532b8df59e27263e4287843c9cca 100644 (file)
@@ -531,13 +531,33 @@ file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum ));
 }
 
 /****************************************************************************
- Return True if the blocking lock queue has entries.
+ Return the number of seconds to the next blocking locks timeout, or default_timeout
 *****************************************************************************/
-
-BOOL blocking_locks_pending(void)
+unsigned blocking_locks_timeout(unsigned default_timeout)
 {
-  blocking_lock_record *blr = (blocking_lock_record *)ubi_slFirst( &blocking_lock_queue );
-  return (blr == NULL ? False : True);
+       unsigned timeout = default_timeout;
+       time_t t;
+       blocking_lock_record *blr = (blocking_lock_record *)ubi_slFirst(&blocking_lock_queue);
+
+       /* note that we avoid the time() syscall if there are no blocking locks */
+       if (!blr) {
+               return timeout;
+       }
+
+       t = time(NULL);
+
+       while (blr) {
+               if (timeout > (blr->expire_time - t)) {
+                       timeout = blr->expire_time - t;
+               }
+               blr = (blocking_lock_record *)ubi_slNext(blr);
+       }
+
+       if (timeout < 1) {
+               timeout = 1;
+       }
+
+       return timeout;
 }
 
 /****************************************************************************
index 55234ec896e422b7b14899401bea15fddce9facc..13fd4998fea4236081d387d468560db173b051dd 100644 (file)
@@ -1032,13 +1032,8 @@ static int setup_select_timeout(void)
        int select_timeout;
        int t;
 
-       /*
-        * Increase the select timeout back to SMBD_SELECT_TIMEOUT if we
-        * have removed any blocking locks. JRA.
-        */
-
-       select_timeout = blocking_locks_pending() ? SMBD_SELECT_TIMEOUT_WITH_PENDING_LOCKS*1000 :
-               SMBD_SELECT_TIMEOUT*1000;
+       select_timeout = blocking_locks_timeout(SMBD_SELECT_TIMEOUT);
+       select_timeout *= 1000;
 
        t = change_notify_timeout();
        if (t != -1) select_timeout = MIN(select_timeout, t*1000);