1. 27 Feb, 2016 5 commits
  2. 26 Feb, 2016 4 commits
    • Nick Mathewson's avatar
      Branch-complete tests for timeouts_next() · 3c533b61
      Nick Mathewson authored
      3c533b61
    • Nick Mathewson's avatar
      Make the tests cover timeout_readd() better · d6b1d966
      Nick Mathewson authored
      Also, make them check the required invariants for to->expires after
      timeout_readd().
      
      Also, actually use the different timeout values in the main()
      function (whoops).
      d6b1d966
    • Nick Mathewson's avatar
      Correct and simplify timeouts_readd() · d00a3762
      Nick Mathewson authored
      William Ahern tells me that the intent here is that timeout_readd()
      should always reschedule the timeout at the first time in the future
      that is an even multiple of to->interval, as if we had called:
      
               do {
                       to->expires += to->interval;
               } while (to->expires <= T->curtime);
      
      But of course, that's not efficient.  The implementation strategy
      used in this patch simplifies the calculation down to a single %
      operation, plus a few additions and subtractions.
      
      To verify the correctness of the formula used here, note first that
              0 <= r < to->interval, and so
              0 < to->interval - r <= to->interval.  Since
              expires' = curtime + (interval - r),
              curtime < expires' <= curtime + interval,
      and so the new expiration time is no more than one interval after
      curtime.
      
      Note second that since
              r = (curtime - expires) % interval,
              expires' = curtime + (interval - r), we have
              (expires' - expires) % interval =
                  (curtime + (interval - r) - expires) % interval =
                  (curtime - r - expires) % interval =
                  (curtime - (curtime-expires) % interval - expires) % interval =
                  (curtime - curtime + expires - expires) % interval =
                  0.
      And so the new expiration time is an even multiple of interval from
      the original expiration time.
      
      Since we have both properties we wanted, this formula should be right.
      d00a3762
    • William Ahern's avatar
  3. 24 Feb, 2016 18 commits
  4. 23 Feb, 2016 5 commits
  5. 22 Feb, 2016 4 commits
  6. 20 Feb, 2016 1 commit
  7. 19 Feb, 2016 3 commits
    • Nick Mathewson's avatar
      Port timeout.c to platforms without __builtin_c[tl]z · 7311ebae
      Nick Mathewson authored
      This patch includes an intrinsic implementation for these functions
      when the compiler is GCC, Clang, or MSVC--or if the compiler claims
      to be one of those.  Otherwise, a naive implementation is used.
      
      Tests are included for all of these functions, which turned up a
      possible problem: according to the gcc documentation, __builtin_ctz
      and __builtin_clz give an undefined result when their inputs is
      zero.  I was not able to persuade myself that we always called them
      with a nonzero argument.
      7311ebae
    • Nick Mathewson's avatar
      Make the 'timeouts' field in struct timeout optional. · e7c5a9e0
      Nick Mathewson authored
      This field eats a pointer for every struct timeout, and it only
      exists in order to enable a set of APIs that omit the 'struct
      timeouts' object. For some applications, the convenience of these
      APIs is not worth the memory overhead. This patch makes it so
      that applications can disable those APIs, and save some memory, by
      defining TIMEOUT_DISABLE_RELATIVE_ACCESS at compile time.
      e7c5a9e0
    • Nick Mathewson's avatar
      Allow the user to disable interval support at compilation time · 6186b353
      Nick Mathewson authored
      Some users only need plain timeouts.  They shouldn't have to pay the
      overhead for a field they will never set.  With this patch, they can
      define TIMEOUT_DISABLE_INTERVALS and turn off the feature at compile
      time.
      6186b353