#include "systhr.h"
#include "systems.h"
#ifdef XP_UNIX
#include <poll.h>
#endif
#define DEFAULT_STACKSIZE (
64*
1024)
static unsigned long _systhr_stacksize =
DEFAULT_STACKSIZE;
NSAPI_PUBLIC
void systhread_set_default_stacksize(
unsigned long size)
{
_systhr_stacksize = size;
}
SYS_THREAD systhread_start(
int prio,
int stksz, thrstartfunc fn,
void *arg) {
pthread_t thr =
0;
pthread_attr_t attr;
pthread_attr_init(&attr);
if(stksz) {
pthread_attr_setstacksize(&attr, stksz);
}
if(pthread_create(&thr, &attr, (posix_thrstartfunc)fn, arg) !=
0) {
}
return thr;
}
SYS_THREAD systhread_current(
void) {
return pthread_self();
}
void systhread_yield(
void) {
sched_yield();
}
void systhread_timerset(
int usec) {
}
SYS_THREAD systhread_attach(
void) {
return 0;
}
void systhread_detach(
SYS_THREAD thr) {
pthread_detach(thr);
}
void systhread_terminate(
SYS_THREAD thr) {
}
void systhread_sleep(
int msec) {
if(msec >
0) {
poll(
NULL,
0, msec);
}
else {
sched_yield();
}
}
NSAPI_PUBLIC int systhread_newkey() {
pthread_key_t key;
pthread_key_create(&key,
NULL);
return (
int)key;
}
NSAPI_PUBLIC void* systhread_getdata(
int key) {
return pthread_getspecific((
pthread_key_t)key);
}
NSAPI_PUBLIC void systhread_setdata(
int key,
void *data) {
pthread_setspecific((
pthread_key_t)key, data);
}
NSAPI_PUBLIC void systhread_init(
char *name)
{
}
NSAPI_PUBLIC void systhread_dummy(
void) {
}