epoc32/include/stdapis/stlport/stl/_pthread_alloc.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
/*
williamr@2
     2
 *
williamr@2
     3
 * Copyright (c) 1994
williamr@2
     4
 * Hewlett-Packard Company
williamr@2
     5
 *
williamr@2
     6
 * Copyright (c) 1996,1997
williamr@2
     7
 * Silicon Graphics Computer Systems, Inc.
williamr@2
     8
 *
williamr@2
     9
 * Copyright (c) 1997
williamr@2
    10
 * Moscow Center for SPARC Technology
williamr@2
    11
 *
williamr@2
    12
 * Copyright (c) 1999 
williamr@2
    13
 * Boris Fomitchev
williamr@2
    14
 *
williamr@2
    15
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
    16
 * or implied. Any use is at your own risk.
williamr@2
    17
 *
williamr@2
    18
 * Permission to use or copy this software for any purpose is hereby granted 
williamr@2
    19
 * without fee, provided the above notices are retained on all copies.
williamr@2
    20
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    21
 * provided the above notices are retained, and a notice that the code was
williamr@2
    22
 * modified is included with the above copyright notice.
williamr@2
    23
 *
williamr@2
    24
 */
williamr@2
    25
williamr@2
    26
#ifndef _STLP_PTHREAD_ALLOC_H
williamr@2
    27
#define _STLP_PTHREAD_ALLOC_H
williamr@2
    28
williamr@2
    29
// Pthread-specific node allocator.
williamr@2
    30
// This is similar to the default allocator, except that free-list
williamr@2
    31
// information is kept separately for each thread, avoiding locking.
williamr@2
    32
// This should be reasonably fast even in the presence of threads.
williamr@2
    33
// The down side is that storage may not be well-utilized.
williamr@2
    34
// It is not an error to allocate memory in thread A and deallocate
williamr@2
    35
// it in thread B.  But this effectively transfers ownership of the memory,
williamr@2
    36
// so that it can only be reallocated by thread B.  Thus this can effectively
williamr@2
    37
// result in a storage leak if it's done on a regular basis.
williamr@2
    38
// It can also result in frequent sharing of
williamr@2
    39
// cache lines among processors, with potentially serious performance
williamr@2
    40
// consequences.
williamr@2
    41
williamr@2
    42
#include <pthread.h>
williamr@2
    43
williamr@2
    44
#ifndef _STLP_INTERNAL_ALLOC_H
williamr@2
    45
#include <stl/_alloc.h>
williamr@2
    46
#endif
williamr@2
    47
williamr@2
    48
#ifndef __RESTRICT
williamr@2
    49
#  define __RESTRICT
williamr@2
    50
#endif
williamr@2
    51
williamr@2
    52
_STLP_BEGIN_NAMESPACE
williamr@2
    53
williamr@2
    54
#define _STLP_DATA_ALIGNMENT 8
williamr@2
    55
williamr@2
    56
union _Pthread_alloc_obj {
williamr@2
    57
    union _Pthread_alloc_obj * __free_list_link;
williamr@2
    58
    char __client_data[_STLP_DATA_ALIGNMENT];    /* The client sees this.    */
williamr@2
    59
};
williamr@2
    60
williamr@2
    61
// Pthread allocators don't appear to the client to have meaningful
williamr@2
    62
// instances.  We do in fact need to associate some state with each
williamr@2
    63
// thread.  That state is represented by
williamr@2
    64
// _Pthread_alloc_per_thread_state<_Max_size>.
williamr@2
    65
williamr@2
    66
template<size_t _Max_size>
williamr@2
    67
