ast_dial_state_callback state_callback; /*!< Status callback */
AST_LIST_HEAD_NOLOCK(, ast_dial_channel) channels; /*!< Channels being dialed */
pthread_t thread; /*!< Thread (if running in async) */
+ ast_mutex_t lock; /*! Lock to protect the thread information above */
};
/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
pbx_exec(chan, ast_app, args);
/* If another thread is not taking over hang up the channel */
+ ast_mutex_lock(&dial->lock);
if (dial->thread != AST_PTHREADT_STOP) {
ast_hangup(chan);
dial_channel->owner = NULL;
}
+ ast_mutex_unlock(&dial->lock);
return;
}
dial->timeout = -1;
dial->actual_timeout = -1;
+ /* Can't forget about the lock */
+ ast_mutex_init(&dial->lock);
+
return dial;
}
/* Record thread */
thread = dial->thread;
+ /* Boom, commence locking */
+ ast_mutex_lock(&dial->lock);
+
/* Stop the thread */
dial->thread = AST_PTHREADT_STOP;
pthread_kill(thread, SIGURG);
}
+ /* Yay done with it */
+ ast_mutex_unlock(&dial->lock);
+
/* Finally wait for the thread to exit */
pthread_join(thread, NULL);
dial->options[i] = NULL;
}
+ /* Lock be gone! */
+ ast_mutex_destroy(&dial->lock);
+
/* Free structure */
ast_free(dial);