thr_read.c (13546) | thr_read.c (22315) |
---|---|
1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37#include <unistd.h> 38#ifdef _THREAD_SAFE 39#include <pthread.h> 40#include "pthread_private.h" 41 42ssize_t 43read(int fd, void *buf, size_t nbytes) 44{ | 1/* 2 * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37#include <unistd.h> 38#ifdef _THREAD_SAFE 39#include <pthread.h> 40#include "pthread_private.h" 41 42ssize_t 43read(int fd, void *buf, size_t nbytes) 44{ |
45 int nonblock; 46 int ret; 47 int status; 48 if (fd < 0 || fd > _thread_dtablesize || _thread_fd_table[fd] == NULL) { 49 _thread_seterrno(_thread_run, EBADF); 50 ret = -1; 51 } else if ((nonblock = _thread_fd_table[fd]->flags & O_NONBLOCK) == 0 && (ret = _thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__)) != 0) { 52 /* Cannot lock file descriptor. */ 53 } else { | 45 int ret; 46 int status; 47 48 /* Lock the file descriptor for read: */ 49 if ((ret = _thread_fd_lock(fd, FD_READ, NULL, 50 __FILE__, __LINE__)) == 0) { 51 /* Perform a non-blocking read syscall: */ |
54 while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) { | 52 while ((ret = _thread_sys_read(fd, buf, nbytes)) < 0) { |
55 if (nonblock == 0 && (errno == EWOULDBLOCK || errno == EAGAIN)) { | 53 if (_thread_fd_table[fd]->flags & O_NONBLOCK == 0 && 54 (errno == EWOULDBLOCK || errno == EAGAIN)) { |
56 _thread_kern_sig_block(&status); 57 _thread_run->data.fd.fd = fd; 58 _thread_kern_set_timeout(NULL); | 55 _thread_kern_sig_block(&status); 56 _thread_run->data.fd.fd = fd; 57 _thread_kern_set_timeout(NULL); |
59 _thread_kern_sched_state(PS_FDR_WAIT, __FILE__, __LINE__); 60 if (errno == EINTR) { | 58 59 /* Reset the interrupted operation flag: */ 60 _thread_run->interrupted = 0; 61 62 _thread_kern_sched_state(PS_FDR_WAIT, 63 __FILE__, __LINE__); 64 65 /* 66 * Check if the operation was 67 * interrupted by a signal 68 */ 69 if (_thread_run->interrupted) { |
61 ret = -1; 62 break; 63 } 64 } else { 65 break; 66 } 67 } | 70 ret = -1; 71 break; 72 } 73 } else { 74 break; 75 } 76 } |
68 if (nonblock == 0) { 69 _thread_fd_unlock(fd, FD_READ); 70 } | 77 _thread_fd_unlock(fd, FD_READ); |
71 } 72 return (ret); 73} 74#endif | 78 } 79 return (ret); 80} 81#endif |