struct _Pthread_alloc_per_thread_state {
williamr@2
    68
  typedef _Pthread_alloc_obj __obj;
williamr@2
    69
  enum { _S_NFREELISTS = _Max_size/_STLP_DATA_ALIGNMENT };
williamr@2
    70
williamr@2
    71
  // Free list link for list of available per thread structures.
williamr@2
    72
  // When one of these becomes available for reuse due to thread
williamr@2
    73
  // termination, any objects in its free list remain associated
williamr@2
    74
  // with it.  The whole structure may then be used by a newly
williamr@2
    75
  // created thread.
williamr@2
    76
  _Pthread_alloc_per_thread_state() : __next(0)
williamr@2
    77
  {
williamr@2
    78
    memset((void *)__free_list, 0, (size_t)_S_NFREELISTS * sizeof(__obj *));
williamr@2
    79
  }
williamr@2
    80
  // Returns an object of size __n, and possibly adds to size n free list.
williamr@2
    81
  void *_M_refill(size_t __n);
williamr@2
    82
  
williamr@2
    83
  _Pthread_alloc_obj* volatile __free_list[_S_NFREELISTS]; 
williamr@2
    84
  _Pthread_alloc_per_thread_state<_Max_size> * __next; 
williamr@2
    85
  // this data member is only to be used by per_thread_allocator, which returns memory to the originating thread.
williamr@2
    86
  _STLP_mutex _M_lock;
williamr@2
    87
williamr@2
    88
 };
williamr@2
    89
williamr@2
    90
// Pthread-specific allocator.
williamr@2
    91
// The argument specifies the largest object size allocated from per-thread
williamr@2
    92
// free lists.  Larger objects are allocated using malloc_alloc.
williamr@2
    93
// Max_size must be a power of 2.
williamr@2
    94
template < __DFL_NON_TYPE_PARAM(size_t, _Max_size, _MAX_BYTES) >
williamr@2
    95
