Cleanup ACE_HAS_PTHREAD_SIGMASK_PROTOTYPE, all platforms support it so far as I can...
[ACE_TAO.git] / ACE / apps / JAWS3 / jaws3 / Cached_Allocator_T.h
blob03f7f7959957b1e0f841de121611b4356df69235
1 /* -*- c++ -*- */
2 #ifndef JAWS_CACHED_ALLOCATOR_T_H
3 #define JAWS_CACHED_ALLOCATOR_T_H
5 #include "ace/ACE.h"
6 #include "ace/Synch.h"
7 #include "ace/Malloc.h"
8 #include "ace/Free_List.h"
10 #define JAWS_DEFAULT_ALLOCATOR_CHUNKS 10
11 #define JAWS_CACHED_ALLOCATOR(T) \
12 JAWS_Cached_Allocator< T, ACE_SYNCH_NULL_MUTEX >
14 template <class T, class ACE_LOCK>
15 class JAWS_Cached_Allocator : public ACE_New_Allocator
16 // = TITLE
17 // Create a cached memory pool with <n_chunks> chunks each with
18 // sizeof (<TYPE>) size.
20 // = DESCRIPTION
21 // This class enables caching of dynamically allocated,
22 // fixed-sized classes.
24 public:
25 JAWS_Cached_Allocator (size_t n_chunks = JAWS_DEFAULT_ALLOCATOR_CHUNKS);
27 ~JAWS_Cached_Allocator ();
29 void* malloc (size_t);
30 // get a chunk of memory from free store.
32 void free (void *);
33 // return a chunk of memory back to free store.
35 protected:
36 char * get_next_pool (char *pool);
38 void set_next_pool (char *pool, char *next_pool);
40 void extend_pool ();
42 private:
43 size_t pool_size_;
45 char *pool_head_;
46 // Head of memory pool.
48 char *pool_tail_;
49 // Tail of memory pool.
51 ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node<T>, ACE_LOCK> free_list_;
52 // Maintain a cached memory free list.
56 template <class T>
57 class JAWS_TSS_Cached_Allocator : public ACE_New_Allocator
58 // = TITLE
59 // Create a thread specific cached memory pool with <n_chunks>
60 // chunks each with sizeof (<TYPE>) size.
62 // = DESCRIPTION
63 // This class enables caching of dynamically allocated,
64 // fixed-sized classes.
66 public:
67 JAWS_TSS_Cached_Allocator (size_t n_chunks = JAWS_DEFAULT_ALLOCATOR_CHUNKS);
69 ~JAWS_TSS_Cached_Allocator ();
71 void * malloc (size_t);
72 // get a chunk of memory from free store.
74 void free (void *);
75 // return a chunk of memory back to free store.
77 protected:
78 JAWS_Cached_Allocator<T, ACE_SYNCH_NULL_MUTEX> * ts_allocator ();
80 private:
81 size_t n_chunks_;
83 ACE_TSS_TYPE (JAWS_CACHED_ALLOCATOR(T)) ts_allocator_;
86 #include "jaws3/Cached_Allocator_T.cpp"
88 #endif /* JAWS_CACHED_ALLOCATOR_T_H */