+
+ /* Close any open resource files */
+ if(glk_data->resource_map != NULL) {
+ giblorb_destroy_map(glk_data->resource_map);
+ glk_stream_close(glk_data->resource_file, NULL);
+ }
+
+ /* Unref the input queues */
+ g_async_queue_unref(glk_data->char_input_queue);
+ g_async_queue_unref(glk_data->line_input_queue);
+
+ /* Wait for any pending window rearrange */
+ g_mutex_lock(glk_data->arrange_lock);
+ if(glk_data->needs_rearrange)
+ g_cond_wait(glk_data->rearranged, glk_data->arrange_lock);
+ g_mutex_unlock(glk_data->arrange_lock);
+
+ /* Default handler for 'stopped' unloads the plugin, so be absolutely sure
+ we're not calling any dispatch callbacks after this point */
+ if(!glk_data->in_startup)
+ g_signal_emit_by_name(glk_data->self, "stopped");
+
+ _chimara_glk_free_nonwindow_private_data(glk_data);
+ glk_data->needs_reset = TRUE;