Changeset 6556 in vbox
- Timestamp:
- Jan 29, 2008 3:03:40 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
r6538 r6556 70 70 static RTFILE g_File = NIL_RTFILE; 71 71 #endif 72 /** 72 /** User counter. 73 73 * A counter of the number of times the library has been initialised, for use with 74 74 * X.org drivers, where the library may be shared by multiple independant modules 75 75 * inside a single process space. 76 76 */ 77 static uint32_t g_cInits = 0; 77 static uint32_t volatile g_cInits = 0; 78 78 79 79 80 VBGLR3DECL(int) VbglR3Init(void) 80 81 { 81 82 uint32_t cInits = ASMAtomicIncU32(&g_cInits); 82 #ifdef VBOX_VBGLR3_XFREE86 83 if (1 != cInits) 84 return VINF_SUCCESS; 85 if (-1 != g_File) 86 return VERR_INTERNAL_ERROR; 87 #else 83 #ifndef VBOX_VBGLR3_XFREE86 88 84 Assert(cInits > 0); 89 if (1 > cInits) 90 { 91 /* This will not work when the library is shared inside a multi-threaded 92 process. Hopefully no-one will try that, as we can't use the threads 93 APIs here. */ 94 if (NIL_RTFILE == g_File) 85 #endif 86 if (cInits > 1) 87 { 88 /* 89 * This will fail if two (or more) threads race each other calling VbglR3Init. 90 * However it will work fine for single threaded or otherwise serialized 91 * processed calling us more than once. 92 */ 93 #ifndef VBOX_VBGLR3_XFREE86 94 if (g_File == NIL_RTFILE) 95 #else 96 if (g_File == -1) 97 #endif 95 98 return VERR_INTERNAL_ERROR; 96 99 return VINF_SUCCESS; 97 100 } 98 if (NIL_RTFILE != g_File) 101 #ifndef VBOX_VBGLR3_XFREE86 102 if (g_File != NIL_RTFILE) 103 #else 104 if (g_File != -1) 105 #endif 99 106 return VERR_INTERNAL_ERROR; 100 #endif101 107 102 108 #if defined(RT_OS_OS2) … … 153 159 #elif defined(VBOX_VBGLR3_XFREE86) 154 160 int File = open(VBOXGUEST_DEVICE_NAME, O_RDWR); 155 if (-1 == File) 156 { 157 return VERR_UNRESOLVED_ERROR; 158 } 161 if (File == -1) 162 return VERR_OPEN_FAILED; 159 163 g_File = File; 160 164 … … 179 183 return; 180 184 #ifndef VBOX_VBGLR3_XFREE86 181 AssertReturnVoid( 0 ==cInits);185 AssertReturnVoid(!cInits); 182 186 RTFILE File = g_File; 183 187 g_File = NIL_RTFILE; 184 AssertReturnVoid(NIL_RTFILE != File); 188 AssertReturnVoid(File != NIL_RTFILE); 189 185 190 #else 186 191 int File = g_File; 187 192 g_File = -1; 188 if ( -1 == File)193 if (File == -1) 189 194 return; 190 195 #endif 196 191 197 #if defined(RT_OS_OS2) 192 198 APIRET rc = DosClose(File); 193 199 AssertMsg(!rc, ("%ld\n", rc)); 200 194 201 #elif defined(VBOX_VBGLR3_XFREE86) 195 /* if (-1 == close(File)) 196 { 197 int iErr = errno; 198 AssertRC(RTErrConvertFromErrno(iErr)); 199 } */ 200 close(File); /* iprt is not available here. */ 202 close(File); 201 203 File = -1; 204 202 205 #else 203 206 int rc = RTFileClose(File); … … 240 243 Hdr.pvDataR3 = pvData; 241 244 245 /** @todo test status code passing! */ 242 246 int rc = ioctl((int)g_File, iFunction, &Hdr); 243 247 if (rc == -1) … … 248 252 return VINF_SUCCESS; 249 253 250 #el se251 /* Default implementation - PORTME: Do not use this without testings that error passing works!*/252 # ifdef VBOX_VBGLR3_XFREE86 253 int rc = ioctl(g_File, (int) iFunction, pvData);254 #elif defined(VBOX_VBGLR3_XFREE86) 255 /* PORTME - This is preferred over the RTFileIOCtl variant below, just be careful with the (int). */ 256 /** @todo test status code passing! */ 257 int rc = ioctl(g_File, (int)iFunction, pvData); 254 258 if (rc == -1) 255 259 { … … 258 262 } 259 263 return VINF_SUCCESS; 260 # else 264 265 #else 266 /* Default implementation - PORTME: Do not use this without testings that passing errors works! */ 267 /** @todo test status code passing! */ 261 268 int rc2 = VERR_INTERNAL_ERROR; 262 269 int rc = RTFileIoCtl(g_File, (int)iFunction, pvData, cbData, &rc2); … … 264 271 rc = rc2; 265 272 return rc; 266 # endif 267 #endif 268 } 269 273 #endif 274 } 275
Note:
See TracChangeset
for help on using the changeset viewer.