Commit 55ddfe8ef53f0eb01be4c9450a7f2241e745cb11

Authored by Jan Kiszka
Committed by Anthony Liguori
1 parent 76e30d0f

Rework reset handler management

Convert the reset handler maintenance code to TAILQ services.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 6 additions and 10 deletions
@@ -3442,12 +3442,13 @@ void vm_start(void) @@ -3442,12 +3442,13 @@ void vm_start(void)
3442 /* reset/shutdown handler */ 3442 /* reset/shutdown handler */
3443 3443
3444 typedef struct QEMUResetEntry { 3444 typedef struct QEMUResetEntry {
  3445 + TAILQ_ENTRY(QEMUResetEntry) entry;
3445 QEMUResetHandler *func; 3446 QEMUResetHandler *func;
3446 void *opaque; 3447 void *opaque;
3447 - struct QEMUResetEntry *next;  
3448 } QEMUResetEntry; 3448 } QEMUResetEntry;
3449 3449
3450 -static QEMUResetEntry *first_reset_entry; 3450 +static TAILQ_HEAD(reset_handlers, QEMUResetEntry) reset_handlers =
  3451 + TAILQ_HEAD_INITIALIZER(reset_handlers);
3451 static int reset_requested; 3452 static int reset_requested;
3452 static int shutdown_requested; 3453 static int shutdown_requested;
3453 static int powerdown_requested; 3454 static int powerdown_requested;
@@ -3501,16 +3502,11 @@ static void do_vm_stop(int reason) @@ -3501,16 +3502,11 @@ static void do_vm_stop(int reason)
3501 3502
3502 void qemu_register_reset(QEMUResetHandler *func, void *opaque) 3503 void qemu_register_reset(QEMUResetHandler *func, void *opaque)
3503 { 3504 {
3504 - QEMUResetEntry **pre, *re; 3505 + QEMUResetEntry *re = qemu_mallocz(sizeof(QEMUResetEntry));
3505 3506
3506 - pre = &first_reset_entry;  
3507 - while (*pre != NULL)  
3508 - pre = &(*pre)->next;  
3509 - re = qemu_mallocz(sizeof(QEMUResetEntry));  
3510 re->func = func; 3507 re->func = func;
3511 re->opaque = opaque; 3508 re->opaque = opaque;
3512 - re->next = NULL;  
3513 - *pre = re; 3509 + TAILQ_INSERT_TAIL(&reset_handlers, re, entry);
3514 } 3510 }
3515 3511
3516 void qemu_system_reset(void) 3512 void qemu_system_reset(void)
@@ -3518,7 +3514,7 @@ void qemu_system_reset(void) @@ -3518,7 +3514,7 @@ void qemu_system_reset(void)
3518 QEMUResetEntry *re; 3514 QEMUResetEntry *re;
3519 3515
3520 /* reset all devices */ 3516 /* reset all devices */
3521 - for(re = first_reset_entry; re != NULL; re = re->next) { 3517 + TAILQ_FOREACH(re, &reset_handlers, entry) {
3522 re->func(re->opaque); 3518 re->func(re->opaque);
3523 } 3519 }
3524 } 3520 }