Mercurial > sdl-ios-xcode
comparison src/thread/amigaos/SDL_syssem.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
35 #undef D | 35 #undef D |
36 | 36 |
37 #define D(x) | 37 #define D(x) |
38 | 38 |
39 SDL_sem * | 39 SDL_sem * |
40 SDL_CreateSemaphore (Uint32 initial_value) | 40 SDL_CreateSemaphore(Uint32 initial_value) |
41 { | 41 { |
42 SDL_sem *sem; | 42 SDL_sem *sem; |
43 | 43 |
44 sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); | 44 sem = (SDL_sem *) SDL_malloc(sizeof(*sem)); |
45 | 45 |
46 if (!sem) { | 46 if (!sem) { |
47 SDL_OutOfMemory (); | 47 SDL_OutOfMemory(); |
48 return (0); | 48 return (0); |
49 } | 49 } |
50 | 50 |
51 D (bug ("Creating semaphore %lx...\n", sem)); | 51 D(bug("Creating semaphore %lx...\n", sem)); |
52 | 52 |
53 SDL_memset (sem, 0, sizeof (*sem)); | 53 SDL_memset(sem, 0, sizeof(*sem)); |
54 | 54 |
55 InitSemaphore (&sem->Sem); | 55 InitSemaphore(&sem->Sem); |
56 | 56 |
57 return (sem); | 57 return (sem); |
58 } | 58 } |
59 | 59 |
60 void | 60 void |
61 SDL_DestroySemaphore (SDL_sem * sem) | 61 SDL_DestroySemaphore(SDL_sem * sem) |
62 { | 62 { |
63 D (bug ("Destroying semaphore %lx...\n", sem)); | 63 D(bug("Destroying semaphore %lx...\n", sem)); |
64 | 64 |
65 if (sem) { | 65 if (sem) { |
66 // Condizioni per liberare i task in attesa? | 66 // Condizioni per liberare i task in attesa? |
67 SDL_free (sem); | 67 SDL_free(sem); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 int | 71 int |
72 SDL_SemTryWait (SDL_sem * sem) | 72 SDL_SemTryWait(SDL_sem * sem) |
73 { | 73 { |
74 if (!sem) { | 74 if (!sem) { |
75 SDL_SetError ("Passed a NULL semaphore"); | 75 SDL_SetError("Passed a NULL semaphore"); |
76 return -1; | 76 return -1; |
77 } | 77 } |
78 | 78 |
79 D (bug ("TryWait semaphore...%lx\n", sem)); | 79 D(bug("TryWait semaphore...%lx\n", sem)); |
80 | 80 |
81 ObtainSemaphore (&sem->Sem); | 81 ObtainSemaphore(&sem->Sem); |
82 // ReleaseSemaphore(&sem->Sem); | 82 // ReleaseSemaphore(&sem->Sem); |
83 | 83 |
84 return 1; | 84 return 1; |
85 } | 85 } |
86 | 86 |
87 int | 87 int |
88 SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) | 88 SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout) |
89 { | 89 { |
90 int retval; | 90 int retval; |
91 | 91 |
92 | 92 |
93 if (!sem) { | 93 if (!sem) { |
94 SDL_SetError ("Passed a NULL semaphore"); | 94 SDL_SetError("Passed a NULL semaphore"); |
95 return -1; | 95 return -1; |
96 } | 96 } |
97 | 97 |
98 D (bug ("WaitTimeout (%ld) semaphore...%lx\n", timeout, sem)); | 98 D(bug("WaitTimeout (%ld) semaphore...%lx\n", timeout, sem)); |
99 | 99 |
100 /* A timeout of 0 is an easy case */ | 100 /* A timeout of 0 is an easy case */ |
101 if (timeout == 0) { | 101 if (timeout == 0) { |
102 ObtainSemaphore (&sem->Sem); | 102 ObtainSemaphore(&sem->Sem); |
103 return 1; | 103 return 1; |
104 } | 104 } |
105 if (!(retval = AttemptSemaphore (&sem->Sem))) { | 105 if (!(retval = AttemptSemaphore(&sem->Sem))) { |
106 SDL_Delay (timeout); | 106 SDL_Delay(timeout); |
107 retval = AttemptSemaphore (&sem->Sem); | 107 retval = AttemptSemaphore(&sem->Sem); |
108 } | 108 } |
109 | 109 |
110 if (retval == TRUE) { | 110 if (retval == TRUE) { |
111 // ReleaseSemaphore(&sem->Sem); | 111 // ReleaseSemaphore(&sem->Sem); |
112 retval = 1; | 112 retval = 1; |
114 | 114 |
115 return retval; | 115 return retval; |
116 } | 116 } |
117 | 117 |
118 int | 118 int |
119 SDL_SemWait (SDL_sem * sem) | 119 SDL_SemWait(SDL_sem * sem) |
120 { | 120 { |
121 ObtainSemaphore (&sem->Sem); | 121 ObtainSemaphore(&sem->Sem); |
122 return 0; | 122 return 0; |
123 } | 123 } |
124 | 124 |
125 Uint32 | 125 Uint32 |
126 SDL_SemValue (SDL_sem * sem) | 126 SDL_SemValue(SDL_sem * sem) |
127 { | 127 { |
128 Uint32 value; | 128 Uint32 value; |
129 | 129 |
130 value = 0; | 130 value = 0; |
131 if (sem) { | 131 if (sem) { |
137 } | 137 } |
138 return value; | 138 return value; |
139 } | 139 } |
140 | 140 |
141 int | 141 int |
142 SDL_SemPost (SDL_sem * sem) | 142 SDL_SemPost(SDL_sem * sem) |
143 { | 143 { |
144 if (!sem) { | 144 if (!sem) { |
145 SDL_SetError ("Passed a NULL semaphore"); | 145 SDL_SetError("Passed a NULL semaphore"); |
146 return -1; | 146 return -1; |
147 } | 147 } |
148 D (bug ("SemPost semaphore...%lx\n", sem)); | 148 D(bug("SemPost semaphore...%lx\n", sem)); |
149 | 149 |
150 ReleaseSemaphore (&sem->Sem); | 150 ReleaseSemaphore(&sem->Sem); |
151 return 0; | 151 return 0; |
152 } | 152 } |
153 | 153 |
154 /* vi: set ts=4 sw=4 expandtab: */ | 154 /* vi: set ts=4 sw=4 expandtab: */ |