Merge pull request #2317 from jwillemsen/jwi-deleteop
[ACE_TAO.git] / ACE / apps / JAWS / clients / Caching / ID_Generator.h
blobe6d30edce01e4572688a10d7734bd01354d55435
1 /* -*- C++ -*- */
4 //=============================================================================
5 /**
6 * @file ID_Generator.h
8 * @author Nanbor Wang
9 */
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)
19 # pragma once
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #define ACE_OFFER_ID_LENGTH 21
24 /**
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.
36 public:
37 /// allocate a new ID string and point <id> to it.
38 static char *get_new_id (char *id);
40 private:
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
51 /// generation time.
52 static size_t last_number_;
54 /// mutex to access private member.
55 static ACE_SYNCH_MUTEX *lock_;
58 #endif /* ACE_ID_GENERATOR_H */