comparison src/thread/epoc/SDL_sysmutex.cpp @ 173:83018110dce8

Added initial support for EPOC/Symbian OS (thanks Hannu!)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 11 Sep 2001 20:38:49 +0000
parents
children e8157fcb3114
comparison
equal deleted inserted replaced
172:37e3ca9254c7 173:83018110dce8
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 /*
24 SDL_sysmutex.cpp
25
26 Epoc version by Markus Mertama (w@iki.fi)
27 */
28
29
30 #ifdef SAVE_RCSID
31 static char rcsid =
32 "@(#) $Id$";
33 #endif
34
35 /* Mutex functions using the Win32 API */
36
37 //#include <stdio.h>
38 //#include <stdlib.h>
39
40 #include<e32std.h>
41
42 #include "SDL_error.h"
43 #include "SDL_mutex.h"
44
45
46
47 struct SDL_mutex
48 {
49 TInt handle;
50 };
51
52 extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
53
54 TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*)
55 {
56 return ((RMutex*)aPtr1)->CreateGlobal(aName);
57 }
58
59 /* Create a mutex */
60 SDL_mutex *SDL_CreateMutex(void)
61 {
62 RMutex rmutex;
63
64 TInt status = CreateUnique(NewMutex, &rmutex, NULL);
65 if(status != KErrNone)
66 {
67 SDL_SetError("Couldn't create mutex");
68 }
69 SDL_mutex* mutex = new /*(ELeave)*/ SDL_mutex;
70 mutex->handle = rmutex.Handle();
71 return(mutex);
72 }
73
74 /* Free the mutex */
75 void SDL_DestroyMutex(SDL_mutex *mutex)
76 {
77 if ( mutex )
78 {
79 RMutex rmutex;
80 rmutex.SetHandle(mutex->handle);
81 rmutex.Signal();
82 rmutex.Close();
83 delete(mutex);
84 mutex = NULL;
85 }
86 }
87
88 /* Lock the mutex */
89 int SDL_mutexP(SDL_mutex *mutex)
90 {
91 if ( mutex == NULL ) {
92 SDL_SetError("Passed a NULL mutex");
93 return -1;
94 }
95 RMutex rmutex;
96 rmutex.SetHandle(mutex->handle);
97 rmutex.Wait();
98 return(0);
99 }
100
101 /* Unlock the mutex */
102 int SDL_mutexV(SDL_mutex *mutex)
103 {
104 if ( mutex == NULL ) {
105 SDL_SetError("Passed a NULL mutex");
106 return -1;
107 }
108 RMutex rmutex;
109 rmutex.SetHandle(mutex->handle);
110 rmutex.Signal();
111 return(0);
112 }