More improvements to support lwip

This commit is contained in:
Ali Mashtizadeh 2015-02-03 14:06:17 -08:00
parent 348a7acc15
commit 251654f2c7
5 changed files with 54 additions and 0 deletions

View File

@ -17,6 +17,7 @@
#define EALREADY 0x1BAD000D #define EALREADY 0x1BAD000D
#define EINPROGRESS 0x1BAD000E #define EINPROGRESS 0x1BAD000E
#define ENFILE 0x1BAD000F #define ENFILE 0x1BAD000F
#define ETIMEDOUT 0x1BAD0010
#define EAFNOSUPPORT 0x1BAD0020 #define EAFNOSUPPORT 0x1BAD0020
#define ENOPROTOOPT 0x1BAD0021 #define ENOPROTOOPT 0x1BAD0021

View File

@ -2,6 +2,8 @@
#ifndef __PTHREAD_H__ #ifndef __PTHREAD_H__
#define __PTHREAD_H__ #define __PTHREAD_H__
#include <time.h>
#define PTHREAD_MUTEX_INITIALIZER NULL #define PTHREAD_MUTEX_INITIALIZER NULL
#define PTHREAD_COND_INITIALIZER NULL #define PTHREAD_COND_INITIALIZER NULL
@ -53,6 +55,8 @@ int pthread_mutex_unlock(pthread_mutex_t *mutex);
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr);
int pthread_cond_destroy(pthread_cond_t *cond); int pthread_cond_destroy(pthread_cond_t *cond);
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime);
int pthread_cond_signal(pthread_cond_t *cond); int pthread_cond_signal(pthread_cond_t *cond);
int pthread_cond_broadcast(pthread_cond_t *cond); int pthread_cond_broadcast(pthread_cond_t *cond);

View File

@ -2,6 +2,8 @@
#ifndef __TIME_H__ #ifndef __TIME_H__
#define __TIME_H__ #define __TIME_H__
#include <sys/timespec.h>
struct tm { struct tm {
int tm_sec; int tm_sec;
int tm_min; int tm_min;

View File

@ -373,6 +373,40 @@ pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
return 0; return 0;
} }
int
pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime)
{
struct pthread_cond *cnd;
uint64_t level;
if (*cond == NULL) {
int status = pthread_cond_init(cond, NULL);
if (status != 0)
return status;
}
cnd = *cond;
if (mutex)
pthread_mutex_unlock(mutex);
CoreMutex_Lock(&cnd->mtx);
level = cnd->enter;
cnd->enter++;
CoreMutex_Unlock(&cnd->mtx);
while (level >= cnd->exit) {
OSThreadSleep(0);
// XXX: check time
}
if (mutex)
pthread_mutex_lock(mutex);
return 0;
}
int int
pthread_cond_signal(pthread_cond_t *cond) pthread_cond_signal(pthread_cond_t *cond)

13
sys/include/timespec.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef __SYS_TIMESPEC_H__
#define __SYS_TIMESPEC_H__
#include <sys/types.h>
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#endif /* __SYS_TIMESPEC_H__ */