reds: Remove a weak pointer usage

RedCharDevice can all be removed just calling unref, beside
the agent that needs special threatment.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
Frediano Ziglio 2020-03-05 13:01:27 +00:00 committed by Frediano Ziglio
parent f4aefa728e
commit 43c6bf91b7
5 changed files with 6 additions and 33 deletions

View File

@ -242,7 +242,6 @@ void red_char_device_write_buffer_release(RedCharDevice *dev,
RedCharDevice *spicevmc_device_connect(RedsState *reds,
SpiceCharDeviceInstance *sin,
uint8_t channel_type);
void spicevmc_device_disconnect(SpiceCharDeviceInstance *char_device);
SpiceCharDeviceInstance *red_char_device_get_device_instance(RedCharDevice *dev);

View File

@ -3201,8 +3201,7 @@ static void reds_add_char_device(RedsState *reds, RedCharDevice *dev)
reds->char_devices = g_list_append(reds->char_devices, dev);
}
static void reds_on_char_device_destroy(RedsState *reds,
RedCharDevice *dev)
static void reds_remove_char_device(RedsState *reds, RedCharDevice *dev)
{
g_return_if_fail(reds != NULL);
g_warn_if_fail(g_list_find(reds->char_devices, dev) != NULL);
@ -3252,9 +3251,6 @@ spice_server_char_device_add_interface(SpiceServer *reds, SpiceBaseInstance *sin
* just a sanity check to ensure that assumption is correct */
spice_assert(dev_state == char_device->st);
g_object_weak_ref(G_OBJECT(dev_state),
(GWeakNotify)reds_on_char_device_destroy,
reds);
/* setting the char_device state to "started" for backward compatibily with
* qemu releases that don't call spice api for start/stop (not implemented yet) */
if (reds->vm_running) {
@ -3281,19 +3277,12 @@ static int spice_server_char_device_remove_interface(RedsState *reds, SpiceBaseI
red_char_device_reset_dev_instance(reds->agent_dev, NULL);
}
}
#ifdef USE_SMARTCARD
else if (strcmp(char_device->subtype, SUBTYPE_SMARTCARD) == 0) {
smartcard_device_disconnect(char_device);
}
#endif
else if (strcmp(char_device->subtype, SUBTYPE_USBREDIR) == 0 ||
strcmp(char_device->subtype, SUBTYPE_PORT) == 0) {
spicevmc_device_disconnect(char_device);
} else {
spice_warning("failed to remove char device %s", char_device->subtype);
}
char_device->st = NULL;
if (char_device->st) {
reds_remove_char_device(reds, char_device->st);
char_device->st->unref();
char_device->st = NULL;
}
return 0;
}

View File

@ -242,13 +242,6 @@ static RedCharDeviceSmartcard *smartcard_device_new(RedsState *reds, SpiceCharDe
return dev;
}
void smartcard_device_disconnect(SpiceCharDeviceInstance *char_device)
{
g_return_if_fail(RED_IS_CHAR_DEVICE_SMARTCARD(char_device->st));
char_device->st->unref();
}
RedCharDevice *smartcard_device_connect(RedsState *reds, SpiceCharDeviceInstance *char_device)
{
RedCharDeviceSmartcard *dev;

View File

@ -44,7 +44,6 @@ struct RedCharDeviceSmartcardClass: public RedCharDeviceClass
* connect to smartcard interface, used by smartcard channel
*/
RedCharDevice *smartcard_device_connect(RedsState *reds, SpiceCharDeviceInstance *char_device);
void smartcard_device_disconnect(SpiceCharDeviceInstance *char_device);
void smartcard_channel_write_to_reader(RedCharDeviceWriteBuffer *write_buf);
SpiceCharDeviceInstance* smartcard_readers_get(uint32_t reader_id);
SpiceCharDeviceInstance *smartcard_readers_get_unattached(void);

View File

@ -688,13 +688,6 @@ RedCharDevice *spicevmc_device_connect(RedsState *reds,
return dev;
}
/* Must be called from RedClient handling thread. */
void spicevmc_device_disconnect(SpiceCharDeviceInstance *sin)
{
sin->st->unref();
sin->st = NULL;
}
static void spicevmc_port_event(RedCharDevice *char_dev, uint8_t event)
{
RedVmcChannel *channel;