20 #include <lwip/arch/sys_arch.h> 25 #include <pedigree/kernel/Log.h> 26 #include <pedigree/kernel/process/Mutex.h> 27 #include <pedigree/kernel/process/Semaphore.h> 28 #include <pedigree/kernel/process/Thread.h> 29 #include <pedigree/kernel/processor/Processor.h> 30 #include <pedigree/kernel/utilities/RingBuffer.h> 31 #include <pedigree/kernel/utilities/pocketknife.h> 61 clock_gettime(CLOCK_REALTIME, &spec);
63 return (spec.tv_sec * 1000) + (spec.tv_nsec / 1000000);
65 return Time::getTimeNanoseconds() / Time::Multiplier::Millisecond;
76 static int thread_shim(
void *arg)
79 meta->thread(meta->arg);
84 const char *name,
lwip_thread_fn thread,
void *arg,
int stacksize,
int prio)
88 meta->thread = thread;
90 StringCopy(meta->name, name);
98 if (sem_init(sem, 0, count) != 0)
108 *sem =
reinterpret_cast<void *
>(newsem);
142 #ifndef UTILITY_LINUX 162 if (sem_wait(sem) == 0)
172 struct timespec now, spec;
173 clock_gettime(CLOCK_REALTIME, &now);
178 u32_t s = timeout / 1000;
179 u32_t ms = timeout % 1000;
181 spec.tv_sec = now.tv_sec + s;
182 spec.tv_nsec = now.tv_nsec + (ms * 1000000);
184 r = sem_timedwait(sem, &spec);
191 clock_gettime(CLOCK_REALTIME, &spec);
195 uint64_t orig_ms = (now.tv_sec * 1000U) + (now.tv_nsec * 1000000U);
196 uint64_t waited_ms = (spec.tv_sec * 1000U) + (spec.tv_nsec * 1000000U);
199 return waited_ms - orig_ms;
207 Time::Timestamp begin = Time::getTimeNanoseconds();
210 if (!s->
acquire(1, timeout * 1000))
215 Time::Timestamp end = Time::getTimeNanoseconds();
216 return (end - begin) / Time::Multiplier::Millisecond;
234 (*mbox)->buffer.write(msg);
239 if (!(*mbox)->buffer.dataReady())
244 *msg = (*mbox)->buffer.read();
250 Time::Timestamp begin = Time::getTimeNanoseconds();
252 Time::Timestamp timeoutMs = 0;
255 timeoutMs = Time::Infinity;
259 timeoutMs = timeout * Time::Multiplier::Millisecond;
262 *msg = (*mbox)->buffer.read(timeoutMs);
268 Time::Timestamp end = Time::getTimeNanoseconds();
269 return (end - begin) / Time::Multiplier::Millisecond;
274 if (!(*mbox)->buffer.canWrite())
279 (*mbox)->buffer.write(msg);
286 return *mbox !=
nullptr ? 1 : 0;
323 return *mutex !=
nullptr ? 1 : 0;
331 sys_prot_t sys_arch_protect()
334 while (!g_Protection.acquire(
true))
345 void sys_arch_unprotect(sys_prot_t pval)
348 g_Protection.release();
void sys_sem_free(sys_sem_t *sem)
static bool getInterrupts()
bool acquire(size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0)
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
void sys_mutex_free(sys_mutex_t *mutex)
void sys_mbox_free(sys_mbox_t *mbox)
void sys_mbox_set_invalid(sys_mbox_t *mbox)
int sys_mbox_valid(sys_mbox_t *mbox)
void sys_mutex_unlock(sys_mutex_t *mutex)
EXPORTED_PUBLIC void runConcurrently(int(*func)(void *), void *param)
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
void(* lwip_thread_fn)(void *arg)
void sys_sem_signal(sys_sem_t *sem)
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
int sys_mutex_valid(sys_mutex_t *mutex)
void sys_mutex_lock(sys_mutex_t *mutex)
static void setInterrupts(bool bEnable)
void sys_sem_set_invalid(sys_sem_t *sem)
void sys_mutex_set_invalid(sys_mutex_t *mutex)
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
int sys_sem_valid(sys_sem_t *sem)
err_t sys_mutex_new(sys_mutex_t *mutex)