genericopenlibs/cppstdlib/stl/src/allocators.cpp
branchRCL_3
changeset 56 acd3cd4aaceb
parent 54 4332f0f7be53
child 57 2efc27d87e1c
equal deleted inserted replaced
54:4332f0f7be53 56:acd3cd4aaceb
    37 
    37 
    38 #include <stl/_threads.h>
    38 #include <stl/_threads.h>
    39 
    39 
    40 #include "lock_free_slist.h"
    40 #include "lock_free_slist.h"
    41 
    41 
    42 
       
    43 #if defined(__SYMBIAN32__WSD__)
    42 #if defined(__SYMBIAN32__WSD__)
    44 #include "libstdcppwsd.h"
    43 #include "libstdcppwsd.h"
    45 
    44 
    46 #define __oom_handler 	get_oom_handler()
    45 #define __oom_handler 	get_oom_handler()
    47 #define _S_lock 		get_allocator_S_lock()
    46 #define _S_lock 		get_allocator_S_lock()
   373   // Beginning of the linked list of allocated chunks of memory
   372   // Beginning of the linked list of allocated chunks of memory
   374   static _ChunkList _S_chunks;
   373   static _ChunkList _S_chunks;
   375 #endif /* _STLP_DO_CLEAN_NODE_ALLOC */
   374 #endif /* _STLP_DO_CLEAN_NODE_ALLOC */
   376 
   375 
   377 public:
   376 public:
   378 
       
   379   /* __n must be > 0      */
   377   /* __n must be > 0      */
   380   static void* _M_allocate(size_t& __n);
   378   static void* _M_allocate(size_t& __n);
   381   /* __p may not be 0 */
   379   /* __p may not be 0 */
   382   static void _M_deallocate(void *__p, size_t __n);
   380   static void _M_deallocate(void *__p, size_t __n);
   383   
   381   
   386 #endif
   384 #endif
   387 };
   385 };
   388 
   386 
   389 #if !defined (_STLP_USE_LOCK_FREE_IMPLEMENTATION)
   387 #if !defined (_STLP_USE_LOCK_FREE_IMPLEMENTATION)
   390 void* __node_alloc_impl::_M_allocate(size_t& __n) {
   388 void* __node_alloc_impl::_M_allocate(size_t& __n) {
   391 
       
   392   __n = _S_round_up(__n);
   389   __n = _S_round_up(__n);
   393   _Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
   390   _Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
   394   _Obj *__r;
   391   _Obj *__r;
   395 
   392 
   396   // Acquire the lock here with a constructor call.
   393   // Acquire the lock here with a constructor call.
   409   // lock is released here
   406   // lock is released here
   410   return __r;
   407   return __r;
   411 }
   408 }
   412 
   409 
   413 void __node_alloc_impl::_M_deallocate(void *__p, size_t __n) {
   410 void __node_alloc_impl::_M_deallocate(void *__p, size_t __n) {
   414    
       
   415   _Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
   411   _Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
   416   _Obj * __pobj = __STATIC_CAST(_Obj*, __p);
   412   _Obj * __pobj = __STATIC_CAST(_Obj*, __p);
   417 
   413 
   418   // acquire lock
   414   // acquire lock
   419   _Node_Alloc_Lock __lock_instance;
   415   _Node_Alloc_Lock __lock_instance;