retire PUBLIC, PRIVATE and FORWARD
This commit is contained in:
@@ -7,20 +7,20 @@
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
|
||||
FORWARD int mthread_increase_thread_pool(void);
|
||||
FORWARD void mthread_thread_init(mthread_thread_t thread, mthread_attr_t
|
||||
static int mthread_increase_thread_pool(void);
|
||||
static void mthread_thread_init(mthread_thread_t thread, mthread_attr_t
|
||||
*tattr, void *(*proc)(void *), void *arg);
|
||||
|
||||
FORWARD void mthread_thread_stop(mthread_thread_t thread);
|
||||
FORWARD void mthread_trampoline(void);
|
||||
static void mthread_thread_stop(mthread_thread_t thread);
|
||||
static void mthread_trampoline(void);
|
||||
|
||||
PRIVATE int initialized = 0;
|
||||
static int initialized = 0;
|
||||
#ifndef PGSHIFT
|
||||
# define PGSHIFT 12 /* XXX: temporarily for ACK */
|
||||
#endif
|
||||
#define MTHREAD_GUARDSIZE (1 << PGSHIFT) /* 1 page */
|
||||
|
||||
PRIVATE struct __mthread_attr default_attr = { MTHREAD_STACK_MIN,
|
||||
static struct __mthread_attr default_attr = { MTHREAD_STACK_MIN,
|
||||
NULL,
|
||||
MTHREAD_CREATE_JOINABLE,
|
||||
NULL, NULL };
|
||||
@@ -28,7 +28,7 @@ PRIVATE struct __mthread_attr default_attr = { MTHREAD_STACK_MIN,
|
||||
/*===========================================================================*
|
||||
* mthread_equal *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_equal(l, r)
|
||||
int mthread_equal(l, r)
|
||||
mthread_thread_t l;
|
||||
mthread_thread_t r;
|
||||
{
|
||||
@@ -42,7 +42,7 @@ mthread_thread_t r;
|
||||
/*===========================================================================*
|
||||
* mthread_create *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_create(threadid, tattr, proc, arg)
|
||||
int mthread_create(threadid, tattr, proc, arg)
|
||||
mthread_thread_t *threadid;
|
||||
mthread_attr_t *tattr;
|
||||
void *(*proc)(void *);
|
||||
@@ -78,7 +78,7 @@ void *arg;
|
||||
/*===========================================================================*
|
||||
* mthread_detach *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_detach(detach)
|
||||
int mthread_detach(detach)
|
||||
mthread_thread_t detach;
|
||||
{
|
||||
/* Mark a thread as detached. Consequently, upon exit, resources allocated for
|
||||
@@ -107,7 +107,7 @@ mthread_thread_t detach;
|
||||
/*===========================================================================*
|
||||
* mthread_exit *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_exit(value)
|
||||
void mthread_exit(value)
|
||||
void *value;
|
||||
{
|
||||
/* Make a thread stop running and store the result value. */
|
||||
@@ -143,7 +143,7 @@ void *value;
|
||||
/*===========================================================================*
|
||||
* mthread_find_tcb *
|
||||
*===========================================================================*/
|
||||
PUBLIC mthread_tcb_t * mthread_find_tcb(thread)
|
||||
mthread_tcb_t * mthread_find_tcb(thread)
|
||||
mthread_thread_t thread;
|
||||
{
|
||||
mthread_tcb_t *rt = NULL;
|
||||
@@ -162,7 +162,7 @@ mthread_thread_t thread;
|
||||
/*===========================================================================*
|
||||
* mthread_increase_thread_pool *
|
||||
*===========================================================================*/
|
||||
PRIVATE int mthread_increase_thread_pool(void)
|
||||
static int mthread_increase_thread_pool(void)
|
||||
{
|
||||
/* Increase thread pool. No fancy algorithms, just double the size. */
|
||||
mthread_tcb_t **new_tcb;
|
||||
@@ -223,7 +223,7 @@ PRIVATE int mthread_increase_thread_pool(void)
|
||||
/*===========================================================================*
|
||||
* mthread_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_init(void)
|
||||
void mthread_init(void)
|
||||
{
|
||||
/* Initialize thread system; allocate thread structures and start creating
|
||||
* threads.
|
||||
@@ -256,7 +256,7 @@ PUBLIC void mthread_init(void)
|
||||
/*===========================================================================*
|
||||
* mthread_join *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_join(join, value)
|
||||
int mthread_join(join, value)
|
||||
mthread_thread_t join;
|
||||
void **value;
|
||||
{
|
||||
@@ -314,7 +314,7 @@ void **value;
|
||||
/*===========================================================================*
|
||||
* mthread_once *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_once(once, proc)
|
||||
int mthread_once(once, proc)
|
||||
mthread_once_t *once;
|
||||
void (*proc)(void);
|
||||
{
|
||||
@@ -334,7 +334,7 @@ void (*proc)(void);
|
||||
/*===========================================================================*
|
||||
* mthread_self *
|
||||
*===========================================================================*/
|
||||
PUBLIC mthread_thread_t mthread_self(void)
|
||||
mthread_thread_t mthread_self(void)
|
||||
{
|
||||
/* Return the thread id of the thread calling this function. */
|
||||
|
||||
@@ -347,7 +347,7 @@ PUBLIC mthread_thread_t mthread_self(void)
|
||||
/*===========================================================================*
|
||||
* mthread_thread_init *
|
||||
*===========================================================================*/
|
||||
PRIVATE void mthread_thread_init(thread, tattr, proc, arg)
|
||||
static void mthread_thread_init(thread, tattr, proc, arg)
|
||||
mthread_thread_t thread;
|
||||
mthread_attr_t *tattr;
|
||||
void *(*proc)(void *);
|
||||
@@ -447,7 +447,7 @@ void *arg;
|
||||
/*===========================================================================*
|
||||
* mthread_thread_reset *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_thread_reset(thread)
|
||||
void mthread_thread_reset(thread)
|
||||
mthread_thread_t thread;
|
||||
{
|
||||
/* Reset the thread to its default values. Free the allocated stack space. */
|
||||
@@ -480,7 +480,7 @@ mthread_thread_t thread;
|
||||
/*===========================================================================*
|
||||
* mthread_thread_stop *
|
||||
*===========================================================================*/
|
||||
PRIVATE void mthread_thread_stop(thread)
|
||||
static void mthread_thread_stop(thread)
|
||||
mthread_thread_t thread;
|
||||
{
|
||||
/* Stop thread from running. Deallocate resources. */
|
||||
@@ -513,7 +513,7 @@ mthread_thread_t thread;
|
||||
/*===========================================================================*
|
||||
* mthread_trampoline *
|
||||
*===========================================================================*/
|
||||
PRIVATE void mthread_trampoline(void)
|
||||
static void mthread_trampoline(void)
|
||||
{
|
||||
/* Execute the /current_thread's/ procedure. Store its result. */
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
|
||||
PRIVATE struct __mthread_attr *va_front, *va_rear;
|
||||
FORWARD void mthread_attr_add(mthread_attr_t *a);
|
||||
FORWARD void mthread_attr_remove(mthread_attr_t *a);
|
||||
FORWARD int mthread_attr_valid(mthread_attr_t *a);
|
||||
static struct __mthread_attr *va_front, *va_rear;
|
||||
static void mthread_attr_add(mthread_attr_t *a);
|
||||
static void mthread_attr_remove(mthread_attr_t *a);
|
||||
static int mthread_attr_valid(mthread_attr_t *a);
|
||||
|
||||
/*===========================================================================*
|
||||
* mthread_init_valid_attributes *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_init_valid_attributes(void)
|
||||
void mthread_init_valid_attributes(void)
|
||||
{
|
||||
/* Initialize list of valid attributs */
|
||||
va_front = va_rear = NULL;
|
||||
@@ -20,7 +20,7 @@ PUBLIC void mthread_init_valid_attributes(void)
|
||||
/*===========================================================================*
|
||||
* mthread_attr_add *
|
||||
*===========================================================================*/
|
||||
PRIVATE void mthread_attr_add(a)
|
||||
static void mthread_attr_add(a)
|
||||
mthread_attr_t *a;
|
||||
{
|
||||
/* Add attribute to list of valid, initialized attributes */
|
||||
@@ -41,7 +41,7 @@ mthread_attr_t *a;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_destroy *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_destroy(attr)
|
||||
int mthread_attr_destroy(attr)
|
||||
mthread_attr_t *attr;
|
||||
{
|
||||
/* Invalidate attribute and deallocate resources. */
|
||||
@@ -66,7 +66,7 @@ mthread_attr_t *attr;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_init(attr)
|
||||
int mthread_attr_init(attr)
|
||||
mthread_attr_t *attr; /* Attribute */
|
||||
{
|
||||
/* Initialize the attribute to a known state. */
|
||||
@@ -95,7 +95,7 @@ mthread_attr_t *attr; /* Attribute */
|
||||
/*===========================================================================*
|
||||
* mthread_attr_getdetachstate *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_getdetachstate(attr, detachstate)
|
||||
int mthread_attr_getdetachstate(attr, detachstate)
|
||||
mthread_attr_t *attr;
|
||||
int *detachstate;
|
||||
{
|
||||
@@ -120,7 +120,7 @@ int *detachstate;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_setdetachstate *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_setdetachstate(attr, detachstate)
|
||||
int mthread_attr_setdetachstate(attr, detachstate)
|
||||
mthread_attr_t *attr;
|
||||
int detachstate;
|
||||
{
|
||||
@@ -148,7 +148,7 @@ int detachstate;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_getstack *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_getstack(attr, stackaddr, stacksize)
|
||||
int mthread_attr_getstack(attr, stackaddr, stacksize)
|
||||
mthread_attr_t *attr;
|
||||
void **stackaddr;
|
||||
size_t *stacksize;
|
||||
@@ -175,7 +175,7 @@ size_t *stacksize;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_getstacksize *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_getstacksize(attr, stacksize)
|
||||
int mthread_attr_getstacksize(attr, stacksize)
|
||||
mthread_attr_t *attr;
|
||||
size_t *stacksize;
|
||||
{
|
||||
@@ -200,7 +200,7 @@ size_t *stacksize;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_setstack *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_setstack(attr, stackaddr, stacksize)
|
||||
int mthread_attr_setstack(attr, stackaddr, stacksize)
|
||||
mthread_attr_t *attr;
|
||||
void *stackaddr;
|
||||
size_t stacksize;
|
||||
@@ -232,7 +232,7 @@ size_t stacksize;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_setstacksize *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_attr_setstacksize(attr, stacksize)
|
||||
int mthread_attr_setstacksize(attr, stacksize)
|
||||
mthread_attr_t *attr;
|
||||
size_t stacksize;
|
||||
{
|
||||
@@ -257,7 +257,7 @@ size_t stacksize;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_remove *
|
||||
*===========================================================================*/
|
||||
PRIVATE void mthread_attr_remove(a)
|
||||
static void mthread_attr_remove(a)
|
||||
mthread_attr_t *a;
|
||||
{
|
||||
/* Remove attribute from list of valid, initialized attributes */
|
||||
@@ -277,7 +277,7 @@ mthread_attr_t *a;
|
||||
/*===========================================================================*
|
||||
* mthread_attr_valid *
|
||||
*===========================================================================*/
|
||||
PRIVATE int mthread_attr_valid(a)
|
||||
static int mthread_attr_valid(a)
|
||||
mthread_attr_t *a;
|
||||
{
|
||||
/* Check to see if attribute is on the list of valid attributes */
|
||||
@@ -302,7 +302,7 @@ mthread_attr_t *a;
|
||||
* mthread_attr_verify *
|
||||
*===========================================================================*/
|
||||
#ifdef MDEBUG
|
||||
PUBLIC int mthread_attr_verify(void)
|
||||
int mthread_attr_verify(void)
|
||||
{
|
||||
/* Return true when no attributes are in use */
|
||||
struct __mthread_attr *loopitem;
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include "proto.h"
|
||||
|
||||
#ifdef MTHREAD_STRICT
|
||||
PRIVATE struct __mthread_cond *vc_front, *vc_rear;
|
||||
FORWARD void mthread_cond_add(mthread_cond_t *c);
|
||||
FORWARD void mthread_cond_remove(mthread_cond_t *c);
|
||||
FORWARD int mthread_cond_valid(mthread_cond_t *c);
|
||||
static struct __mthread_cond *vc_front, *vc_rear;
|
||||
static void mthread_cond_add(mthread_cond_t *c);
|
||||
static void mthread_cond_remove(mthread_cond_t *c);
|
||||
static int mthread_cond_valid(mthread_cond_t *c);
|
||||
#else
|
||||
# define mthread_cond_add(c) ((*c)->mc_magic = MTHREAD_INIT_MAGIC)
|
||||
# define mthread_cond_remove(c) ((*c)->mc_magic = MTHREAD_NOT_INUSE)
|
||||
@@ -17,7 +17,7 @@ FORWARD int mthread_cond_valid(mthread_cond_t *c);
|
||||
/*===========================================================================*
|
||||
* mthread_init_valid_conditions *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_init_valid_conditions(void)
|
||||
void mthread_init_valid_conditions(void)
|
||||
{
|
||||
#ifdef MTHREAD_STRICT
|
||||
/* Initialize condition variable list */
|
||||
@@ -30,7 +30,7 @@ PUBLIC void mthread_init_valid_conditions(void)
|
||||
* mthread_cond_add *
|
||||
*===========================================================================*/
|
||||
#ifdef MTHREAD_STRICT
|
||||
PRIVATE void mthread_cond_add(c)
|
||||
static void mthread_cond_add(c)
|
||||
mthread_cond_t *c;
|
||||
{
|
||||
/* Add condition to list of valid, initialized conditions */
|
||||
@@ -51,7 +51,7 @@ mthread_cond_t *c;
|
||||
/*===========================================================================*
|
||||
* mthread_cond_broadcast *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_cond_broadcast(cond)
|
||||
int mthread_cond_broadcast(cond)
|
||||
mthread_cond_t *cond;
|
||||
{
|
||||
/* Signal all threads waiting for condition 'cond'. */
|
||||
@@ -82,7 +82,7 @@ mthread_cond_t *cond;
|
||||
/*===========================================================================*
|
||||
* mthread_cond_destroy *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_cond_destroy(cond)
|
||||
int mthread_cond_destroy(cond)
|
||||
mthread_cond_t *cond;
|
||||
{
|
||||
/* Destroy a condition variable. Make sure it's not in use */
|
||||
@@ -119,7 +119,7 @@ mthread_cond_t *cond;
|
||||
/*===========================================================================*
|
||||
* mthread_cond_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_cond_init(cond, cattr)
|
||||
int mthread_cond_init(cond, cattr)
|
||||
mthread_cond_t *cond;
|
||||
mthread_condattr_t *cattr;
|
||||
{
|
||||
@@ -153,7 +153,7 @@ mthread_condattr_t *cattr;
|
||||
* mthread_cond_remove *
|
||||
*===========================================================================*/
|
||||
#ifdef MTHREAD_STRICT
|
||||
PRIVATE void mthread_cond_remove(c)
|
||||
static void mthread_cond_remove(c)
|
||||
mthread_cond_t *c;
|
||||
{
|
||||
/* Remove condition from list of valid, initialized conditions */
|
||||
@@ -174,7 +174,7 @@ mthread_cond_t *c;
|
||||
/*===========================================================================*
|
||||
* mthread_cond_signal *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_cond_signal(cond)
|
||||
int mthread_cond_signal(cond)
|
||||
mthread_cond_t *cond;
|
||||
{
|
||||
/* Signal a thread that condition 'cond' was met. Just a single thread. */
|
||||
@@ -208,7 +208,7 @@ mthread_cond_t *cond;
|
||||
* mthread_cond_valid *
|
||||
*===========================================================================*/
|
||||
#ifdef MTHREAD_STRICT
|
||||
PRIVATE int mthread_cond_valid(c)
|
||||
static int mthread_cond_valid(c)
|
||||
mthread_cond_t *c;
|
||||
{
|
||||
/* Check to see if cond is on the list of valid conditions */
|
||||
@@ -233,7 +233,7 @@ mthread_cond_t *c;
|
||||
* mthread_cond_verify *
|
||||
*===========================================================================*/
|
||||
#ifdef MDEBUG
|
||||
PUBLIC int mthread_cond_verify(void)
|
||||
int mthread_cond_verify(void)
|
||||
{
|
||||
/* Return true in case no condition variables are in use. */
|
||||
|
||||
@@ -247,7 +247,7 @@ PUBLIC int mthread_cond_verify(void)
|
||||
/*===========================================================================*
|
||||
* mthread_cond_wait *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_cond_wait(cond, mutex)
|
||||
int mthread_cond_wait(cond, mutex)
|
||||
mthread_cond_t *cond;
|
||||
mthread_mutex_t *mutex;
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*===========================================================================*
|
||||
* mthread_event_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_event_init(event)
|
||||
int mthread_event_init(event)
|
||||
mthread_event_t *event; /* The event to be initialized */
|
||||
{
|
||||
/* Initialize an event object.
|
||||
@@ -29,7 +29,7 @@ mthread_event_t *event; /* The event to be initialized */
|
||||
/*===========================================================================*
|
||||
* mthread_event_destroy *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_event_destroy(event)
|
||||
int mthread_event_destroy(event)
|
||||
mthread_event_t *event; /* The event to be destroyed */
|
||||
{
|
||||
/* Destroy an event object.
|
||||
@@ -49,7 +49,7 @@ mthread_event_t *event; /* The event to be destroyed */
|
||||
/*===========================================================================*
|
||||
* mthread_event_wait *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_event_wait(event)
|
||||
int mthread_event_wait(event)
|
||||
mthread_event_t *event; /* The event to be waited on */
|
||||
{
|
||||
/* Wait for an event, blocking the current thread in the process.
|
||||
@@ -75,7 +75,7 @@ mthread_event_t *event; /* The event to be waited on */
|
||||
/*===========================================================================*
|
||||
* mthread_event_fire *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_event_fire(event)
|
||||
int mthread_event_fire(event)
|
||||
mthread_event_t *event; /* The event to be fired */
|
||||
{
|
||||
/* Fire an event, waking up any thread blocked on it.
|
||||
@@ -102,7 +102,7 @@ mthread_event_t *event; /* The event to be fired */
|
||||
/*===========================================================================*
|
||||
* mthread_event_fire_all *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_event_fire_all(event)
|
||||
int mthread_event_fire_all(event)
|
||||
mthread_event_t *event; /* The event to be fired */
|
||||
{
|
||||
/* Fire an event, waking up any thread blocked on it.
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "global.h"
|
||||
#include "proto.h"
|
||||
|
||||
PRIVATE int keys_used = 0;
|
||||
PRIVATE struct {
|
||||
static int keys_used = 0;
|
||||
static struct {
|
||||
int used;
|
||||
int nvalues;
|
||||
void *mvalue;
|
||||
@@ -15,7 +15,7 @@ PRIVATE struct {
|
||||
/*===========================================================================*
|
||||
* mthread_init_keys *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_init_keys(void)
|
||||
void mthread_init_keys(void)
|
||||
{
|
||||
/* Initialize the table of key entries.
|
||||
*/
|
||||
@@ -28,7 +28,7 @@ PUBLIC void mthread_init_keys(void)
|
||||
/*===========================================================================*
|
||||
* mthread_key_create *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_key_create(mthread_key_t *key, void (*destructor)(void *))
|
||||
int mthread_key_create(mthread_key_t *key, void (*destructor)(void *))
|
||||
{
|
||||
/* Allocate a key.
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ PUBLIC int mthread_key_create(mthread_key_t *key, void (*destructor)(void *))
|
||||
/*===========================================================================*
|
||||
* mthread_key_delete *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_key_delete(mthread_key_t key)
|
||||
int mthread_key_delete(mthread_key_t key)
|
||||
{
|
||||
/* Free up a key, as well as any associated storage space.
|
||||
*/
|
||||
@@ -80,7 +80,7 @@ PUBLIC int mthread_key_delete(mthread_key_t key)
|
||||
/*===========================================================================*
|
||||
* mthread_getspecific *
|
||||
*===========================================================================*/
|
||||
PUBLIC void *mthread_getspecific(mthread_key_t key)
|
||||
void *mthread_getspecific(mthread_key_t key)
|
||||
{
|
||||
/* Get this thread's local value for the given key. The default is NULL.
|
||||
*/
|
||||
@@ -102,7 +102,7 @@ PUBLIC void *mthread_getspecific(mthread_key_t key)
|
||||
/*===========================================================================*
|
||||
* mthread_setspecific *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_setspecific(mthread_key_t key, void *value)
|
||||
int mthread_setspecific(mthread_key_t key, void *value)
|
||||
{
|
||||
/* Set this thread's value for the given key. Allocate more resources as
|
||||
* necessary.
|
||||
@@ -143,7 +143,7 @@ PUBLIC int mthread_setspecific(mthread_key_t key, void *value)
|
||||
/*===========================================================================*
|
||||
* mthread_cleanup_values *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_cleanup_values(void)
|
||||
void mthread_cleanup_values(void)
|
||||
{
|
||||
/* Clean up all the values associated with an exiting thread, calling keys'
|
||||
* destruction procedures as appropriate.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* mthread_debug_f *
|
||||
*===========================================================================*/
|
||||
#ifdef MDEBUG
|
||||
PUBLIC void mthread_debug_f(const char *file, int line, const char *msg)
|
||||
void mthread_debug_f(const char *file, int line, const char *msg)
|
||||
{
|
||||
/* Print debug message */
|
||||
printf("MTH (%s:%d): %s\n", file, line, msg);
|
||||
@@ -18,7 +18,7 @@ PUBLIC void mthread_debug_f(const char *file, int line, const char *msg)
|
||||
* mthread_panic_f *
|
||||
*===========================================================================*/
|
||||
#ifdef MDEBUG
|
||||
PUBLIC void mthread_panic_f(const char *file, int line, const char *msg)
|
||||
void mthread_panic_f(const char *file, int line, const char *msg)
|
||||
{
|
||||
/* Print panic message to stdout and exit */
|
||||
volatile int *sf;
|
||||
@@ -33,7 +33,7 @@ PUBLIC void mthread_panic_f(const char *file, int line, const char *msg)
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
PUBLIC void mthread_panic_s(void)
|
||||
void mthread_panic_s(void)
|
||||
{
|
||||
/* Silent panic */
|
||||
volatile int *sf;
|
||||
@@ -49,7 +49,7 @@ PUBLIC void mthread_panic_s(void)
|
||||
* mthread_verify_f *
|
||||
*===========================================================================*/
|
||||
#ifdef MDEBUG
|
||||
PUBLIC void mthread_verify_f(char *file, int line)
|
||||
void mthread_verify_f(char *file, int line)
|
||||
{
|
||||
/* Verify library state. It is assumed this function is never called from
|
||||
* a spawned thread, but from the 'main' thread. The library should be
|
||||
@@ -84,7 +84,7 @@ PUBLIC void mthread_verify_f(char *file, int line)
|
||||
/*===========================================================================*
|
||||
* mthread_stats *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_stats(void)
|
||||
void mthread_stats(void)
|
||||
{
|
||||
mthread_thread_t t;
|
||||
mthread_tcb_t *tcb;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include "proto.h"
|
||||
|
||||
#ifdef MTHREAD_STRICT
|
||||
PRIVATE struct __mthread_mutex *vm_front, *vm_rear;
|
||||
FORWARD void mthread_mutex_add(mthread_mutex_t *m);
|
||||
FORWARD void mthread_mutex_remove(mthread_mutex_t *m);
|
||||
static struct __mthread_mutex *vm_front, *vm_rear;
|
||||
static void mthread_mutex_add(mthread_mutex_t *m);
|
||||
static void mthread_mutex_remove(mthread_mutex_t *m);
|
||||
#else
|
||||
# define mthread_mutex_add(m) ((*m)->mm_magic = MTHREAD_INIT_MAGIC)
|
||||
# define mthread_mutex_remove(m) ((*m)->mm_magic = MTHREAD_NOT_INUSE)
|
||||
@@ -14,7 +14,7 @@ FORWARD void mthread_mutex_remove(mthread_mutex_t *m);
|
||||
/*===========================================================================*
|
||||
* mthread_init_valid_mutexes *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_init_valid_mutexes(void)
|
||||
void mthread_init_valid_mutexes(void)
|
||||
{
|
||||
#ifdef MTHREAD_STRICT
|
||||
/* Initialize list of valid mutexes */
|
||||
@@ -27,7 +27,7 @@ PUBLIC void mthread_init_valid_mutexes(void)
|
||||
* mthread_mutex_add *
|
||||
*===========================================================================*/
|
||||
#ifdef MTHREAD_STRICT
|
||||
PRIVATE void mthread_mutex_add(m)
|
||||
static void mthread_mutex_add(m)
|
||||
mthread_mutex_t *m;
|
||||
{
|
||||
/* Add mutex to list of valid, initialized mutexes */
|
||||
@@ -48,7 +48,7 @@ mthread_mutex_t *m;
|
||||
/*===========================================================================*
|
||||
* mthread_mutex_destroy *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_mutex_destroy(mutex)
|
||||
int mthread_mutex_destroy(mutex)
|
||||
mthread_mutex_t *mutex;
|
||||
{
|
||||
/* Invalidate mutex and deallocate resources. */
|
||||
@@ -87,7 +87,7 @@ mthread_mutex_t *mutex;
|
||||
/*===========================================================================*
|
||||
* mthread_mutex_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_mutex_init(mutex, mattr)
|
||||
int mthread_mutex_init(mutex, mattr)
|
||||
mthread_mutex_t *mutex; /* Mutex that is to be initialized */
|
||||
mthread_mutexattr_t *mattr; /* Mutex attribute */
|
||||
{
|
||||
@@ -119,7 +119,7 @@ mthread_mutexattr_t *mattr; /* Mutex attribute */
|
||||
/*===========================================================================*
|
||||
* mthread_mutex_lock *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_mutex_lock(mutex)
|
||||
int mthread_mutex_lock(mutex)
|
||||
mthread_mutex_t *mutex; /* Mutex that is to be locked */
|
||||
{
|
||||
/* Try to lock this mutex. If already locked, append the current thread to
|
||||
@@ -153,7 +153,7 @@ mthread_mutex_t *mutex; /* Mutex that is to be locked */
|
||||
* mthread_mutex_remove *
|
||||
*===========================================================================*/
|
||||
#ifdef MTHREAD_STRICT
|
||||
PRIVATE void mthread_mutex_remove(m)
|
||||
static void mthread_mutex_remove(m)
|
||||
mthread_mutex_t *m;
|
||||
{
|
||||
/* Remove mutex from list of valid, initialized mutexes */
|
||||
@@ -173,7 +173,7 @@ mthread_mutex_t *m;
|
||||
/*===========================================================================*
|
||||
* mthread_mutex_trylock *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_mutex_trylock(mutex)
|
||||
int mthread_mutex_trylock(mutex)
|
||||
mthread_mutex_t *mutex; /* Mutex that is to be locked */
|
||||
{
|
||||
/* Try to lock this mutex and return OK. If already locked, return error. */
|
||||
@@ -202,7 +202,7 @@ mthread_mutex_t *mutex; /* Mutex that is to be locked */
|
||||
/*===========================================================================*
|
||||
* mthread_mutex_unlock *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_mutex_unlock(mutex)
|
||||
int mthread_mutex_unlock(mutex)
|
||||
mthread_mutex_t *mutex; /* Mutex that is to be unlocked */
|
||||
{
|
||||
/* Unlock a previously locked mutex. If there is a pending lock for this mutex
|
||||
@@ -231,7 +231,7 @@ mthread_mutex_t *mutex; /* Mutex that is to be unlocked */
|
||||
* mthread_mutex_valid *
|
||||
*===========================================================================*/
|
||||
#ifdef MTHREAD_STRICT
|
||||
PUBLIC int mthread_mutex_valid(m)
|
||||
int mthread_mutex_valid(m)
|
||||
mthread_mutex_t *m;
|
||||
{
|
||||
/* Check to see if mutex is on the list of valid mutexes */
|
||||
@@ -256,7 +256,7 @@ mthread_mutex_t *m;
|
||||
* mthread_mutex_verify *
|
||||
*===========================================================================*/
|
||||
#ifdef MDEBUG
|
||||
PUBLIC int mthread_mutex_verify(void)
|
||||
int mthread_mutex_verify(void)
|
||||
{
|
||||
/* Return true when no mutexes are in use */
|
||||
int r = 1;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
/*===========================================================================*
|
||||
* mthread_queue_add *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_queue_add(queue, thread)
|
||||
void mthread_queue_add(queue, thread)
|
||||
mthread_queue_t *queue; /* Queue we want thread to append to */
|
||||
mthread_thread_t thread;
|
||||
{
|
||||
@@ -32,7 +32,7 @@ mthread_thread_t thread;
|
||||
/*===========================================================================*
|
||||
* mthread_queue_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_queue_init(queue)
|
||||
void mthread_queue_init(queue)
|
||||
mthread_queue_t *queue; /* Queue that has to be initialized */
|
||||
{
|
||||
/* Initialize queue to a known state */
|
||||
@@ -44,7 +44,7 @@ mthread_queue_t *queue; /* Queue that has to be initialized */
|
||||
/*===========================================================================*
|
||||
* mthread_queue_isempty *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_queue_isempty(queue)
|
||||
int mthread_queue_isempty(queue)
|
||||
mthread_queue_t *queue;
|
||||
{
|
||||
return(queue->mq_head == NULL);
|
||||
@@ -55,7 +55,7 @@ mthread_queue_t *queue;
|
||||
* mthread_dump_queue *
|
||||
*===========================================================================*/
|
||||
#ifdef MDEBUG
|
||||
PUBLIC void mthread_dump_queue(queue)
|
||||
void mthread_dump_queue(queue)
|
||||
mthread_queue_t *queue;
|
||||
{
|
||||
int threshold, count = 0;
|
||||
@@ -90,7 +90,7 @@ mthread_queue_t *queue;
|
||||
/*===========================================================================*
|
||||
* mthread_queue_remove *
|
||||
*===========================================================================*/
|
||||
PUBLIC mthread_thread_t mthread_queue_remove(queue)
|
||||
mthread_thread_t mthread_queue_remove(queue)
|
||||
mthread_queue_t *queue; /* Queue we want a thread from */
|
||||
{
|
||||
/* Get the first thread in this queue, if there is one. */
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*===========================================================================*
|
||||
* mthread_rwlock_init *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_rwlock_init(rwlock)
|
||||
int mthread_rwlock_init(rwlock)
|
||||
mthread_rwlock_t *rwlock; /* The rwlock to be initialized */
|
||||
{
|
||||
/* Initialize a readers/writer lock. */
|
||||
@@ -30,7 +30,7 @@ mthread_rwlock_t *rwlock; /* The rwlock to be initialized */
|
||||
/*===========================================================================*
|
||||
* mthread_rwlock_destroy *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_rwlock_destroy(rwlock)
|
||||
int mthread_rwlock_destroy(rwlock)
|
||||
mthread_rwlock_t *rwlock; /* The rwlock to be destroyed */
|
||||
{
|
||||
/* Destroy a readers/writer lock. */
|
||||
@@ -52,7 +52,7 @@ mthread_rwlock_t *rwlock; /* The rwlock to be destroyed */
|
||||
/*===========================================================================*
|
||||
* mthread_rwlock_rdlock *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_rwlock_rdlock(rwlock)
|
||||
int mthread_rwlock_rdlock(rwlock)
|
||||
mthread_rwlock_t *rwlock; /* The rwlock to be read locked */
|
||||
{
|
||||
/* Acquire a reader lock. */
|
||||
@@ -77,7 +77,7 @@ mthread_rwlock_t *rwlock; /* The rwlock to be read locked */
|
||||
/*===========================================================================*
|
||||
* mthread_rwlock_wrlock *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_rwlock_wrlock(rwlock)
|
||||
int mthread_rwlock_wrlock(rwlock)
|
||||
mthread_rwlock_t *rwlock; /* The rwlock to be write locked */
|
||||
{
|
||||
/* Acquire a writer lock. */
|
||||
@@ -104,7 +104,7 @@ mthread_rwlock_t *rwlock; /* The rwlock to be write locked */
|
||||
/*===========================================================================*
|
||||
* mthread_rwlock_unlock *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_rwlock_unlock(rwlock)
|
||||
int mthread_rwlock_unlock(rwlock)
|
||||
mthread_rwlock_t *rwlock; /* The rwlock to be unlocked */
|
||||
{
|
||||
/* Release a lock. */
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#define OLD_CTX &(threads[old_thread]->m_context)
|
||||
#define CURRENT_CTX &(threads[current_thread]->m_context)
|
||||
#define CURRENT_STATE threads[current_thread]->m_state
|
||||
PRIVATE int yield_all;
|
||||
static int yield_all;
|
||||
|
||||
/*===========================================================================*
|
||||
* mthread_getcontext *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_getcontext(ctx)
|
||||
int mthread_getcontext(ctx)
|
||||
ucontext_t *ctx;
|
||||
{
|
||||
/* Retrieve this process' current state.*/
|
||||
@@ -28,7 +28,7 @@ ucontext_t *ctx;
|
||||
/*===========================================================================*
|
||||
* mthread_schedule *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_schedule(void)
|
||||
void mthread_schedule(void)
|
||||
{
|
||||
/* Pick a new thread to run and run it. In practice, this involves taking the
|
||||
* first thread off the (FIFO) run queue and resuming that thread.
|
||||
@@ -80,7 +80,7 @@ PUBLIC void mthread_schedule(void)
|
||||
/*===========================================================================*
|
||||
* mthread_init_scheduler *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_init_scheduler(void)
|
||||
void mthread_init_scheduler(void)
|
||||
{
|
||||
/* Initialize the scheduler */
|
||||
mthread_queue_init(&run_queue);
|
||||
@@ -92,7 +92,7 @@ PUBLIC void mthread_init_scheduler(void)
|
||||
/*===========================================================================*
|
||||
* mthread_suspend *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_suspend(state)
|
||||
void mthread_suspend(state)
|
||||
mthread_state_t state;
|
||||
{
|
||||
/* Stop the current thread from running. There can be multiple reasons for
|
||||
@@ -131,7 +131,7 @@ mthread_state_t state;
|
||||
/*===========================================================================*
|
||||
* mthread_unsuspend *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_unsuspend(thread)
|
||||
void mthread_unsuspend(thread)
|
||||
mthread_thread_t thread; /* Thread to make runnable */
|
||||
{
|
||||
/* Mark the state of a thread runnable and add it to the run queue */
|
||||
@@ -148,7 +148,7 @@ mthread_thread_t thread; /* Thread to make runnable */
|
||||
/*===========================================================================*
|
||||
* mthread_yield *
|
||||
*===========================================================================*/
|
||||
PUBLIC int mthread_yield(void)
|
||||
int mthread_yield(void)
|
||||
{
|
||||
/* Defer further execution of the current thread and let another thread run. */
|
||||
mthread_tcb_t *tcb;
|
||||
@@ -186,7 +186,7 @@ PUBLIC int mthread_yield(void)
|
||||
/*===========================================================================*
|
||||
* mthread_yield_all *
|
||||
*===========================================================================*/
|
||||
PUBLIC void mthread_yield_all(void)
|
||||
void mthread_yield_all(void)
|
||||
{
|
||||
/* Yield until there are no more runnable threads left. Two threads calling
|
||||
* this function will lead to a deadlock.
|
||||
|
||||
Reference in New Issue
Block a user