#if !defined(__FreeBSD__) && !defined(__APPLE__)
#define _POSIX_SOURCE
#endif /* Some BSDs break <sys/socket.h> if this is defined. */
-#define _GNU_SOURCE
+#define _GNU_SOURCE
#define _XOPEN_SOURCE
#define _BSD_TYPES
#define __EXTENSIONS__
/* Find any old empty entry in __mf_pthread_info; mark it used and
return it. Return NULL if there are no more available slots. */
-struct pthread_info*
+struct pthread_info*
__mf_allocate_blank_threadinfo (unsigned* idx)
{
static unsigned probe = LIBMUDFLAPTH_THREADS_MAX-1;
}
}
while (probe != probe_at_start);
-
+
rc = pthread_mutex_unlock (& mutex);
assert (rc == 0);
return NULL;
from this context, since a new thread might just be "booting up",
making printf unsafe to call.
*/
-static struct pthread_info*
+static struct pthread_info*
__mf_find_threadinfo ()
{
pthread_t it = pthread_self ();
else for (i = 0; i < LIBMUDFLAPTH_THREADS_MAX; i++)
{
struct pthread_info* pi2 = & __mf_pthread_info [i];
- if (pi2->used_p && pi2->self == it)
+ if (pi2->used_p && pi2->self == it)
{
*hash = i;
result = pi2;
break;
}
}
- }
+ }
if (result == NULL)
{
if (last != it)
{
/*
- VERBOSE_TRACE ("found threadinfo for %u, slot %u\n",
+ VERBOSE_TRACE ("found threadinfo for %u, slot %u\n",
(unsigned) it,
(unsigned) *hash);
*/
}
-static void
+static void
__mf_pthread_cleanup (void *arg)
{
struct pthread_info *pi = arg;
pi->state = active;
VERBOSE_TRACE ("new user thread\n");
-
+
if (__mf_opts.heur_std_data)
{
pi->thread_errno = & errno;
- __mf_register (pi->thread_errno, sizeof (int),
+ __mf_register (pi->thread_errno, sizeof (int),
__MF_TYPE_GUESS, "errno area (thread)");
/* NB: we could use __MF_TYPE_STATIC above, but we guess that
the thread errno is coming out of some dynamically allocated
/* Signal the main thread to resume. */
psi->thread_info = pi;
-
+
result = (*user_fn)(user_arg);
}
#if PIC
/* A special bootstrap variant. */
int
-__mf_0fn_pthread_create (pthread_t *thr, const pthread_attr_t *attr,
+__mf_0fn_pthread_create (pthread_t *thr, const pthread_attr_t *attr,
void * (*start) (void *), void *arg)
{
return -1;
#undef pthread_create
-WRAPPER(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
+WRAPPER(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
void * (*start) (void *), void *arg)
{
DECLARE(int, munmap, void *p, size_t l);
DECLARE(void *, mmap, void *p, size_t l, int prot, int flags, int fd, off_t of);
- DECLARE(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
+ DECLARE(int, pthread_create, pthread_t *thr, const pthread_attr_t *attr,
void * (*start) (void *), void *arg);
int result;
pthread_attr_t override_attr;
/* VERBOSE_TRACE ("thread %u pi %p stack cleanup deferred (%u)\n",
(unsigned) pi->self, pi, pi->dead_p); */
-
+
/* Delay actual deallocation by a few cycles, try to discourage the
race mentioned at the end of __mf_pthread_spawner(). */
if (pi->dead_p)
#endif
#ifdef MF_MAP_ANON
- override_stack = CALL_REAL (mmap, NULL, override_stacksize,
- PROT_READ|PROT_WRITE,
+ override_stack = CALL_REAL (mmap, NULL, override_stacksize,
+ PROT_READ|PROT_WRITE,
MAP_PRIVATE|MF_MAP_ANON,
0, 0);
#else
if (zerofd == -1)
override_stack = MAP_FAILED;
else
- override_stack = CALL_REAL (mmap, NULL, override_stacksize,
- PROT_READ|PROT_WRITE,
+ override_stack = CALL_REAL (mmap, NULL, override_stacksize,
+ PROT_READ|PROT_WRITE,
MAP_PRIVATE, zerofd, 0);
}
#endif
return -1;
}
- VERBOSE_TRACE ("thread stack alloc %p size %lu\n",
+ VERBOSE_TRACE ("thread stack alloc %p size %lu\n",
override_stack, (unsigned long) override_stacksize);
/* Save the original allocated values for later deallocation. */
override_stack = (void *)
(((uintptr_t) override_stack + override_stacksize - alignment - perturb)
& (~(uintptr_t)(alignment-1)));
-
+
/* XXX: consider using POSIX2K attr_setstack() */
if (pthread_attr_setstackaddr (& override_attr, override_stack) != 0 ||
- pthread_attr_setstacksize (& override_attr,
+ pthread_attr_setstacksize (& override_attr,
override_stacksize - alignment - perturb) != 0)
{
/* This should not happen. */
{
struct pthread_start_info psi;
struct pthread_info *pi = NULL;
-
+
/* Fill in startup-control fields. */
psi.user_fn = start;
psi.user_arg = arg;
psi.thread_info = NULL;
-
+
/* Actually create the thread. */
__mf_state = reentrant;
result = CALL_REAL (pthread_create, thr, & override_attr,
{
volatile struct pthread_start_info *psip = & psi;
pi = psip->thread_info;
- if (pi != NULL)
+ if (pi != NULL)
break;
sched_yield ();
}
__mf_state = reentrant;
result = CALL_REAL (pthread_join, thr, rc);
__mf_state = active;
-
+
return result;
}
/* __mf_state = reentrant; */
CALL_REAL (pthread_exit, rc);
/* NOTREACHED */
+ exit (0); /* Satisfy noreturn attribute of pthread_exit. */
}