class _Pthread_alloc {
williamr@2
    96
williamr@2
    97
public: // but only for internal use:
williamr@2
    98
williamr@2
    99
  typedef _Pthread_alloc_obj __obj;
williamr@2
   100
  typedef _Pthread_alloc_per_thread_state<_Max_size> __state_type;
williamr@2
   101
  typedef char value_type;
williamr@2
   102
williamr@2
   103
  // Allocates a chunk for nobjs of size size.  nobjs may be reduced
williamr@2
   104
  // if it is inconvenient to allocate the requested number.
williamr@2
   105
  static char *_S_chunk_alloc(size_t __size, size_t &__nobjs);
williamr@2
   106
williamr@2
   107
  enum {_S_ALIGN = _STLP_DATA_ALIGNMENT};
williamr@2
   108
williamr@2
   109
  static size_t _S_round_up(size_t __bytes) {
williamr@2
   110
        return (((__bytes) + (int)_S_ALIGN-1) & ~((int)_S_ALIGN - 1));
williamr@2
   111
  }
williamr@2
   112
  static size_t _S_freelist_index(size_t __bytes) {
williamr@2
   113
        return (((__bytes) + (int)_S_ALIGN-1)/(int)_S_ALIGN - 1);
williamr@2
   114
  }
williamr@2
   115
williamr@2
   116
private:
williamr@2
   117
  // Chunk allocation state. And other shared state.
williamr@2
   118
  // Protected by _S_chunk_allocator_lock.
williamr@2
   119
  static _STLP_mutex_base _S_chunk_allocator_lock;
williamr@2
   120
  static char *_S_start_free;
williamr@2
   121
  static char *_S_end_free;
williamr@2
   122
  static size_t _S_heap_size;
williamr@2
   123
  static _Pthread_alloc_per_thread_state<_Max_size>* _S_free_per_thread_states;
williamr@2
   124
  static pthread_key_t _S_key;
williamr@2
   125
  static bool _S_key_initialized;
williamr@2
   126
        // Pthread key under which per thread state is stored. 
williamr@2
   127
        // Allocator instances that are currently unclaimed by any thread.
williamr@2
   128
  static void _S_destructor(void *instance);
williamr@2
   129
        // Function to be called on thread exit to reclaim per thread
williamr@2
   130
        // state.
williamr@2
   131
  static _Pthread_alloc_per_thread_state<_Max_size> *_S_new_per_thread_state();
williamr@2
   132
public:
williamr@2
   133
        // Return a recycled or new per thread state.
williamr@2
   134
  static _Pthread_alloc_per_thread_state<_Max_size> *_S_get_per_thread_state();
williamr@2
   135
private:
williamr@2
   136
        // ensure that the current thread has an associated
williamr@2
   137
        // per thread state.
williamr@2
   138
  class _M_lock;
williamr@2
   139
  friend class _M_lock;
williamr@2
   140
  class _M_lock {
williamr@2
   141
      public:
williamr@2
   142
        _M_lock () { _S_chunk_allocator_lock._M_acquire_lock(); }
williamr@2
   143
        ~_M_lock () { _S_chunk_allocator_lock._M_release_lock(); }
williamr@2
   144
  };
williamr@2
   145
williamr@2
   146
public:
williamr@2
   147
williamr@2
   148
  /* n must be > 0      */
williamr@2
   149
  static void * allocate(size_t __n)
williamr@2
   150
  {
williamr@2
   151
    __obj * volatile * __my_free_list;
williamr@2
   152
    __obj * __RESTRICT __result;
williamr@2
   153
    __state_type* __a;
williamr@2
   154
williamr@2
   155
    if (__n > _Max_size) {
williamr@2
   156
        return(__malloc_alloc<0>::allocate(__n));
williamr@2
   157
    }
williamr@2
   158
williamr@2
   159
    __a = _S_get_per_thread_state();
williamr@2
   160
williamr@2
   161
    __my_free_list = __a -> __free_list + _S_freelist_index(__n);
williamr@2
   162
    __result = *__my_free_list;
williamr@2
   163
    if (__result == 0) {
williamr@2
   164
        void *__r = __a -> _M_refill(_S_round_up(__n));
williamr@2
   165
        return __r;
williamr@2
   166
    }
williamr@2
   167
    *__my_free_list = __result -> __free_list_link;
williamr@2
   168
    return (__result);
williamr@2
   169
  };
williamr@2
   170
williamr@2
   171
  /* p may not be 0 */
williamr@2
   172
  static void deallocate(void *__p, size_t __n)
williamr@2
   173
  {
williamr@2
   174
    __obj *__q = (__obj *)__p;
williamr@2
   175
    __obj * volatile * __my_free_list;
williamr@2
   176
    __state_type* __a;
williamr@2
   177
williamr@2
   178
    if (__n > _Max_size) {
williamr@2
   179
        __malloc_alloc<0>::deallocate(__p, __n);
williamr@2
   180
        return;
williamr@2
   181
    }
williamr@2
   182
williamr@2
   183
    __a = _S_get_per_thread_state();
williamr@2
   184
    
williamr@2
   185
    __my_free_list = __a->__free_list + _S_freelist_index(__n);
williamr@2
   186
    __q -> __free_list_link = *__my_free_list;
williamr@2
   187
    *__my_free_list = __q;
williamr@2
   188
  }
williamr@2
   189
williamr@2
   190
  // boris : versions for per_thread_allocator
williamr@2
   191
  /* n must be > 0      */
williamr@2
   192
  static void * allocate(size_t __n, __state_type* __a)
williamr@2
   193
  {
williamr@2
   194
    __obj * volatile * __my_free_list;
williamr@2
   195
    __obj * __RESTRICT __result;
williamr@2
   196
williamr@2
   197
    if (__n > _Max_size) {
williamr@2
   198
        return(__malloc_alloc<0>::allocate(__n));
williamr@2
   199
    }
williamr@2
   200
williamr@2
   201
    // boris : here, we have to lock per thread state, as we may be getting memory from
williamr@2
   202
    // different thread pool.
williamr@2
   203
    _STLP_mutex_lock __lock(__a->_M_lock);
williamr@2
   204
williamr@2
   205
    __my_free_list = __a -> __free_list + _S_freelist_index(__n);
williamr@2
   206
    __result = *__my_free_list;
williamr@2
   207
    if (__result == 0) {
williamr@2
   208
        void *__r = __a -> _M_refill(_S_round_up(__n));
williamr@2
   209
        return __r;
williamr@2
   210
    }
williamr@2
   211
    *__my_free_list = __result -> __free_list_link;
williamr@2
   212
    return (__result);
williamr@2
   213
  };
williamr@2
   214
williamr@2
   215
  /* p may not be 0 */
williamr@2
   216
  static void deallocate(void *__p, size_t __n, __state_type* __a)
williamr@2
   217
  {
williamr@2
   218
    __obj *__q = (__obj *)__p;
williamr@2
   219
    __obj * volatile * __my_free_list;
williamr@2
   220
williamr@2
   221
    if (__n > _Max_size) {
williamr@2
   222
        __malloc_alloc<0>::deallocate(__p, __n);
williamr@2
   223
        return;
williamr@2
   224
    }
williamr@2
   225
williamr@2
   226
    // boris : here, we have to lock per thread state, as we may be returning memory from
williamr@2
   227
    // different thread.
williamr@2
   228
    _STLP_mutex_lock __lock(__a->_M_lock);
williamr@2
   229
williamr@2
   230
    __my_free_list = __a->__free_list + _S_freelist_index(__n);
williamr@2
   231
    __q -> __free_list_link = *__my_free_list;
williamr@2
   232
    *__my_free_list = __q;
williamr@2
   233
  }
williamr@2
   234
williamr@2
   235
  static void * reallocate(void *__p, size_t __old_sz, size_t __new_sz);
williamr@2
   236
williamr@2
   237
} ;
williamr@2
   238
