mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-12 06:32:34 -05:00
current_tick simulation added
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1005 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
3f0bf03677
commit
973b1a8274
1 changed files with 9 additions and 5 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
|
||||||
|
long current_tick = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We emulate the target threads by using pthreads. We have a mutex that only
|
* We emulate the target threads by using pthreads. We have a mutex that only
|
||||||
|
|
@ -38,6 +39,7 @@ void init_threads(void)
|
||||||
/* get mutex to only allow one thread running at a time */
|
/* get mutex to only allow one thread running at a time */
|
||||||
pthread_mutex_lock(&mp);
|
pthread_mutex_lock(&mp);
|
||||||
|
|
||||||
|
current_tick = time(NULL); /* give it a boost from start! */
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
int pthread_create(pthread_t *new_thread_ID,
|
int pthread_create(pthread_t *new_thread_ID,
|
||||||
|
|
@ -45,16 +47,17 @@ void init_threads(void)
|
||||||
void * (*start_func)(void *), void *arg);
|
void * (*start_func)(void *), void *arg);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void (yield)(void)
|
void yield(void)
|
||||||
{
|
{
|
||||||
|
current_tick+=3;
|
||||||
pthread_mutex_unlock(&mp); /* return */
|
pthread_mutex_unlock(&mp); /* return */
|
||||||
pthread_mutex_lock(&mp); /* get it again */
|
pthread_mutex_lock(&mp); /* get it again */
|
||||||
}
|
}
|
||||||
|
|
||||||
void newfunc(void (*func)(void))
|
void newfunc(void (*func)(void))
|
||||||
{
|
{
|
||||||
yield();
|
yield();
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -72,9 +75,9 @@ int create_thread(void* fp, void* sp, int stk_size)
|
||||||
(void *(*)(void *)) newfunc, /* function to start */
|
(void *(*)(void *)) newfunc, /* function to start */
|
||||||
fp /* start argument */);
|
fp /* start argument */);
|
||||||
if(0 != error)
|
if(0 != error)
|
||||||
fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
|
fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Thread %ld is running\n", (long)tid);
|
fprintf(stderr, "Thread %ld is running\n", (long)tid);
|
||||||
|
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
|
|
@ -84,6 +87,7 @@ int create_thread(void* fp, void* sp, int stk_size)
|
||||||
/* ticks is HZ per second */
|
/* ticks is HZ per second */
|
||||||
void x11_sleep(int ticks)
|
void x11_sleep(int ticks)
|
||||||
{
|
{
|
||||||
|
current_tick+=5;
|
||||||
pthread_mutex_unlock(&mp); /* return */
|
pthread_mutex_unlock(&mp); /* return */
|
||||||
/* portable subsecond "sleep" */
|
/* portable subsecond "sleep" */
|
||||||
poll((void *)0, 0, ticks * 1000/HZ);
|
poll((void *)0, 0, ticks * 1000/HZ);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue