switch_event 添加引用计数

This commit is contained in:
qiwei 2024-10-19 19:02:55 +08:00
parent a231eec09c
commit c9baac2da9
3 changed files with 15 additions and 5 deletions

View File

@ -100,6 +100,7 @@ struct switch_event {
unsigned long key;
struct switch_event *next;
int flags;
int use_count;
};
typedef struct switch_serial_event_s {

View File

@ -383,7 +383,11 @@ static void event_handler(switch_event_t *event)
}
if (send) {
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
clone = event;
clone->use_count += 1;
//if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
if (clone) {
qstatus = switch_queue_trypush(l->event_queue, clone);
if (qstatus == SWITCH_STATUS_SUCCESS) {
if (l->lost_events) {
@ -401,7 +405,9 @@ static void event_handler(switch_event_t *event)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Killing listener because of too many lost events. Lost [%d] Queue size[%u/%u]\n", l->lost_events, qsize, MAX_QUEUE_LEN);
kill_listener(l, "killed listener because of lost events\n");
}
switch_event_destroy(&clone);
//switch_event_destroy(&clone);
clone->use_count -= 1;
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(l->session), SWITCH_LOG_ERROR, "Memory Error!\n");

View File

@ -418,8 +418,10 @@ SWITCH_DECLARE(void) switch_event_deliver(switch_event_t **event)
}
switch_thread_rwlock_unlock(RWLOCK);
}
switch_event_destroy(event);
(*event)->use_count -= 1;
if((*event)->use_count <= 0){
switch_event_destroy(event);
}
}
SWITCH_DECLARE(switch_status_t) switch_event_running(void)
@ -782,7 +784,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_subclass_detailed(const char
(*event)->subclass_name = DUP(subclass_name);
switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, "Event-Subclass", subclass_name);
}
(*event)->event_id;
(*event)->use_count = 1;
return SWITCH_STATUS_SUCCESS;
}