williamr@2
   239
# if defined (_STLP_USE_TEMPLATE_EXPORT)
williamr@2
   240
_STLP_EXPORT_TEMPLATE_CLASS _Pthread_alloc<_MAX_BYTES>;
williamr@2
   241
# endif
williamr@2
   242
williamr@2
   243
typedef _Pthread_alloc<_MAX_BYTES> __pthread_alloc;
williamr@2
   244
typedef __pthread_alloc pthread_alloc;
williamr@2
   245
williamr@2
   246
template <class _Tp>
williamr@2
   247
class pthread_allocator {
williamr@2
   248
  typedef pthread_alloc _S_Alloc;          // The underlying allocator.
williamr@2
   249
public:
williamr@2
   250
  typedef size_t     size_type;
williamr@2
   251
  typedef ptrdiff_t  difference_type;
williamr@2
   252
  typedef _Tp*       pointer;
williamr@2
   253
  typedef const _Tp* const_pointer;
williamr@2
   254
  typedef _Tp&       reference;
williamr@2
   255
  typedef const _Tp& const_reference;
williamr@2
   256
  typedef _Tp        value_type;
williamr@2
   257
williamr@2
   258
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
williamr@2
   259
  template <class _NewType> struct rebind {
williamr@2
   260
    typedef pthread_allocator<_NewType> other;
williamr@2
   261
  };
williamr@2
   262
#endif
williamr@2
   263
williamr@2
   264
  pthread_allocator() _STLP_NOTHROW {}
williamr@2
   265
  pthread_allocator(const pthread_allocator<_Tp>& a) _STLP_NOTHROW {}
williamr@2
   266
williamr@2
   267
#if defined (_STLP_MEMBER_TEMPLATES) /* && defined (_STLP_FUNCTION_PARTIAL_ORDER) */
williamr@2
   268
  template <class _OtherType> pthread_allocator(const pthread_allocator<_OtherType>&)
williamr@2
   269
		_STLP_NOTHROW {}
williamr@2
   270
#endif
williamr@2
   271
williamr@2
   272
  ~pthread_allocator() _STLP_NOTHROW {}
williamr@2
   273
williamr@2
   274
  pointer address(reference __x) const { return &__x; }
williamr@2
   275
  const_pointer address(const_reference __x) const { return &__x; }
williamr@2
   276
williamr@2
   277
  // __n is permitted to be 0.  The C++ standard says nothing about what
williamr@2
   278
  // the return value is when __n == 0.
williamr@2
   279
  _Tp* allocate(size_type __n, const void* = 0) {
williamr@2
   280
    return __n != 0 ? __STATIC_CAST(_Tp*,_S_Alloc::allocate(__n * sizeof(_Tp)))
williamr@2
   281
                    : 0;
williamr@2
   282
  }
williamr@2
   283
williamr@2
   284
  // p is not permitted to be a null pointer.
williamr@2
   285
  void deallocate(pointer __p, size_type __n)
williamr@2
   286
    { _S_Alloc::deallocate(__p, __n * sizeof(_Tp)); }
williamr@2
   287
williamr@2
   288
  size_type max_size() const _STLP_NOTHROW 
williamr@2
   289
    { return size_t(-1) / sizeof(_Tp); }
williamr@2
   290
williamr@2
   291
  void construct(pointer __p, const _Tp& __val) { _STLP_PLACEMENT_NEW (__p) _Tp(__val); }
williamr@2
   292
  void destroy(pointer _p) { _p->~_Tp(); }
williamr@2
   293
};
williamr@2
   294
