first commit

This commit is contained in:
Jose Caban
2025-06-07 11:34:38 -04:00
commit 0eb2d7c07d
4708 changed files with 1500614 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
/* Basic platform-independent macro definitions for mutexes,
thread-specific data and parameters for malloc.
SGI threads (sprocs) version.
Copyright (C) 2004 Wolfram Gloger <wg@malloc.de>.
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that (i) the above copyright notices and this permission
notice appear in all copies of the software and related documentation,
and (ii) the name of Wolfram Gloger may not be used in any advertising
or publicity relating to the software.
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL WOLFRAM GLOGER BE LIABLE FOR ANY SPECIAL,
INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY
OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _SPROC_MALLOC_MACHINE_H
#define _SPROC_MALLOC_MACHINE_H
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/prctl.h>
#include <abi_mutex.h>
typedef abilock_t mutex_t;
#define MUTEX_INITIALIZER { 0 }
#define mutex_init(m) init_lock(m)
#define mutex_lock(m) (spin_lock(m), 0)
#define mutex_trylock(m) acquire_lock(m)
#define mutex_unlock(m) release_lock(m)
typedef int tsd_key_t;
int tsd_key_next;
#define tsd_key_create(key, destr) ((*key) = tsd_key_next++)
#define tsd_setspecific(key, data) (((void **)(&PRDA->usr_prda))[key] = data)
#define tsd_getspecific(key, vptr) (vptr = ((void **)(&PRDA->usr_prda))[key])
#define thread_atfork(prepare, parent, child) do {} while(0)
#include <sysdeps/generic/malloc-machine.h>
#endif /* !defined(_SPROC_MALLOC_MACHINE_H) */

View File

@@ -0,0 +1,85 @@
/*
* $Id:$
* sproc version
* by Wolfram Gloger 2001, 2004, 2006
*/
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/prctl.h>
#ifndef STACKSIZE
#define STACKSIZE 32768
#endif
struct thread_st {
char *sp; /* stack pointer, can be 0 */
void (*func)(struct thread_st* st); /* must be set by user */
int id;
int flags;
struct user_data u;
};
static void
thread_init(void)
{
printf("Using sproc() threads.\n");
}
static void
thread_wrapper(void *ptr, size_t stack_len)
{
struct thread_st *st = (struct thread_st*)ptr;
/*printf("begin %p\n", st->sp);*/
st->func(st);
/*printf("end %p\n", st->sp);*/
}
/* Create a thread. */
static int
thread_create(struct thread_st *st)
{
st->flags = 0;
if(!st->sp)
st->sp = malloc(STACKSIZE);
if(!st->sp) return -1;
st->id = sprocsp(thread_wrapper, PR_SALL, st, st->sp+STACKSIZE, STACKSIZE);
if(st->id < 0) {
return -1;
}
return 0;
}
/* Wait for one of several subthreads to finish. */
static void
wait_for_thread(struct thread_st st[], int n_thr,
int (*end_thr)(struct thread_st*))
{
int i;
int id;
int status = 0;
id = wait(&status);
if(status != 0) {
if(WIFSIGNALED(status))
printf("thread %id terminated by signal %d\n",
id, WTERMSIG(status));
else
printf("thread %id exited with status %d\n",
id, WEXITSTATUS(status));
}
for(i=0; i<n_thr; i++)
if(id == st[i].id) {
if(end_thr)
end_thr(&st[i]);
break;
}
}
/*
* Local variables:
* tab-width: 4
* End:
*/