Changeset 2090 for trunk/src/emx/include
- Timestamp:
- Jun 27, 2005, 5:30:23 AM (20 years ago)
- Location:
- trunk/src/emx/include
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/include/emx/io.h
-
Property cvs2svn:cvs-rev
changed from
1.15
to1.16
r2089 r2090 8 8 #include <InnoTekLIBC/fork.h> 9 9 #include <alloca.h> 10 #include <stdio.h> 10 11 11 12 __BEGIN_DECLS … … 148 149 #define _IONOCLOSEALL 0x00020000 149 150 151 /** This bit is set when the stream is locked by flockfile() or ftrylockfile(). 152 * !!TEMPORARY HACK!! 153 * @todo replace the fmutex on the stream with a recursive lock! */ 154 #define _IOLOCKED 0xff000000 150 155 151 156 #define _FLUSH_FLUSH (-1) … … 192 197 193 198 #if defined (_SYS_FMUTEX_H) 194 195 199 /* This semaphore (defined in app/stdio.c) protects _streamv[]. Only 196 200 concurrent access by _newstream(), _setmore(), and freopen() in … … 204 208 #define STREAMV_LOCK _fmutex_checked_request(&_streamv_fmutex, _FMR_IGNINT) 205 209 #define STREAMV_UNLOCK _fmutex_checked_release(&_streamv_fmutex) 206 207 #define STREAM_LOCK(f) \ 208 ((f)->__uVersion != _FILE_STDIO_VERSION ? __stream_abort (f, "version error") \ 209 : _fmutex_request(&(f)->__u.__fsem, _FMR_IGNINT) != 0 \ 210 ? __stream_abort (f, "fmutex request") : 0) 211 212 #define STREAM_UNLOCK(f) \ 213 (_fmutex_release(&(f)->__u.__fsem) != 0 ? __stream_abort (f, "fmutex release") : (void)0) 214 215 #define STREAM_LOCK_NOWAIT(f) \ 216 (((f)->__uVersion == _FILE_STDIO_VERSION || __stream_abort (f, "version error")) && _fmutex_request(&(f)->__u.__fsem, _FMR_NOWAIT) == 0) 217 218 #define STREAM_UNLOCKED(f) ((f)->__uVersion == _FILE_STDIO_VERSION && _fmutex_available(&(f)->__u.__fsem)) 210 #endif /* _SYS_FMUTEX_H */ 211 212 #if defined (__FILE_FSEM_DECLARED) 219 213 220 214 int __stream_abort(struct _FILE *f, const char *pszMsg); 221 215 222 #endif /* defined (_SYS_FMUTEX_H) */ 216 static int __inline__ stream_validate(struct _FILE *stream) 217 { 218 if (stream->__uVersion != _FILE_STDIO_VERSION) 219 { 220 __stream_abort(stream, "version error"); 221 return 0; 222 } 223 return 1; 224 } 225 226 static int __inline__ stream_lock(struct _FILE *stream) 227 { 228 if (!stream_validate(stream)) 229 return 0; 230 if ( !(stream->_flags & _IOLOCKED) 231 || !_fmutex_is_owner(&stream->__u.__fsem)) 232 { 233 if (_fmutex_request(&stream->__u.__fsem, _FMR_IGNINT) != 0) 234 { 235 __stream_abort(stream, "fmutex_request failed"); 236 return 0; 237 } 238 stream->_flags = 0x01000000 | (stream->_flags & ~_IOLOCKED); 239 } 240 else 241 stream->_flags = ((stream->_flags & _IOLOCKED) + 0x01000000) | (stream->_flags & ~_IOLOCKED); 242 return 1; 243 } 244 245 static int __inline__ stream_trylock(struct _FILE *stream) 246 { 247 if (!stream_validate(stream)) 248 return 0; 249 if ( !(stream->_flags & _IOLOCKED) 250 || !_fmutex_is_owner(&stream->__u.__fsem)) 251 { 252 if (_fmutex_request(&stream->__u.__fsem, _FMR_NOWAIT) != 0) 253 { 254 __stream_abort(stream, "fmutex_request failed"); 255 return 0; 256 } 257 stream->_flags = 0x01000000 | (stream->_flags & ~_IOLOCKED); 258 } 259 else 260 stream->_flags = ((stream->_flags & _IOLOCKED) + 0x01000000) | (stream->_flags & ~_IOLOCKED); 261 return 1; 262 } 263 264 static int __inline__ stream_unlock(struct _FILE *stream) 265 { 266 if (!stream_validate(stream)) 267 return 0; 268 if (!(stream->_flags & _IOLOCKED)) 269 { 270 __stream_abort(stream, "unlock, 0 count"); 271 return 0; 272 } 273 #ifdef __LIBC_STRICT 274 if (!_fmutex_is_owner(&stream->__u.__fsem)) 275 { 276 __stream_abort(stream, "unlock, not owner"); 277 return 0; 278 } 279 #endif 280 stream->_flags = ((stream->_flags & _IOLOCKED) - 0x01000000) | (stream->_flags & ~_IOLOCKED); 281 if ( !(stream->_flags & _IOLOCKED) 282 && _fmutex_release(&stream->__u.__fsem) != 0) 283 { 284 __stream_abort(stream, "fmutex_release failed"); 285 return 0; 286 } 287 return 1; 288 } 289 290 #define STREAM_LOCK(f) stream_lock(f) 291 #define STREAM_UNLOCK(f) stream_unlock(f) 292 #define STREAM_LOCK_NOWAIT(f) stream_trylock(f) 293 #define STREAM_UNLOCKED(f) ((f)->__uVersion == _FILE_STDIO_VERSION && _fmutex_available(&(f)->__u.__fsem)) 294 295 #endif /* __FILE_FSEM_DECLARED */ 223 296 224 297 struct __libc_FileHandle; … … 434 507 int _flushstream (struct _FILE *, int); 435 508 void _closestream (struct _FILE *); 436 int _fflush_nolock (struct _FILE *); 437 int _fseek_nolock (struct _FILE *, off_t, int); 438 off_t _ftell_nolock (struct _FILE *); 439 size_t _fwrite_nolock (const void *, size_t, size_t, struct _FILE *); 509 int _fseek_unlocked (struct _FILE *, off_t, int); 510 off_t _ftello_unlocked (struct _FILE *); 440 511 int _input (struct _FILE *, __const__ char *, char *); 441 512 struct _FILE *_newstream (void); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/stdio.h
-
Property cvs2svn:cvs-rev
changed from
1.14
to1.15
r2089 r2090 200 200 { 201 201 #if defined (_SYS_FMUTEX_H) 202 #define __FILE_FSEM_DECLARED 203 /** @todo replace this by a nested lock construct, see flockfile(). */ 202 204 _fmutex __fsem; 203 205 #endif … … 287 289 long ftell(FILE *); 288 290 size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict); 289 #if 0 /* bird: emx */290 291 int getc(FILE *); 291 #else /* bird: emx */292 /** @todo: Check the standard, if this is correct or not. declaration might be required. */293 #define getc(s) fgetc(s) /* bird: emx */294 #endif /* bird: emx */295 292 int getchar(void); 296 293 char *gets(char *); 297 294 void perror(const char *); 298 295 int printf(const char * __restrict, ...); 299 #if 0 /* bird: emx */300 296 int putc(int, FILE *); 301 #else /* bird: emx */302 /** @todo: Check the standard, if this is correct or not. declaration might be required. */303 #define putc(c,s) fputc(c,s) /* bird: emx */304 #endif /* bird: emx */305 297 int putchar(int); 306 298 int puts(const char *); … … 356 348 357 349 #if __POSIX_VISIBLE >= 199506 358 /** @todo int ftrylockfile(FILE *); */ 359 /** @todo void flockfile(FILE *); */ 360 /** @todo void funlockfile(FILE *); */ 350 int ftrylockfile(FILE *); 351 void flockfile(FILE *); 352 void funlockfile(FILE *); 361 353 362 354 /* … … 364 356 * requires functions as well. 365 357 */ 366 /** @todo int getc_unlocked(FILE *); */ 367 /** @todo int getchar_unlocked(void); */ 368 /** @todo int putc_unlocked(int, FILE *); */ 369 /** @todo int putchar_unlocked(int); */ 358 int getc_unlocked(FILE *); 359 int getchar_unlocked(void); 360 int putc_unlocked(int, FILE *); 361 int putchar_unlocked(int); 370 362 #endif 371 363 #if __BSD_VISIBLE 372 /** @todo void clearerr_unlocked(FILE *); */ 373 /** @todo int feof_unlocked(FILE *); */ 374 /** @todo int ferror_unlocked(FILE *); */ 375 /** @todo int fileno_unlocked(FILE *); */ 364 void clearerr_unlocked(FILE *); 365 int feof_unlocked(FILE *); 366 int ferror_unlocked(FILE *); 367 int fileno_unlocked(FILE *); 368 #endif 369 #ifdef __USE_MISC 370 int fflush_unlocked(FILE *); 371 size_t fwrite_unlocked(const void * __restrict, size_t, size_t, FILE * __restrict); 372 size_t fread_unlocked(void * __restrict, size_t, size_t, FILE * __restrict); 373 int fgetc_unlocked(FILE *); 374 int fputc_unlocked(int, FILE *); 375 int fputs_unlocked(const char * __restrict, FILE * __restrict); 376 int puts_unlocked(const char *); 376 377 #endif 377 378 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/sys/fmutex.h
-
Property cvs2svn:cvs-rev
changed from
1.6
to1.7
r2089 r2090 104 104 } 105 105 106 107 static __inline__ int _fmutex_is_owner (_fmutex *sem) 108 { 109 return sem->fs > _FMS_AVAILABLE && sem->Owner == fibGetTidPid(); 110 } 111 106 112 /** 107 113 * Release a semaphore in the child process after the -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.