Experimental pthread compatibility library

This patch adds pthread compatibility by using libmthread.

To use this with a program using pthreads, you have to replace
  #include <pthread>
with
  #define _MTHREADIFY_PTHREADS
  #include <minix/mthreads>

This also changes the initialization function to be a constructor, which
is implicitly called before the call to main. This allows for
conformance with pthreads, while not paying a high price by checking on
each mthread_* call whether the library has been initialized or not.

As mthread_init is now a constructor, it also has been set as static, and
relevent calls removed from programs using it.

Change-Id: I2aa375db557958d2bee9a70d285aabb990c88f00
This commit is contained in:
2014-07-28 17:05:08 +02:00
parent 29b8e5ff06
commit d3d33afe9f
21 changed files with 306 additions and 93 deletions
+9 -20
View File
@@ -46,8 +46,6 @@ mthread_attr_t *attr;
{
/* Invalidate attribute and deallocate resources. */
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
@@ -72,8 +70,6 @@ mthread_attr_t *attr; /* Attribute */
/* Initialize the attribute to a known state. */
struct __mthread_attr *a;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EAGAIN);
else if (mthread_attr_valid(attr))
@@ -102,8 +98,6 @@ int *detachstate;
/* Get detachstate of a thread attribute */
struct __mthread_attr *a;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
@@ -127,8 +121,6 @@ int detachstate;
/* Set detachstate of a thread attribute */
struct __mthread_attr *a;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
@@ -156,8 +148,6 @@ size_t *stacksize;
/* Get stack attribute */
struct __mthread_attr *a;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
@@ -182,8 +172,6 @@ size_t *stacksize;
/* Get stack size attribute */
struct __mthread_attr *a;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
@@ -208,8 +196,6 @@ size_t stacksize;
/* Set stack attribute */
struct __mthread_attr *a;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
@@ -239,8 +225,6 @@ size_t stacksize;
/* Set stack size attribute */
struct __mthread_attr *a;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
if (attr == NULL)
return(EINVAL);
@@ -283,8 +267,6 @@ mthread_attr_t *a;
/* Check to see if attribute is on the list of valid attributes */
struct __mthread_attr *loopitem;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
loopitem = va_front;
while (loopitem != NULL) {
@@ -307,8 +289,6 @@ int mthread_attr_verify(void)
/* Return true when no attributes are in use */
struct __mthread_attr *loopitem;
MTHREAD_CHECK_INIT(); /* Make sure mthreads is initialized */
loopitem = va_front;
while (loopitem != NULL) {
@@ -320,4 +300,13 @@ int mthread_attr_verify(void)
}
#endif
/* pthread compatibility layer. */
__weak_alias(pthread_attr_destroy, mthread_attr_destroy)
__weak_alias(pthread_attr_getdetachstate, mthread_attr_getdetachstate)
__weak_alias(pthread_attr_getstack, mthread_attr_getstack)
__weak_alias(pthread_attr_getstacksize, mthread_attr_getstacksize)
__weak_alias(pthread_attr_init, mthread_attr_init)
__weak_alias(pthread_attr_setdetachstate, mthread_attr_setdetachstate)
__weak_alias(pthread_attr_setstack, mthread_attr_setstack)
__weak_alias(pthread_attr_setstacksize, mthread_attr_setstacksize)