Release 970202
[wine/multimedia.git] / win32 / thread.c
blob6c0559fe3972a2d1f03ca82740e9c2b171415f40
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis
5 */
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <string.h>
10 #include "windows.h"
11 #include "winbase.h"
12 #include "winerror.h"
13 #include "stddebug.h"
14 #include "debug.h"
15 #include "xmalloc.h"
17 /**********************************************************************
18 * Critical Sections are currently ignored
20 void InitializeCriticalSection(CRITICAL_SECTION *lpCrit)
22 memset(lpCrit,0,sizeof(CRITICAL_SECTION));
25 void EnterCriticalSection(CRITICAL_SECTION* lpCrit)
27 if (lpCrit->LockCount)
28 fprintf( stderr, "Error: re-entering critical section %08lx\n",
29 (DWORD)lpCrit );
30 lpCrit->LockCount++;
33 void LeaveCriticalSection(CRITICAL_SECTION* lpCrit)
35 if (!lpCrit->LockCount)
36 fprintf( stderr, "Error: leaving critical section %08lx again\n",
37 (DWORD)lpCrit );
38 lpCrit->LockCount--;
41 void DeleteCriticalSection(CRITICAL_SECTION* lpCrit)
43 return;
46 void ReinitializeCriticalSection(CRITICAL_SECTION *lpCrit) {
47 /* hmm */
50 void MakeCriticalSectionGlobal(CRITICAL_SECTION *lpCrit) {
51 /* hmm */
55 /* FIXME: This is required to work cross-addres space as well */
56 static CRITICAL_SECTION interlocked;
57 static int interlocked_init;
59 static void get_interlocked()
61 if(!interlocked_init)
62 InitializeCriticalSection(&interlocked);
63 interlocked_init=1;
64 EnterCriticalSection(&interlocked);
67 static void release_interlocked()
69 LeaveCriticalSection(&interlocked);
72 /***********************************************************************
73 * InterlockedIncrement
75 LONG InterlockedIncrement(LPLONG lpAddend)
77 int ret;
78 get_interlocked();
79 (*lpAddend)++;
80 ret=*lpAddend;
81 release_interlocked();
82 return ret;
85 /***********************************************************************
86 * InterlockedDecrement
88 LONG InterlockedDecrement(LPLONG lpAddend)
90 int ret;
91 get_interlocked();
92 (*lpAddend)--;
93 ret=*lpAddend;
94 release_interlocked();
95 return ret;
98 /***********************************************************************
99 * InterlockedExchange
101 LONG InterlockedExchange(LPLONG target, LONG value)
103 int ret;
104 get_interlocked();
105 ret=*target;
106 *target=value;
107 release_interlocked();
108 return ret;