#include "rcs_defs.hh"
#include <windows.h>
#include <winbase.h>
#include <stdio.h>
#include "dbg_mem.h"
Include dependency graph for win32_sem.c:
Go to the source code of this file.
Functions | |
int | rcs_sem_clear (rcs_sem_t *sem) |
rcs_sem_t * | rcs_sem_open (const char *name, int oflag,...) |
rcs_sem_t * | rcs_sem_create (unsigned long int id, int mode, int state) |
int | rcs_sem_init (rcs_sem_t *sem, int pshared, unsigned int value) |
int | rcs_sem_destroy (rcs_sem_t *sem) |
int | rcs_sem_close (rcs_sem_t *sem) |
int | rcs_sem_unlink (const char *name) |
int | rcs_sem_wait (rcs_sem_t *sem, double timeout) |
int | rcs_sem_trywait (rcs_sem_t *sem) |
int | rcs_sem_post (rcs_sem_t *sem) |
int | rcs_sem_flush (rcs_sem_t *sem) |
int | rcs_sem_getvalue (rcs_sem_t *sem, unsigned int *sval) |
|
Definition at line 25 of file win32_sem.c. Referenced by rcs_sem_t().
00026 { 00027 /* Un implimented. */ 00028 return (0); 00029 } |
|
Definition at line 32 of file win32_sem.c. Referenced by rcs_sem_create(), and rcs_sem_t().
00033 { 00034 #if defined(WIN32) && defined(UNICODE) 00035 wchar_t wname[64]; 00036 #endif 00037 unsigned long int id = (unsigned long int) name; 00038 rcs_sem_t *sem; 00039 sem = (rcs_sem_t *) DEBUG_MALLOC (sizeof (rcs_sem_t)); 00040 if (NULL == sem) 00041 { 00042 rcs_print_error ("Out of memory. (Error = %d\n)", GetLastError ()); 00043 return NULL; 00044 } 00045 00046 #ifndef NO_STDIO 00047 sprintf (sem->name, "sem%d", (int) id); 00048 #else 00049 strcpy (sem->name, "sem"); 00050 _itoa (id, sem->name + 3, 10); 00051 #endif 00052 00053 #ifdef UNDER_CE 00054 #ifdef UNICODE 00055 RCS_CE_ASCII_TO_UNICODE (wname, sem->name, 64); 00056 sem->handle = CreateMutex (NULL, FALSE, wname); 00057 #else 00058 sem->handle = CreateMutex (NULL, FALSE, sem->name); 00059 #endif 00060 if (NULL == sem->handle) 00061 { 00062 rcs_print_error ("Can not create semaphore. (Error = %d)\n", 00063 GetLastError ()); 00064 free (sem); 00065 return NULL; 00066 } 00067 #else 00068 sem->handle = OpenMutex (MUTEX_ALL_ACCESS, TRUE, sem->name); 00069 if (NULL == sem->handle) 00070 { 00071 rcs_print_error ("Can not create semaphore. (Error = %d)\n", 00072 GetLastError ()); 00073 free (sem); 00074 return NULL; 00075 } 00076 #endif 00077 return sem; 00078 } |
|
Definition at line 81 of file win32_sem.c. Referenced by rcs_sem_t().
00082 { 00083 #ifdef UNICODE 00084 wchar_t wname[64]; 00085 #endif 00086 rcs_sem_t *sem; 00087 #ifndef UNDER_CE 00088 SECURITY_ATTRIBUTES sa; 00089 SECURITY_DESCRIPTOR sd; 00090 if (FALSE == 00091 InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION)) 00092 { 00093 rcs_print_error 00094 ("Can not initailize security descriptor.(Error = %d)\n", 00095 GetLastError ()); 00096 return NULL; 00097 } 00098 sa.nLength = sizeof (SECURITY_ATTRIBUTES); 00099 sa.lpSecurityDescriptor = &sd; 00100 sa.bInheritHandle = TRUE; 00101 #endif 00102 sem = (rcs_sem_t *) DEBUG_MALLOC (sizeof (rcs_sem_t)); 00103 if (NULL == sem) 00104 { 00105 rcs_print_error ("Out of memory. (Error = %d\n)", GetLastError ()); 00106 return NULL; 00107 } 00108 #ifndef NO_STDIO 00109 sprintf (sem->name, "sem%d", (int) id); 00110 #else 00111 strcpy (sem->name, "sem"); 00112 _itoa (id, sem->name + 3, 10); 00113 #endif 00114 #ifdef UNDER_CE 00115 #ifdef UNICODE 00116 RCS_CE_ASCII_TO_UNICODE (wname, sem->name, 64); 00117 sem->handle = CreateMutex (NULL, FALSE, wname); 00118 #else 00119 sem->handle = CreateMutex (NULL, FALSE, sem->name); 00120 #endif 00121 #else 00122 sem->handle = CreateMutex (&sa, FALSE, sem->name); 00123 #endif 00124 00125 if (NULL == sem->handle) 00126 { 00127 rcs_print_error ("Can not create semaphore. (Error = %d)\n", 00128 GetLastError ()); 00129 free (sem); 00130 return NULL; 00131 } 00132 return sem; 00133 } |
|
Definition at line 136 of file win32_sem.c. Referenced by rcs_sem_create(), and rcs_sem_t().
00137 { 00138 return 0; 00139 } |
|
Definition at line 142 of file win32_sem.c. Referenced by rcs_sem_t().
00143 { 00144 return rcs_sem_close (sem); 00145 } |
|
Definition at line 148 of file win32_sem.c. Referenced by rcs_sem_destroy(), rcs_sem_t(), and rcs_sem_unlink().
|
|
Definition at line 162 of file win32_sem.c. Referenced by rcs_sem_t().
00163 { 00164 rcs_sem_t *sem = (rcs_sem_t *) name; 00165 return rcs_sem_close (sem); 00166 } |
|
Definition at line 169 of file win32_sem.c. Referenced by rcs_sem_t(), and rcs_sem_trywait().
00170 { 00171 int error; 00172 if (sem == NULL) 00173 { 00174 return -1; 00175 } 00176 if (sem->handle == NULL) 00177 { 00178 return -1; 00179 } 00180 if (WAIT_FAILED == WaitForSingleObject (sem->handle, 00181 ((unsigned long) (timeout * 1000)))) 00182 { 00183 if (WAIT_TIMEOUT == (error = GetLastError ())) 00184 { 00185 return -2; 00186 } 00187 rcs_print_error ("WaitForSingleObject failed. (Error = %d)\n", error); 00188 return -1; 00189 } 00190 return 0; 00191 } |
|
Definition at line 195 of file win32_sem.c. Referenced by rcs_sem_t(), and rcs_sem_wait().
00196 { 00197 return rcs_sem_wait (sem, 0); 00198 } |
|
Definition at line 201 of file win32_sem.c. Referenced by rcs_sem_t().
00202 { 00203 if (FALSE == ReleaseMutex (sem->handle)) 00204 { 00205 rcs_print_error ("ReleaseMutex failed. (Error = %d)\n", 00206 GetLastError ()); 00207 return -1; 00208 } 00209 return 0; 00210 } |
|
Definition at line 213 of file win32_sem.c. Referenced by rcs_sem_t(), and sem_force_fifo().
00214 { 00215 if (FALSE == ReleaseMutex (sem->handle)) 00216 { 00217 rcs_print_error ("ReleaseMutex failed. (Error = %d)\n", 00218 GetLastError ()); 00219 return -1; 00220 } 00221 return 0; 00222 } |
|
Definition at line 226 of file win32_sem.c. Referenced by RCS_SEMAPHORE::RCS_SEMAPHORE(), and rcs_sem_t().
00227 { 00228 if (WAIT_FAILED == WaitForSingleObject (sem->handle, 0)) 00229 { 00230 return 1; 00231 } 00232 return 0; 00233 } |