1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
23 #include "thread-win32.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__ */
31 int set_irq_level (int level
)
39 Sleep (1000 / HZ
* ticks
);
45 Sleep (1); /* prevent busy loop */
46 PostThreadMessage (GetWindowThreadProcessId (hGUIWnd
,NULL
), TM_YIELD
, 0, 0);
49 void queue_init(struct event_queue
*q
)
55 void queue_wait(struct event_queue
*q
, struct event
*ev
)
57 while(q
->read
== q
->write
)
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
))
74 if(q
->read
!= q
->write
)
76 *ev
= q
->events
[(q
->read
++) & QUEUE_LENGTH_MASK
];
84 void queue_post(struct event_queue
*q
, int id
, void *data
)
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)
107 /* TODO: Implement mutexes for win32 */
108 void mutex_init(struct mutex
*m
)
113 void mutex_lock(struct mutex
*m
)
118 void mutex_unlock(struct mutex
*m
)