Cleanup any allocated event queue data
This commit is contained in:
parent
ad4b523edc
commit
e85d95a659
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2001-2013 Stephen Williams (steve@icarus.com)
|
* Copyright (c) 2001-2015 Stephen Williams (steve@icarus.com)
|
||||||
*
|
*
|
||||||
* This source code is free software; you can redistribute it
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
# include "config.h"
|
||||||
# include "schedule.h"
|
# include "schedule.h"
|
||||||
# include "vthread.h"
|
# include "vthread.h"
|
||||||
# include "vpi_priv.h"
|
# include "vpi_priv.h"
|
||||||
|
|
@ -27,8 +28,11 @@
|
||||||
# include <csignal>
|
# include <csignal>
|
||||||
# include <cstdlib>
|
# include <cstdlib>
|
||||||
# include <cassert>
|
# include <cassert>
|
||||||
|
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
# include "vvp_cleanup.h"
|
||||||
|
# include "ivl_alloc.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned long count_assign_events = 0;
|
unsigned long count_assign_events = 0;
|
||||||
unsigned long count_gen_events = 0;
|
unsigned long count_gen_events = 0;
|
||||||
|
|
@ -1137,4 +1141,21 @@ void schedule_simulate(void)
|
||||||
|
|
||||||
// Execute post-simulation callbacks
|
// Execute post-simulation callbacks
|
||||||
vpiPostsim();
|
vpiPostsim();
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
schedule_delete();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
void schedule_delete(void)
|
||||||
|
{
|
||||||
|
vthread_event_heap.delete_pool();
|
||||||
|
assign4_heap.delete_pool();
|
||||||
|
assign8_heap.delete_pool();
|
||||||
|
assignr_heap.delete_pool();
|
||||||
|
array_w_heap.delete_pool();
|
||||||
|
array_r_w_heap.delete_pool();
|
||||||
|
generic_event_heap.delete_pool();
|
||||||
|
event_time_heap.delete_pool();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
||||||
39
vvp/slab.h
39
vvp/slab.h
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef IVL_slab_H
|
#ifndef IVL_slab_H
|
||||||
#define IVL_slab_H
|
#define IVL_slab_H
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008-2014 Picture Elements, Inc.
|
* Copyright (c) 2008-2015 Picture Elements, Inc.
|
||||||
* Stephen Williams (steve@icarus.com)
|
* Stephen Williams (steve@icarus.com)
|
||||||
*
|
*
|
||||||
* This source code is free software; you can redistribute it
|
* This source code is free software; you can redistribute it
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
# include "config.h"
|
||||||
|
|
||||||
template <size_t SLAB_SIZE, size_t CHUNK_COUNT> class slab_t {
|
template <size_t SLAB_SIZE, size_t CHUNK_COUNT> class slab_t {
|
||||||
|
|
||||||
union item_cell_u {
|
union item_cell_u {
|
||||||
|
|
@ -33,12 +35,22 @@ template <size_t SLAB_SIZE, size_t CHUNK_COUNT> class slab_t {
|
||||||
|
|
||||||
void* alloc_slab();
|
void* alloc_slab();
|
||||||
void free_slab(void*);
|
void free_slab(void*);
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
// If we have allocated memory then we need to delete it to make
|
||||||
|
// valgrind happy.
|
||||||
|
void delete_pool(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
unsigned long pool;
|
unsigned long pool;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
item_cell_u*heap_;
|
item_cell_u*heap_;
|
||||||
item_cell_u initial_chunk_[CHUNK_COUNT];
|
item_cell_u initial_chunk_[CHUNK_COUNT];
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
// Each slab needs a pointer to the allocated space.
|
||||||
|
item_cell_u**slab_pool;
|
||||||
|
unsigned slab_pool_count;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template <size_t SLAB_SIZE, size_t CHUNK_COUNT>
|
template <size_t SLAB_SIZE, size_t CHUNK_COUNT>
|
||||||
|
|
@ -50,6 +62,11 @@ slab_t<SLAB_SIZE,CHUNK_COUNT>::slab_t()
|
||||||
initial_chunk_[idx].next = initial_chunk_+idx+1;
|
initial_chunk_[idx].next = initial_chunk_+idx+1;
|
||||||
|
|
||||||
initial_chunk_[CHUNK_COUNT-1].next = 0;
|
initial_chunk_[CHUNK_COUNT-1].next = 0;
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
// Initially we have no allocated space.
|
||||||
|
slab_pool = NULL;
|
||||||
|
slab_pool_count = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t SLAB_SIZE, size_t CHUNK_COUNT>
|
template <size_t SLAB_SIZE, size_t CHUNK_COUNT>
|
||||||
|
|
@ -57,6 +74,12 @@ inline void* slab_t<SLAB_SIZE,CHUNK_COUNT>::alloc_slab()
|
||||||
{
|
{
|
||||||
if (heap_ == 0) {
|
if (heap_ == 0) {
|
||||||
item_cell_u*chunk = new item_cell_u[CHUNK_COUNT];
|
item_cell_u*chunk = new item_cell_u[CHUNK_COUNT];
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
slab_pool_count += 1;
|
||||||
|
slab_pool = (item_cell_u **) realloc(slab_pool,
|
||||||
|
slab_pool_count*sizeof(item_cell_u **));
|
||||||
|
slab_pool[slab_pool_count-1] = chunk;
|
||||||
|
#endif
|
||||||
for (unsigned idx = 0 ; idx < CHUNK_COUNT ; idx += 1) {
|
for (unsigned idx = 0 ; idx < CHUNK_COUNT ; idx += 1) {
|
||||||
chunk[idx].next = heap_;
|
chunk[idx].next = heap_;
|
||||||
heap_ = chunk+idx;
|
heap_ = chunk+idx;
|
||||||
|
|
@ -77,4 +100,18 @@ inline void slab_t<SLAB_SIZE,CHUNK_COUNT>::free_slab(void*ptr)
|
||||||
heap_ = cur;
|
heap_ = cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CHECK_WITH_VALGRIND
|
||||||
|
template <size_t SLAB_SIZE, size_t CHUNK_COUNT>
|
||||||
|
inline void slab_t<SLAB_SIZE,CHUNK_COUNT>::delete_pool(void)
|
||||||
|
{
|
||||||
|
for (unsigned idx = 0; idx < slab_pool_count; idx += 1) {
|
||||||
|
delete [] slab_pool[idx];
|
||||||
|
}
|
||||||
|
free(slab_pool);
|
||||||
|
slab_pool = NULL;
|
||||||
|
slab_pool_count = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* IVL_slab_H */
|
#endif /* IVL_slab_H */
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef IVL_vvp_cleanup_H
|
#ifndef IVL_vvp_cleanup_H
|
||||||
#define IVL_vvp_cleanup_H
|
#define IVL_vvp_cleanup_H
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009-2014 Cary R. (cygcary@yahoo.com)
|
* Copyright (c) 2009-2015 Cary R. (cygcary@yahoo.com)
|
||||||
*
|
*
|
||||||
* This source code is free software; you can redistribute it
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -33,6 +33,7 @@ extern void vpi_mcd_delete(void);
|
||||||
extern void load_module_delete(void);
|
extern void load_module_delete(void);
|
||||||
extern void modpath_delete(void);
|
extern void modpath_delete(void);
|
||||||
extern void root_table_delete(void);
|
extern void root_table_delete(void);
|
||||||
|
extern void schedule_delete(void);
|
||||||
extern void signal_pool_delete(void);
|
extern void signal_pool_delete(void);
|
||||||
extern void simulator_cb_delete(void);
|
extern void simulator_cb_delete(void);
|
||||||
extern void udp_defns_delete(void);
|
extern void udp_defns_delete(void);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue