#include <stdio.h>
#include <sys/param.h>
#include <sys/dir.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <unistd.h>
#include <mach/machine/thread_status.h>
#include <mach/arm/thread_act.h>
#include "macosx-threads.h"
#include "macosx-low.h"
void
gdb_pthread_kill (pthread_t pthread)
{
mach_port_t mthread;
kern_return_t kret;
int ret;
mthread = pthread_mach_thread_np (pthread);
kret = thread_suspend (mthread);
MACH_CHECK_ERROR (kret);
ret = pthread_cancel (pthread);
if (ret != 0)
{
warning ("Unable to cancel thread: %s (%d)", strerror (errno), errno);
thread_terminate (mthread);
}
kret = thread_abort (mthread);
MACH_CHECK_ERROR (kret);
kret = thread_resume (mthread);
MACH_CHECK_ERROR (kret);
ret = pthread_join (pthread, NULL);
if (ret != 0)
{
warning ("Unable to join to canceled thread: %s (%d)", strerror (errno),
errno);
}
}
pthread_t
gdb_pthread_fork (pthread_fn_t function, void *arg)
{
int result;
pthread_t pthread = NULL;
pthread_attr_t attr;
result = pthread_attr_init (&attr);
if (result != 0)
{
error ("Unable to initialize thread attributes: %s (%d)",
strerror (errno), errno);
}
result = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE);
if (result != 0)
{
error ("Unable to initialize thread attributes: %s (%d)",
strerror (errno), errno);
}
result = pthread_create (&pthread, &attr, function, arg);
if (result != 0)
{
error ("Unable to create thread: %s (%d)", strerror (errno), errno);
}
result = pthread_attr_destroy (&attr);
if (result != 0)
{
warning ("Unable to deallocate thread attributes: %s (%d)",
strerror (errno), errno);
}
return pthread;
}