From: Michael D. <mik...@us...> - 2004-10-24 21:42:49
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28327/NHibernate/Cache Modified Files: Timestamper.cs Log Message: Fixed up Timestamper to be more like hibernate. Not sure the old impl was at all correct. Index: Timestamper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Cache/Timestamper.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Timestamper.cs 6 May 2004 20:53:59 -0000 1.6 --- Timestamper.cs 24 Oct 2004 21:42:40 -0000 1.7 *************** *** 13,35 **** public sealed class Timestamper { private static short counter = 0; private static long time; private const int BinDigits = 12; ! public const short OneMs = 1<<BinDigits; - [MethodImpl(MethodImplOptions.Synchronized)] public static long Next() { ! long newTime = System.DateTime.Now.Ticks << BinDigits; //is this right? ! if (time < newTime) ! { ! time = newTime; ! counter = 0; ! } ! else if (counter < OneMs - 1) { ! counter++; } - return time + counter; } --- 13,46 ---- public sealed class Timestamper { + private static object lockObject = new object(); + + // hibernate is using System.currentMilliSeconds which is calculated + // from jan 1, 1970 + private static long baseDateMs = (new DateTime(1970, 1, 1).Ticks)/10000; + private static short counter = 0; private static long time; private const int BinDigits = 12; ! public const short OneMs = 1<<BinDigits; //(4096 is the value) public static long Next() { ! lock( lockObject ) { ! // Ticks is accurate down to 100 nanoseconds - hibernate uses milliseconds ! // to help calculate next time so drop the nanoseconds portion.(1ms==1000000ns) ! long newTime = ( (System.DateTime.Now.Ticks/10000) - baseDateMs ) << BinDigits; ! if (time < newTime) ! { ! time = newTime; ! counter = 0; ! } ! else if (counter < OneMs - 1) ! { ! counter++; ! } ! return time + counter; ! } } |