2002-06-12 15:39:39 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Felix Arends
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-07-19 20:43:21 +00:00
|
|
|
#define WINDOWS_LEAN_AND_MEAN
|
2002-06-12 15:39:39 +00:00
|
|
|
#include <windows.h>
|
2005-07-20 16:52:52 +00:00
|
|
|
#include <time.h>
|
2002-06-12 15:39:39 +00:00
|
|
|
#include "thread-win32.h"
|
2005-07-19 20:43:21 +00:00
|
|
|
#include "kernel.h"
|
2005-07-20 16:52:52 +00:00
|
|
|
#include "debug.h"
|
2002-06-12 15:39:39 +00:00
|
|
|
|
|
|
|
HANDLE lpThreads[256];
|
|
|
|
int nThreads = 0,
|
|
|
|
nPos = 0;
|
2002-06-15 10:58:14 +00:00
|
|
|
long current_tick = 0;
|
2005-07-19 20:43:21 +00:00
|
|
|
CRITICAL_SECTION CriticalSection;
|
2002-06-12 15:39:39 +00:00
|
|
|
|
|
|
|
|
2005-07-19 20:43:21 +00:00
|
|
|
void yield(void)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&CriticalSection);
|
2005-12-04 12:18:01 +00:00
|
|
|
Sleep(1);
|
2005-07-19 20:43:21 +00:00
|
|
|
EnterCriticalSection(&CriticalSection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sim_sleep(int ticks)
|
|
|
|
{
|
|
|
|
LeaveCriticalSection(&CriticalSection);
|
|
|
|
Sleep((1000/HZ) * ticks);
|
|
|
|
EnterCriticalSection(&CriticalSection);
|
|
|
|
}
|
|
|
|
|
2002-06-12 15:39:39 +00:00
|
|
|
DWORD WINAPI runthread (LPVOID lpParameter)
|
|
|
|
{
|
2005-07-19 20:43:21 +00:00
|
|
|
EnterCriticalSection(&CriticalSection);
|
2002-06-12 15:39:39 +00:00
|
|
|
((void(*)())lpParameter) ();
|
2005-07-19 20:43:21 +00:00
|
|
|
LeaveCriticalSection(&CriticalSection);
|
2002-06-12 15:39:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-12 10:05:13 +00:00
|
|
|
int create_thread(void (*fp)(void), void* sp, int stk_size)
|
2002-06-12 15:39:39 +00:00
|
|
|
{
|
|
|
|
DWORD dwThreadID;
|
|
|
|
|
2002-08-02 14:00:52 +00:00
|
|
|
(void)sp;
|
|
|
|
(void)stk_size;
|
|
|
|
|
2002-06-12 15:39:39 +00:00
|
|
|
if (nThreads == 256)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
lpThreads[nThreads++] = CreateThread (NULL,
|
|
|
|
0,
|
|
|
|
runthread,
|
|
|
|
fp,
|
|
|
|
0,
|
|
|
|
&dwThreadID);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_threads(void)
|
|
|
|
{
|
2005-07-19 20:43:21 +00:00
|
|
|
InitializeCriticalSection(&CriticalSection);
|
|
|
|
EnterCriticalSection(&CriticalSection);
|
2002-06-12 15:39:39 +00:00
|
|
|
}
|