Changeset 6e41e73 for lib/data-struct


Ignore:
Timestamp:
11/27/14 14:19:19 (8 years ago)
Author:
Richard Sanger <rsangerarj@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d7fd648
Parents:
21f5f0f
Message:

Fixes bug where packets could be destroyed by unregistered threads
We now destroy the packet object cache thread caches before unresistering a thread

Also includes some whitespace fixes.

Location:
lib/data-struct
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/data-struct/object_cache.c

    r78911b5 r6e41e73  
    1 
    21#include "object_cache.h"
    32#include <assert.h>
     
    3433
    3534/**
    36  * @brief free_array assumes we DONT hold spin
     35 * @brief unregister_thread assumes we DONT hold spin
    3736 */
    3837static inline void unregister_thread(struct local_cache *lc) {
     
    7170
    7271/**
    73  * @brief free_array assumes we hold spin!!!
     72 * @brief register_thread assumes we DONT hold spin
    7473 */
    7574static inline void register_thread(libtrace_ocache_t *oc, struct local_cache *lc) {
     
    429428}
    430429
     430/**
     431 * @brief ocache_unregister_thread removes a thread from an ocache.
     432 * @param The ocache to remove this thread, this will free any packets in the TLS cache
     433 */
     434DLLEXPORT void libtrace_ocache_unregister_thread(libtrace_ocache_t *oc) {
     435        size_t i;
     436        struct local_cache *lc = find_cache(oc);
     437
     438        if (lc) {
     439                for (i = 0; i < t_mem_caches_used; ++i) {
     440                        if (&t_mem_caches[i] == lc) {
     441                                // Free the cache against the ocache
     442                                unregister_thread(&t_mem_caches[i]);
     443                                free(t_mem_caches[i].cache);
     444                                // And remove it from the thread itself
     445                                --t_mem_caches_used;
     446                                t_mem_caches[i] = t_mem_caches[t_mem_caches_used];
     447                                memset(&t_mem_caches[t_mem_caches_used], 0, sizeof(struct local_cache));
     448                        }
     449                }
     450        }
     451}
  • lib/data-struct/object_cache.h

    ra49a9eb r6e41e73  
    2121
    2222DLLEXPORT void libtrace_ocache_init(libtrace_ocache_t *oc, void *(*alloc)(void), void (*free)(void*),
    23                                                                           size_t thread_cache_size, size_t buffer_size, bool limit_size);
     23                                    size_t thread_cache_size, size_t buffer_size, bool limit_size);
    2424DLLEXPORT int libtrace_ocache_destroy(libtrace_ocache_t *oc);
    2525DLLEXPORT size_t libtrace_ocache_alloc(libtrace_ocache_t *oc, void *values[], size_t nb_buffers, size_t min_nb_buffers);
    2626DLLEXPORT size_t libtrace_ocache_free(libtrace_ocache_t *oc, void *values[], size_t nb_buffers, size_t min_nb_buffers);
    2727DLLEXPORT void libtrace_zero_ocache(libtrace_ocache_t *oc);
     28DLLEXPORT void libtrace_ocache_unregister_thread(libtrace_ocache_t *oc);
    2829#endif // LIBTRACE_OBJECT_CACHE_H
    29 
    30 
Note: See TracChangeset for help on using the changeset viewer.