1 #if !defined (ACE_ID_GENERATOR_C)
2 #define ACE_ID_GENERATOR_C
4 #include "ace/Object_Manager.h"
5 #include "ID_Generator.h"
7 time_t ACE_ID_Generator::last_time_
= 0;
9 size_t ACE_ID_Generator::last_number_
= 0;
11 ACE_SYNCH_MUTEX
*ACE_ID_Generator::lock_
= 0;
14 ACE_ID_Generator::get_new_id (char *id
)
19 ACE_ID_Generator::get_serial_id (t
, sn
);
20 ACE_NEW_RETURN (id
, char [ACE_OFFER_ID_LENGTH
], 0);
22 ACE_OS::sprintf (id
, "%014d%06d", t
, sn
);
27 ACE_ID_Generator::get_serial_id (time_t &t
, size_t &s
)
29 ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX
, ace_mon
, *ACE_ID_Generator::get_lock ()));
32 if (t
!= ACE_ID_Generator::last_time_
)
34 ACE_ID_Generator::last_time_
= t
;
35 s
= ACE_ID_Generator::last_number_
= 0;
38 s
= ACE_ID_Generator::last_number_
++;
42 ACE_ID_Generator::get_lock ()
44 #if defined (ACE_HAS_THREADS)
45 if (ACE_ID_Generator::lock_
== 0)
47 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex
, ace_mon
, *ACE_Static_Object_Lock::instance (), 0));
49 // Double-checked Locking Optimization.
50 if (ACE_ID_Generator::lock_
== 0)
51 ACE_NEW_RETURN (ACE_ID_Generator::lock_
, ACE_SYNCH_MUTEX
, 0);
53 #endif /* ACE_HAS_THREADS */
54 return ACE_ID_Generator::lock_
;
57 #endif /* ACE_ID_GENERATOR_C */