4 //=============================================================================
10 //=============================================================================
13 #ifndef ACE_ID_GENERATOR_H
14 #define ACE_ID_GENERATOR_h
16 #include "ace/config-all.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #define ACE_OFFER_ID_LENGTH 21
25 * @class ACE_ID_Generator
27 * @brief An unique ID generator.
29 class ACE_ID_Generator
31 // Generate an offer ID according to current time and avoid
32 // duplicate ID. It guarantees ID uniqueness within a process,
33 // i.e. no two threads may get the same ID string. Using a
34 // similar method like the backery algorithm.
37 /// allocate a new ID string and point <id> to it.
38 static char *get_new_id (char *id
);
41 /// Atomically get info required to generate an offer ID.
42 static void get_serial_id (time_t &t
, size_t &s
);
44 /// Get the lock instance.
45 static ACE_SYNCH_MUTEX
*get_lock ();
47 /// Record the time last offer ID generated.
48 static time_t last_time_
;
50 /// Record serial number of last offer ID with same
52 static size_t last_number_
;
54 /// mutex to access private member.
55 static ACE_SYNCH_MUTEX
*lock_
;
58 #endif /* ACE_ID_GENERATOR_H */