< prev index next >

src/java.base/linux/native/libnet/linux_close.c

Print this page




  43 /*
  44  * Stack allocated by thread when doing blocking operation
  45  */
  46 typedef struct threadEntry {
  47     pthread_t thr;                      /* this thread */
  48     struct threadEntry *next;           /* next thread */
  49     int intr;                           /* interrupted */
  50 } threadEntry_t;
  51 
  52 /*
  53  * Heap allocated during initialized - one entry per fd
  54  */
  55 typedef struct {
  56     pthread_mutex_t lock;               /* fd lock */
  57     threadEntry_t *threads;             /* threads blocked on fd */
  58 } fdEntry_t;
  59 
  60 /*
  61  * Signal to unblock thread
  62  */
  63 static int sigWakeup = (__SIGRTMAX - 2);
  64 
  65 /*
  66  * fdTable holds one entry per file descriptor, up to a certain
  67  * maximum.
  68  * Theoretically, the number of possible file descriptors can get
  69  * large, though usually it does not. Entries for small value file
  70  * descriptors are kept in a simple table, which covers most scenarios.
  71  * Entries for large value file descriptors are kept in an overflow
  72  * table, which is organized as a sparse two dimensional array whose
  73  * slabs are allocated on demand. This covers all corner cases while
  74  * keeping memory consumption reasonable.
  75  */
  76 
  77 /* Base table for low value file descriptors */
  78 static fdEntry_t* fdTable = NULL;
  79 /* Maximum size of base table (in number of entries). */
  80 static const int fdTableMaxSize = 0x1000; /* 4K */
  81 /* Actual size of base table (in number of entries) */
  82 static int fdTableLen = 0;
  83 /* Max. theoretical number of file descriptors on system. */


 132     } else {
 133         for (i = 0; i < fdTableLen; i ++) {
 134             pthread_mutex_init(&fdTable[i].lock, NULL);
 135         }
 136     }
 137 
 138     /* Allocate overflow table, if needed */
 139     if (fdLimit > fdTableMaxSize) {
 140         fdOverflowTableLen = ((fdLimit - fdTableMaxSize) / fdOverflowTableSlabSize) + 1;
 141         fdOverflowTable = (fdEntry_t**) calloc(fdOverflowTableLen, sizeof(fdEntry_t*));
 142         if (fdOverflowTable == NULL) {
 143             fprintf(stderr, "library initialization failed - "
 144                     "unable to allocate file descriptor overflow table - out of memory");
 145             abort();
 146         }
 147     }
 148 
 149     /*
 150      * Setup the signal handler
 151      */

 152     sa.sa_handler = sig_wakeup;
 153     sa.sa_flags   = 0;
 154     sigemptyset(&sa.sa_mask);
 155     sigaction(sigWakeup, &sa, NULL);
 156 
 157     sigemptyset(&sigset);
 158     sigaddset(&sigset, sigWakeup);
 159     sigprocmask(SIG_UNBLOCK, &sigset, NULL);
 160 }
 161 
 162 /*
 163  * Return the fd table for this fd.
 164  */
 165 static inline fdEntry_t *getFdEntry(int fd)
 166 {
 167     fdEntry_t* result = NULL;
 168 
 169     if (fd < 0) {
 170         return NULL;
 171     }




  43 /*
  44  * Stack allocated by thread when doing blocking operation
  45  */
  46 typedef struct threadEntry {
  47     pthread_t thr;                      /* this thread */
  48     struct threadEntry *next;           /* next thread */
  49     int intr;                           /* interrupted */
  50 } threadEntry_t;
  51 
  52 /*
  53  * Heap allocated during initialized - one entry per fd
  54  */
  55 typedef struct {
  56     pthread_mutex_t lock;               /* fd lock */
  57     threadEntry_t *threads;             /* threads blocked on fd */
  58 } fdEntry_t;
  59 
  60 /*
  61  * Signal to unblock thread
  62  */
  63 static int sigWakeup;
  64 
  65 /*
  66  * fdTable holds one entry per file descriptor, up to a certain
  67  * maximum.
  68  * Theoretically, the number of possible file descriptors can get
  69  * large, though usually it does not. Entries for small value file
  70  * descriptors are kept in a simple table, which covers most scenarios.
  71  * Entries for large value file descriptors are kept in an overflow
  72  * table, which is organized as a sparse two dimensional array whose
  73  * slabs are allocated on demand. This covers all corner cases while
  74  * keeping memory consumption reasonable.
  75  */
  76 
  77 /* Base table for low value file descriptors */
  78 static fdEntry_t* fdTable = NULL;
  79 /* Maximum size of base table (in number of entries). */
  80 static const int fdTableMaxSize = 0x1000; /* 4K */
  81 /* Actual size of base table (in number of entries) */
  82 static int fdTableLen = 0;
  83 /* Max. theoretical number of file descriptors on system. */


 132     } else {
 133         for (i = 0; i < fdTableLen; i ++) {
 134             pthread_mutex_init(&fdTable[i].lock, NULL);
 135         }
 136     }
 137 
 138     /* Allocate overflow table, if needed */
 139     if (fdLimit > fdTableMaxSize) {
 140         fdOverflowTableLen = ((fdLimit - fdTableMaxSize) / fdOverflowTableSlabSize) + 1;
 141         fdOverflowTable = (fdEntry_t**) calloc(fdOverflowTableLen, sizeof(fdEntry_t*));
 142         if (fdOverflowTable == NULL) {
 143             fprintf(stderr, "library initialization failed - "
 144                     "unable to allocate file descriptor overflow table - out of memory");
 145             abort();
 146         }
 147     }
 148 
 149     /*
 150      * Setup the signal handler
 151      */
 152     sigWakeup = SIGRTMAX - 2;
 153     sa.sa_handler = sig_wakeup;
 154     sa.sa_flags   = 0;
 155     sigemptyset(&sa.sa_mask);
 156     sigaction(sigWakeup, &sa, NULL);
 157 
 158     sigemptyset(&sigset);
 159     sigaddset(&sigset, sigWakeup);
 160     sigprocmask(SIG_UNBLOCK, &sigset, NULL);
 161 }
 162 
 163 /*
 164  * Return the fd table for this fd.
 165  */
 166 static inline fdEntry_t *getFdEntry(int fd)
 167 {
 168     fdEntry_t* result = NULL;
 169 
 170     if (fd < 0) {
 171         return NULL;
 172     }


< prev index next >