williamr@2
   295
_STLP_TEMPLATE_NULL
williamr@2
   296
class _STLP_CLASS_DECLSPEC pthread_allocator<void> {
williamr@2
   297
public:
williamr@2
   298
  typedef size_t      size_type;
williamr@2
   299
  typedef ptrdiff_t   difference_type;
williamr@2
   300
  typedef void*       pointer;
williamr@2
   301
  typedef const void* const_pointer;
williamr@2
   302
  typedef void        value_type;
williamr@2
   303
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
williamr@2
   304
  template <class _NewType> struct rebind {
williamr@2
   305
    typedef pthread_allocator<_NewType> other;
williamr@2
   306
  };
williamr@2
   307
#endif
williamr@2
   308
};
williamr@2
   309
williamr@2
   310
template <class _T1, class _T2>
williamr@2
   311
inline bool operator==(const pthread_allocator<_T1>&,
williamr@2
   312
                       const pthread_allocator<_T2>& a2) 
williamr@2
   313
{
williamr@2
   314
  return true;
williamr@2
   315
}
williamr@2
   316
williamr@2
   317
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
williamr@2
   318
template <class _T1, class _T2>
williamr@2
   319
inline bool operator!=(const pthread_allocator<_T1>&,
williamr@2
   320
                       const pthread_allocator<_T2>&)
williamr@2
   321
{
williamr@2
   322
  return false;
williamr@2
   323
}
williamr@2
   324
#endif
williamr@2
   325
williamr@2
   326
williamr@2
   327
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
williamr@2
   328
williamr@2
   329
# ifdef _STLP_USE_RAW_SGI_ALLOCATORS
williamr@2
   330
template <class _Tp, size_t _Max_size>
williamr@2
   331
struct _Alloc_traits<_Tp, _Pthread_alloc<_Max_size> >
williamr@2
   332
{
williamr@2
   333
  typedef __allocator<_Tp, _Pthread_alloc<_Max_size> > 
williamr@2
   334
          allocator_type;
williamr@2
   335
};
williamr@2
   336
# endif
williamr@2
   337
williamr@2
   338
template <class _Tp, class _Atype>
williamr@2
   339
struct _Alloc_traits<_Tp, pthread_allocator<_Atype> >
williamr@2
   340
{
williamr@2
   341
  typedef pthread_allocator<_Tp> allocator_type;
williamr@2
   342
};
williamr@2
   343
williamr@2
   344
#endif
williamr@2
   345
williamr@2
   346
#if !defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
williamr@2
   347
williamr@2
   348
