/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
*/
/*
* Copyright 2016 Joyent, Inc.
*/
#include <pthread.h>
#include <thread.h>
#include <synch.h>
#include <threads.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
/*
*
* In illumos, the underlying implementation of lock related routines is the
* same between pthreads and traditional SunOS routines. The same is true with
* the C11 routines. Their types are actually just typedef's to other things.
* Thus in the implementation here, we treat this as a wrapper around existing
* thread related routines and don't sweet the extra indirection.
*
* Note that in many places the C standard doesn't allow for errors to be
* returned. In those cases, if we have an instance of programmer error
* (something resulting in EINVAL), we opt to abort the program as we don't have
* much other recourse available.
*/
void
{
abort();
}
int
{
int ret;
if (ret == 0)
return (thrd_success);
else
return (thrd_error);
}
void
{
if (pthread_cond_destroy(cnd) != 0)
abort();
}
int
{
int ret;
if (ret == 0)
return (thrd_success);
return (thrd_error);
}
int
{
int ret;
if (ret == 0)
return (thrd_success);
else
return (thrd_error);
}
/* ARGSUSED */
int
{
int ret;
if (ret == 0)
return (thrd_success);
return (thrd_timedout);
return (thrd_error);
}
/* ARGSUSED */
int
{
int ret;
if (ret == 0)
return (thrd_success);
return (thrd_error);
}
void
{
if (pthread_mutex_destroy(mtx) != 0)
abort();
}
int
{
int mtype;
switch (type) {
case mtx_plain:
case mtx_timed:
break;
case mtx_plain | mtx_recursive:
case mtx_timed | mtx_recursive:
break;
default:
return (thrd_error);
}
/*
* Here, we buck the trend and use the traditional SunOS routine. It's
* much simpler than fighting with pthread attributes.
*/
return (thrd_success);
return (thrd_error);
}
int
{
if (pthread_mutex_lock(mtx) == 0)
return (thrd_success);
return (thrd_error);
}
int
{
int ret;
return (thrd_timedout);
else if (ret != 0)
return (thrd_error);
return (thrd_success);
}
int
{
int ret;
if (ret == 0)
return (thrd_success);
return (thrd_busy);
else
return (thrd_error);
}
int
{
if (pthread_mutex_unlock(mtx) == 0)
return (thrd_success);
return (thrd_error);
}
int
{
int ret;
if (ret == 0)
return (thrd_success);
return (thrd_nomem);
else
return (thrd_error);
}
thrd_current(void)
{
return (pthread_self());
}
int
{
if (pthread_detach(thr) == 0)
return (thrd_success);
return (thrd_error);
}
int
{
}
_NORETURN_KYWD void
{
}
int
{
void *es;
return (thrd_error);
return (thrd_success);
}
/*
* thrd_sleep has somewhat odd standardized return values. It doesn't use the
* same returns values as the thrd_* family of functions at all.
*/
int
{
int ret;
return (0);
return (-1);
return (-2);
}
void
thrd_yield(void)
{
thr_yield();
}
int
{
return (thrd_success);
return (thrd_error);
}
void
{
if (pthread_key_delete(key) != 0)
abort();
}
void *
{
return (pthread_getspecific(key));
}
int
{
return (thrd_success);
return (thrd_error);
}