#include <signal.h>
#include <sched.h>
#include <asterisk/io.h>
-#include <pthread.h>
+#include <asterisk/lock.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/select.h>
static char *_argv[256];
static int shuttingdown = 0;
static int restartnow = 0;
-static pthread_t consolethread = (pthread_t) -1;
+static pthread_t consolethread = AST_PTHREADT_NULL;
int ast_register_atexit(void (*func)(void))
{
restartnow = 1;
/* If there is a consolethread running send it a SIGHUP
so it can execvp, otherwise we can do it ourselves */
- if (consolethread != (pthread_t) -1) {
+ if (consolethread != AST_PTHREADT_NULL) {
pthread_kill(consolethread, SIGHUP);
/* Give the signal handler some time to complete */
sleep(2);
fflush(stdout);
if (complete)
/* Wake up a select()ing console */
- if (option_console && consolethread != (pthread_t) -1)
+ if (option_console && consolethread != AST_PTHREADT_NULL)
pthread_kill(consolethread, SIGURG);
}
};
static struct asent *aslist = NULL;
-static pthread_t asthread = (pthread_t) -1;
+static pthread_t asthread = AST_PTHREADT_NULL;
static void *autoservice_run(void *ign)
{
ast_frfree(f);
}
}
- asthread = (pthread_t) -1;
+ asthread = AST_PTHREADT_NULL;
return NULL;
}
struct asent *as;
int needstart;
ast_mutex_lock(&autolock);
- needstart = (asthread == (pthread_t) -1) ? 1 : 0 /* aslist ? 0 : 1 */;
+ needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
as = aslist;
while(as) {
if (as->chan == chan)
if (!chan->_softhangup)
res = 0;
}
- if (asthread != (pthread_t) -1)
+ if (asthread != AST_PTHREADT_NULL)
pthread_kill(asthread, SIGURG);
ast_mutex_unlock(&autolock);
/* Wait for it to un-block */
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
static int restart_monitor(void)
{
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == -2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
ast_log(LOG_WARNING, "Cannot kill myself\n");
return -1;
}
- if (monitor_thread && (monitor_thread != -2)) {
+ if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
/* Wake up the thread */
pthread_kill(monitor_thread, SIGURG);
} else {
}
if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != -2)) {
+ if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
pthread_cancel(monitor_thread);
pthread_kill(monitor_thread, SIGURG);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = (pthread_t) -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
static char accountcode[20];
static int amaflags = 0;
-static pthread_t netthreadid;
+static pthread_t netthreadid = AST_PTHREADT_NULL;
#define IAX_STATE_STARTED (1 << 0)
#define IAX_STATE_AUTHENTICATED (1 << 1)
{
int x;
/* Cancel the network thread, close the net socket */
- pthread_cancel(netthreadid);
- pthread_join(netthreadid, NULL);
+ if (netthreadid != AST_PTHREADT_NULL) {
+ pthread_cancel(netthreadid);
+ pthread_join(netthreadid, NULL);
+ }
close(netsocket);
for (x=0;x<AST_IAX_MAX_CALLS;x++)
if (iaxs[x])
static int amaflags = 0;
static int notransfer = 0;
-static pthread_t netthreadid;
+static pthread_t netthreadid = AST_PTHREADT_NULL;
#define IAX_STATE_STARTED (1 << 0)
#define IAX_STATE_AUTHENTICATED (1 << 1)
{
int x;
/* Cancel the network thread, close the net socket */
- pthread_cancel(netthreadid);
- pthread_join(netthreadid, NULL);
+ if (netthreadid != AST_PTHREADT_NULL) {
+ pthread_cancel(netthreadid);
+ pthread_join(netthreadid, NULL);
+ }
close(netsocket);
for (x=0;x<IAX_MAX_CALLS;x++)
if (iaxs[x])
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == (pthread_t) -2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
return -1;
}
if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != -2)) {
+ if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
pthread_cancel(monitor_thread);
pthread_kill(monitor_thread, SIGURG);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = (pthread_t) -1;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
static int restart_monitor()
{
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == (pthread_t) -2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
ast_log(LOG_WARNING, "Cannot kill myself\n");
return -1;
}
- if (monitor_thread != (pthread_t) -1) {
+ if (monitor_thread != AST_PTHREADT_NULL) {
pthread_cancel(monitor_thread);
/* Nudge it a little, as it's probably stuck in select */
pthread_kill(monitor_thread, SIGURG);
return -1;
}
if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread != (pthread_t) -1 && monitor_thread != (pthread_t) -2) {
+ if (monitor_thread != AST_PTHREADT_NULL && monitor_thread != AST_PTHREADT_STOP) {
pthread_cancel(monitor_thread);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = (pthread_t) -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = -1;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
static int restart_monitor()
{
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == -2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
ast_log(LOG_WARNING, "Cannot kill myself\n");
return -1;
}
- if (monitor_thread != -1) {
+ if (monitor_thread != AST_PTHREADT_NULL) {
pthread_cancel(monitor_thread);
#if 0
pthread_join(monitor_thread, NULL);
return -1;
}
if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread > -1) {
+ if (monitor_thread > AST_PTHREADT_NULL) {
pthread_cancel(monitor_thread);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
static int restart_monitor(void)
{
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == (pthread_t) -2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
return -1;
}
if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && ((int)monitor_thread != -2)) {
+ if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
pthread_cancel(monitor_thread);
pthread_kill(monitor_thread, SIGURG);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = (pthread_t) -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
/* Wait up to 16 seconds for first digit */
static int firstdigittimeout = 16000;
{
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == (pthread_t)-2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
return -1;
}
if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != -2)) {
+ if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
pthread_cancel(monitor_thread);
pthread_kill(monitor_thread, SIGURG);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
static int restart_monitor(void)
{
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == -2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
pthread_kill(monitor_thread, SIGURG);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
/* This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
-static pthread_t monitor_thread = 0;
+static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int restart_monitor(void);
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
/* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == -2)
+ if (monitor_thread == AST_PTHREADT_STOP)
return 0;
if (ast_mutex_lock(&monlock)) {
ast_log(LOG_WARNING, "Unable to lock monitor\n");
return -1;
}
if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != -2)) {
+ if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
pthread_cancel(monitor_thread);
pthread_kill(monitor_thread, SIGURG);
pthread_join(monitor_thread, NULL);
}
- monitor_thread = -2;
+ monitor_thread = AST_PTHREADT_STOP;
ast_mutex_unlock(&monlock);
} else {
ast_log(LOG_WARNING, "Unable to lock the monitor\n");