This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Diff mt_allocator part 2 of item 3


Hi,

here's the rest of item 3:
- If a thread, when it dies, still has memory on it's freelist this memory is not returned to global list anymore which simplifies both _S_get_thread_id and _S_thread_key_destr.
- Fixed minor typos.
- Added keyword volatile to the appropriate global vars.


Brgds

/Stefan
182c182
<         block_record* volatile next;
---
>         block_record* next;
185a186
>          * All blocks are initially "owned" by global pool thread id 0.
197,198c198,199
<         block_record** volatile first;
<         block_record** volatile last;
---
>         block_record** first;
>         block_record** last;
206,207c207,208
<         size_t* volatile free;
<         size_t* volatile used;
---
>         size_t* free;
>         size_t* used;
223c224
<       static bin_record* volatile _S_bin;
---
>       static bin_record* _S_bin;
641d641
< 
648c648
<           _S_bin[bin].mutex =(__gthread_mutex_t*) malloc(sizeof(__gthread_mutex_t));
---
>           _S_bin[bin].mutex =(__gthread_mutex_t*)  malloc(sizeof(__gthread_mutex_t));
679a680,708
>        * If the thread - when it dies - still has records on its
>        * freelist we return them to the global pool here.
>        */
>       for (size_t bin = 0; bin < _S_no_of_bins; bin++)
>         {
>           block_record* block =
>             _S_bin[bin].first[((thread_record*)freelist_pos)->id];
> 
>           if (block != NULL)
>             {
>               __gthread_mutex_lock(_S_bin[bin].mutex);
>               while (block != NULL)
>                 {
>                   if (_S_bin[bin].first[0] == NULL)
>                     _S_bin[bin].first[0] = block;
>                   else
>                     _S_bin[bin].last[0]->next = block;
> 
>                   _S_bin[bin].last[0] = block;
>                   block = block->next;
>                   _S_bin[bin].free[0]++;
>                 }
> 
>               _S_bin[bin].last[0]->next = NULL;
>               __gthread_mutex_unlock(_S_bin[bin].mutex);
>             }
>         }
> 
>       /*
701c730
<           thread_record* freelist_pos;
---
>           thread_record* volatile freelist_pos;
716a746,760
> 
>               /*
>                * Since thread_ids may/will be reused (espcially in
>                * producer/consumer applications) we make sure that the
>                * list pointers and free counter is reset BUT as the
>                * "old" thread may still be owner of some memory (which
>                * is referred to by other threads and thus not freed)
>                * we don't reset the used counter.
>                */
>               for (size_t bin = 0; bin < _S_no_of_bins; bin++)
>                 {
>                   _S_bin[bin].first[freelist_pos->id] = NULL;
>                   _S_bin[bin].last[freelist_pos->id] = NULL;
>                   _S_bin[bin].free[freelist_pos->id] = 0;
>                 }
798c842
<   volatile __mt_alloc<_Tp>::_S_bin = NULL;
---
>   __mt_alloc<_Tp>::_S_bin = NULL;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]