template <class _Tp1, class _Tp2>
williamr@2
   349
inline pthread_allocator<_Tp2>&
williamr@2
   350
__stl_alloc_rebind(pthread_allocator<_Tp1>& __x, const _Tp2*) {
williamr@2
   351
  return (pthread_allocator<_Tp2>&)__x;
williamr@2
   352
}
williamr@2
   353
williamr@2
   354
template <class _Tp1, class _Tp2>
williamr@2
   355
inline pthread_allocator<_Tp2>
williamr@2
   356
__stl_alloc_create(pthread_allocator<_Tp1>&, const _Tp2*) {
williamr@2
   357
  return pthread_allocator<_Tp2>();
williamr@2
   358
}
williamr@2
   359
williamr@2
   360
#endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
williamr@2
   361
williamr@2
   362
//
williamr@2
   363
// per_thread_allocator<> : this allocator always return memory to the same thread 
williamr@2
   364
// it was allocated from.
williamr@2
   365
//
williamr@2
   366
williamr@2
   367
template <class _Tp>
williamr@2
   368
class per_thread_allocator {
williamr@2
   369
  typedef pthread_alloc _S_Alloc;          // The underlying allocator.
williamr@2
   370
  typedef pthread_alloc::__state_type __state_type;
williamr@2
   371
public:
williamr@2
   372
  typedef size_t     size_type;
williamr@2
   373
  typedef ptrdiff_t  difference_type;
williamr@2
   374
  typedef _Tp*       pointer;
williamr@2
   375
  typedef const _Tp* const_pointer;
williamr@2
   376
  typedef _Tp&       reference;
williamr@2
   377
  typedef const _Tp& const_reference;
williamr@2
   378
  typedef _Tp        value_type;
williamr@2
   379
williamr@2
   380
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
williamr@2
   381
  template <class _NewType> struct rebind {
williamr@2
   382
    typedef per_thread_allocator<_NewType> other;
williamr@2
   383
  };
williamr@2
   384
#endif
williamr@2
   385
williamr@2
   386
  per_thread_allocator() _STLP_NOTHROW { 
williamr@2
   387
    _M_state = _S_Alloc::_S_get_per_thread_state();
williamr@2
   388
  }
williamr@2
   389
  per_thread_allocator(const per_thread_allocator<_Tp>& __a) _STLP_NOTHROW : _M_state(__a._M_state){}
williamr@2
   390
williamr@2
   391
#if defined (_STLP_MEMBER_TEMPLATES) /* && defined (_STLP_FUNCTION_PARTIAL_ORDER) */
williamr@2
   392
  template <class _OtherType> per_thread_allocator(const per_thread_allocator<_OtherType>& __a)
williamr@2
   393
		_STLP_NOTHROW : _M_state(__a._M_state) {}
williamr@2
   394
#endif
williamr@2
   395
williamr@2
   396
  ~per_thread_allocator() _STLP_NOTHROW {}
williamr@2
   397
williamr@2
   398
  pointer address(reference __x) const { return &__x; }
williamr@2
   399
  const_pointer address(const_reference __x) const { return &__x; }
williamr@2
   400
williamr@2
   401
  // __n is permitted to be 0.  The C++ standard says nothing about what
williamr@2
   402
  // the return value is when __n == 0.
williamr@2
   403
  _Tp* allocate(size_type __n, const void* = 0) {
williamr@2
   404
    return __n != 0 ? __STATIC_CAST(_Tp*,_S_Alloc::allocate(__n * sizeof(_Tp), _M_state)): 0;
williamr@2
   405
  }
williamr@2
   406
williamr@2
   407
  // p is not permitted to be a null pointer.
williamr@2
   408
  void deallocate(pointer __p, size_type __n)
williamr@2
   409
    { _S_Alloc::deallocate(__p, __n * sizeof(_Tp), _M_state); }
williamr@2
   410
williamr@2
   411
  size_type max_size() const _STLP_NOTHROW 
williamr@2
   412
    { return size_t(-1) / sizeof(_Tp); }
williamr@2
   413
williamr@2
   414
  void construct(pointer __p, const _Tp& __val) { _STLP_PLACEMENT_NEW (__p) _Tp(__val); }
williamr@2
   415
  void destroy(pointer _p) { _p->~_Tp(); }
williamr@2
   416
williamr@2
   417
  // state is being kept here
williamr@2
   418
  __state_type* _M_state;
williamr@2
   419
};
williamr@2
   420
