Skip to content

Commit

Permalink
Don't crash, only warn, if hooks are not disconnected before exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Oct 29, 2014
1 parent e4ce9f7 commit 024075f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/libaudcore/eventqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <pthread.h>
#include <string.h>

#include "internal.h"
#include "list.h"
#include "mainloop.h"
#include "objects.h"
Expand Down Expand Up @@ -101,7 +102,7 @@ EXPORT void event_queue_cancel (const char * name, void * data)
pthread_mutex_unlock (& mutex);
}

EXPORT void event_queue_cancel_all (void)
void event_queue_cancel_all ()
{
pthread_mutex_lock (& mutex);
events.clear ();
Expand Down
15 changes: 15 additions & 0 deletions src/libaudcore/hook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
#include <pthread.h>

#include "index.h"
#include "internal.h"
#include "multihash.h"
#include "objects.h"
#include "runtime.h"

struct HookItem {
HookFunction func;
Expand Down Expand Up @@ -124,3 +126,16 @@ EXPORT void hook_call (const char * name, void * data)
DONE:
pthread_mutex_unlock (& mutex);
}

void leak_cb (const String & name, HookList & list, void *)
{
AUDWARN ("Hook not disconnected: %s (%d)\n", (const char *) name, list.items.len ());
}

void hook_cleanup ()
{
pthread_mutex_lock (& mutex);
hooks.iterate (leak_cb, nullptr);
hooks.clear ();
pthread_mutex_unlock (& mutex);
}
3 changes: 0 additions & 3 deletions src/libaudcore/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ void event_queue_full (const char * name, void * data, EventDestroyFunc destroy)
* all hook calls matching <name> are canceled. */
void event_queue_cancel (const char * name, void * data);

/* Cancels all pending hook calls. */
void event_queue_cancel_all (void);

/* Convenience wrapper for C++ classes. Allows non-static member functions to
* be used as hook callbacks. The HookReceiver should be made a member of the
* class in question so that hook_dissociate() is called automatically from the
Expand Down
66 changes: 36 additions & 30 deletions src/libaudcore/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ class Tuple;

typedef bool (* DirForeachFunc) (const char * path, const char * basename, void * user);

/* adder.c */
void adder_cleanup (void);
/* adder.cc */
void adder_cleanup ();

/* art.c */
void art_init (void);
void art_cleanup (void);
/* art.cc */
void art_init ();
void art_cleanup ();

/* art-search.c */
/* art-search.cc */
String art_search (const char * filename);

/* charset.c */
void chardet_init (void);
void chardet_cleanup (void);
/* charset.cc */
void chardet_init ();
void chardet_cleanup ();

/* config.c */
void config_load (void);
void config_save (void);
void config_cleanup (void);
/* config.cc */
void config_load ();
void config_save ();
void config_cleanup ();

/* effect.c */
/* effect.cc */
void effect_start (int & channels, int & rate);
Index<float> & effect_process (Index<float> & data);
bool effect_flush (bool force);
Expand All @@ -61,31 +61,37 @@ int effect_adjust_delay (int delay);
bool effect_plugin_start (PluginHandle * plugin);
void effect_plugin_stop (PluginHandle * plugin);

/* equalizer.c */
void eq_init (void);
void eq_cleanup (void);
/* equalizer.cc */
void eq_init ();
void eq_cleanup ();
void eq_set_format (int new_channels, int new_rate);
void eq_filter (float * data, int samples);

/* fft.c */
/* eventqueue.cc */
void event_queue_cancel_all ();

/* fft.cc */
void calc_freq (const float data[512], float freq[256]);

/* interface.c */
PluginHandle * iface_plugin_probe (void);
PluginHandle * iface_plugin_get_current (void);
/* hook.cc */
void hook_cleanup ();

/* interface.cc */
PluginHandle * iface_plugin_probe ();
PluginHandle * iface_plugin_get_current ();
bool iface_plugin_set_current (PluginHandle * plugin);

void interface_run (void);
void interface_run ();

/* playback.c */
/* playback.cc */
/* do not call these; use aud_drct_play/stop() instead */
void playback_play (int seek_time, bool pause);
void playback_stop (void);
void playback_stop ();

/* probe-buffer.c */
/* probe-buffer.cc */
VFSFile probe_buffer_new (const char * filename);

/* util.c */
/* util.cc */
const char * get_home_utf8 ();
bool dir_foreach (const char * path, DirForeachFunc func, void * user_data);
String write_temp_file (void * data, int64_t len);
Expand All @@ -96,15 +102,15 @@ void cut_path_element (char * path, int pos);

unsigned int32_hash (unsigned val);

/* vis-runner.c */
/* vis-runner.cc */
void vis_runner_start_stop (bool playing, bool paused);
void vis_runner_pass_audio (int time, const Index<float> & data, int channels, int rate);
void vis_runner_flush (void);
void vis_runner_flush ();
void vis_runner_enable (bool enable);

/* visualization.c */
/* visualization.cc */
void vis_activate (bool activate);
void vis_send_clear (void);
void vis_send_clear ();
void vis_send_audio (const float * data, int channels);

bool vis_plugin_start (PluginHandle * plugin);
Expand Down
1 change: 1 addition & 0 deletions src/libaudcore/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ EXPORT void aud_cleanup ()
playlist_end ();

event_queue_cancel_all ();
hook_cleanup ();

config_save ();
config_cleanup ();
Expand Down

0 comments on commit 024075f

Please sign in to comment.