Experimenting with USER
[kugel-rb.git] / uisimulator / win32 / kernel.c
blob44ac88ae7c9d725642ae66bcccc85373ce7991d3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Felix Arends
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include <windows.h>
21 #include "uisw32.h"
22 #include "kernel.h"
23 #include "thread-win32.h"
24 #include "thread.h"
26 /* (Daniel 2002-10-31) Mingw32 requires this errno variable to be present.
27 I'm not quite sure why and I don't know if this breaks the MSVC compile.
28 If it does, we should put this within #ifdef __MINGW32__ */
29 int errno;
31 int set_irq_level (int level)
33 static int _lv = 0;
34 return (_lv = level);
37 void sleep(int ticks)
39 Sleep (1000 / HZ * ticks);
43 void yield (void)
45 Sleep (1); /* prevent busy loop */
46 PostThreadMessage (GetWindowThreadProcessId (hGUIWnd,NULL), TM_YIELD, 0, 0);
49 void queue_init(struct event_queue *q)
51 q->read = 0;
52 q->write = 0;
55 void queue_wait(struct event_queue *q, struct event *ev)
57 while(q->read == q->write)
59 switch_thread();
62 *ev = q->events[(q->read++) & QUEUE_LENGTH_MASK];
65 void queue_wait_w_tmo(struct event_queue *q, struct event *ev, int ticks)
67 unsigned int timeout = current_tick + ticks;
69 while(q->read == q->write && TIME_BEFORE( current_tick, timeout ))
71 sleep(1);
74 if(q->read != q->write)
76 *ev = q->events[(q->read++) & QUEUE_LENGTH_MASK];
78 else
80 ev->id = SYS_TIMEOUT;
84 void queue_post(struct event_queue *q, int id, void *data)
86 int wr;
87 int oldlevel;
89 oldlevel = set_irq_level(15<<4);
90 wr = (q->write++) & QUEUE_LENGTH_MASK;
92 q->events[wr].id = id;
93 q->events[wr].data = data;
94 set_irq_level(oldlevel);
97 bool queue_empty(struct event_queue* q)
99 return ( q->read == q->write );
102 void switch_thread (void)
104 yield ();
107 /* TODO: Implement mutexes for win32 */
108 void mutex_init(struct mutex *m)
110 (void)m;
113 void mutex_lock(struct mutex *m)
115 (void)m;
118 void mutex_unlock(struct mutex *m)
120 (void)m;