shithub: choc

Download patch

ref: 076adeb0aa24e9bdc677435ddb6e444db58d5436
parent: 4d13a1330013cfcf70c8bc13f6183ea404bbdbe4
author: Simon Howard <[email protected]>
date: Sun Aug 30 08:07:04 EDT 2009

Add method to clear all existing callbacks.

Subversion-branch: /branches/opl-branch
Subversion-revision: 1642

--- a/opl/opl.c
+++ b/opl/opl.c
@@ -117,6 +117,14 @@
     }
 }
 
+void OPL_ClearCallbacks(void)
+{
+    if (driver != NULL)
+    {
+        driver->clear_callbacks_func();
+    }
+}
+
 void OPL_Lock(void)
 {
     if (driver != NULL)
--- a/opl/opl.h
+++ b/opl/opl.h
@@ -79,6 +79,10 @@
 
 void OPL_SetCallback(unsigned int ms, opl_callback_t callback, void *data);
 
+// Clear all OPL callbacks that have been set.
+
+void OPL_ClearCallbacks(void);
+
 // Begin critical section, during which, OPL callbacks will not be
 // invoked.
 
--- a/opl/opl_internal.h
+++ b/opl/opl_internal.h
@@ -36,6 +36,7 @@
 typedef void (*opl_set_callback_func)(unsigned int ms,
                                       opl_callback_t callback,
                                       void *data);
+typedef void (*opl_clear_callbacks_func)(void);
 typedef void (*opl_lock_func)(void);
 typedef void (*opl_unlock_func)(void);
 
@@ -48,6 +49,7 @@
     opl_read_port_func read_port_func;
     opl_write_port_func write_port_func;
     opl_set_callback_func set_callback_func;
+    opl_clear_callbacks_func clear_callbacks_func;
     opl_lock_func lock_func;
     opl_unlock_func unlock_func;
 } opl_driver_t;
--- a/opl/opl_linux.c
+++ b/opl/opl_linux.c
@@ -92,6 +92,7 @@
     OPL_Linux_PortRead,
     OPL_Linux_PortWrite,
     OPL_Timer_SetCallback,
+    OPL_Timer_ClearCallbacks,
     OPL_Timer_Lock,
     OPL_Timer_Unlock
 };
--- a/opl/opl_queue.c
+++ b/opl/opl_queue.c
@@ -65,6 +65,11 @@
     return queue->num_entries == 0;
 }
 
+void OPL_Queue_Clear(opl_callback_queue_t *queue)
+{
+    queue->num_entries = 0;
+}
+
 void OPL_Queue_Push(opl_callback_queue_t *queue,
                     opl_callback_t callback, void *data,
                     unsigned int time)
--- a/opl/opl_queue.h
+++ b/opl/opl_queue.h
@@ -32,6 +32,7 @@
 
 opl_callback_queue_t *OPL_Queue_Create(void);
 int OPL_Queue_IsEmpty(opl_callback_queue_t *queue);
+void OPL_Queue_Clear(opl_callback_queue_t *queue);
 void OPL_Queue_Destroy(opl_callback_queue_t *queue);
 void OPL_Queue_Push(opl_callback_queue_t *queue,
                     opl_callback_t callback, void *data,
--- a/opl/opl_sdl.c
+++ b/opl/opl_sdl.c
@@ -374,6 +374,13 @@
     SDL_UnlockMutex(callback_queue_mutex);
 }
 
+static void OPL_SDL_ClearCallbacks(void)
+{
+    SDL_LockMutex(callback_queue_mutex);
+    OPL_Queue_Clear(callback_queue);
+    SDL_UnlockMutex(callback_queue_mutex);
+}
+
 static void OPL_SDL_Lock(void)
 {
     SDL_LockMutex(callback_mutex);
@@ -392,6 +399,7 @@
     OPL_SDL_PortRead,
     OPL_SDL_PortWrite,
     OPL_SDL_SetCallback,
+    OPL_SDL_ClearCallbacks,
     OPL_SDL_Lock,
     OPL_SDL_Unlock
 };
--- a/opl/opl_timer.c
+++ b/opl/opl_timer.c
@@ -202,6 +202,13 @@
     SDL_UnlockMutex(callback_queue_mutex);
 }
 
+void OPL_Timer_ClearCallbacks(void)
+{
+    SDL_LockMutex(callback_queue_mutex);
+    OPL_Queue_Clear(callback_queue);
+    SDL_UnlockMutex(callback_queue_mutex);
+}
+
 void OPL_Timer_Lock(void)
 {
     SDL_LockMutex(timer_mutex);
--- a/opl/opl_timer.h
+++ b/opl/opl_timer.h
@@ -33,6 +33,7 @@
 void OPL_Timer_SetCallback(unsigned int ms,
                            opl_callback_t callback,
                            void *data);
+void OPL_Timer_ClearCallbacks(void);
 void OPL_Timer_Lock(void);
 void OPL_Timer_Unlock(void);