williamr@2
   421
_STLP_TEMPLATE_NULL
williamr@2
   422
class _STLP_CLASS_DECLSPEC per_thread_allocator<void> {
williamr@2
   423
public:
williamr@2
   424
  typedef size_t      size_type;
williamr@2
   425
  typedef ptrdiff_t   difference_type;
williamr@2
   426
  typedef void*       pointer;
williamr@2
   427
  typedef const void* const_pointer;
williamr@2
   428
  typedef void        value_type;
williamr@2
   429
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
williamr@2
   430
  template <class _NewType> struct rebind {
williamr@2
   431
    typedef per_thread_allocator<_NewType> other;
williamr@2
   432
  };
williamr@2
   433
#endif
williamr@2
   434
};
williamr@2
   435
williamr@2
   436
template <class _T1, class _T2>
williamr@2
   437
inline bool operator==(const per_thread_allocator<_T1>& __a1,
williamr@2
   438
                       const per_thread_allocator<_T2>& __a2) 
williamr@2
   439
{
williamr@2
   440
  return __a1._M_state == __a2._M_state;
williamr@2
   441
}
williamr@2
   442
williamr@2
   443
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
williamr@2
   444
template <class _T1, class _T2>
williamr@2
   445
inline bool operator!=(const per_thread_allocator<_T1>& __a1,
williamr@2
   446
                       const per_thread_allocator<_T2>& __a2)
williamr@2
   447
{
williamr@2
   448
  return __a1._M_state != __a2._M_state;
williamr@2
   449
}
williamr@2
   450
#endif
williamr@2
   451
williamr@2
   452
williamr@2
   453
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
williamr@2
   454
williamr@2
   455
template <class _Tp, class _Atype>
williamr@2
   456
struct _Alloc_traits<_Tp, per_thread_allocator<_Atype> >
williamr@2
   457
{
williamr@2
   458
  typedef per_thread_allocator<_Tp> allocator_type;
williamr@2
   459
};
williamr@2
   460
williamr@2
   461
#endif
williamr@2
   462
williamr@2
   463
#if !defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
williamr@2
   464
williamr@2
   465
template <class _Tp1, class _Tp2>
williamr@2
   466
inline per_thread_allocator<_Tp2>&
williamr@2
   467
__stl_alloc_rebind(per_thread_allocator<_Tp1>& __x, const _Tp2*) {
williamr@2
   468
  return (per_thread_allocator<_Tp2>&)__x;
williamr@2
   469
}
williamr@2
   470
williamr@2
   471
template <class _Tp1, class _Tp2>
williamr@2
   472
inline per_thread_allocator<_Tp2>
williamr@2
   473
__stl_alloc_create(per_thread_allocator<_Tp1>&, const _Tp2*) {
williamr@2
   474
  return per_thread_allocator<_Tp2>();
williamr@2
   475
}
williamr@2
   476
williamr@2
   477
#endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
williamr@2
   478
williamr@2
   479
_STLP_END_NAMESPACE
williamr@2
   480
williamr@2
   481
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
williamr@2
   482
#  include <stl/_pthread_alloc.c>
williamr@2
   483
# endif
williamr@2
   484
williamr@2
   485
#endif /* _STLP_PTHREAD_ALLOC */
williamr@2
   486
williamr@2
   487
// Local Variables:
williamr@2
   488
// mode:C++
williamr@2
   489
// End: