Print this page
5910 libnisdb won't build with modern GCC

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libnisdb/nisdb_rw.c
          +++ new/usr/src/lib/libnisdb/nisdb_rw.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
       23 + * Copyright 2015 Gary Mills
  23   24   * Copyright (c) 2001 by Sun Microsystems, Inc.
  24   25   * All rights reserved.
  25   26   */
  26   27  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  28      -
  29   28  #include <stdio.h>
  30   29  #include <rpc/types.h>
  31   30  #include <rpc/xdr.h>
  32   31  #include "db_dictionary_c.h"
  33   32  #include "nisdb_rw.h"
  34   33  #include "nisdb_ldap.h"
  35   34  
  36   35  /*
  37   36   * Nesting-safe RW locking functions. Return 0 when successful, an
  38   37   * error number from the E-series when not.
↓ open down ↓ 61 lines elided ↑ open up ↑
 100   99                          break;
 101  100          }
 102  101  
 103  102          return (rr);
 104  103  }
 105  104  
 106  105  
 107  106  int
 108  107  __nisdb_rw_readlock_ok(__nisdb_rwlock_t *rw) {
 109  108          int             ret;
 110      -        pthread_t       myself = pthread_self();
 111      -        __nisdb_rl_t    *rr;
 112  109  
 113  110          if (rw == 0)
 114  111                  return (EFAULT);
 115  112  
 116  113          if (rw->destroyed != 0)
 117  114                  return (ESHUTDOWN);
 118  115  
 119  116          if ((ret = mutex_lock(&rw->mutex)) != 0)
 120  117                  return (ret);
 121  118  
↓ open down ↓ 10 lines elided ↑ open up ↑
 132  129  
 133  130          (void) mutex_unlock(&rw->mutex);
 134  131  
 135  132          return (ret);
 136  133  }
 137  134  
 138  135  
 139  136  int
 140  137  __nisdb_rw_force_writelock(__nisdb_rwlock_t *rw) {
 141  138          int             ret;
 142      -        pthread_t       myself = pthread_self();
 143      -        __nisdb_rl_t    *rr;
 144  139  
 145  140          if (rw == 0 || rw->destroyed != 0)
 146  141                  return (ESHUTDOWN);
 147  142  
 148  143          if ((ret = mutex_lock(&rw->mutex)) != 0)
 149  144                  return (ret);
 150  145  
 151  146          /*
 152  147           * Only allow changing 'force_write' when it's really safe; i.e.,
 153  148           * the lock hasn't been destroyed, and there are no readers.
↓ open down ↓ 45 lines elided ↑ open up ↑
 199  194                  rw->writer.count = 1;
 200  195                  return (mutex_unlock(&rw->mutex));
 201  196          }
 202  197  
 203  198          /*
 204  199           * Need to know if we're holding a read lock already, and if
 205  200           * all other readers are blocked waiting for the mutex.
 206  201           */
 207  202          if (rw->reader_count > 0) {
 208  203                  if ((rr = find_reader(myself, rw)) != 0) {
 209      -                        if (rr->count)
      204 +                        if (rr->count) {
 210  205                                  /*
 211  206                                   * We're already holding a read lock, so
 212  207                                   * if the number of readers equals the number
 213  208                                   * of blocked readers plus one, all other
 214  209                                   * readers are blocked.
 215  210                                   */
 216  211                                  if (rw->reader_count ==
 217  212                                                  (rw->reader_blocked + 1))
 218  213                                          all_readers_blocked = 1;
 219      -                        else
      214 +                        } else {
 220  215                                  /*
 221  216                                   * We're not holding a read lock, so the
 222  217                                   * number of readers should equal the number
 223  218                                   * of blocked readers if all readers are
 224  219                                   * blocked.
 225  220                                   */
 226  221                                  if (rw->reader_count == rw->reader_blocked)
 227  222                                          all_readers_blocked = 1;
      223 +                        }
 228  224                  }
 229  225          }
 230  226  
 231  227          /* Wait for reader(s) or writer to finish */
 232  228          while (1) {
 233  229                  /*
 234  230                   * We can stop looping if one of the following holds:
 235  231                   *      - No readers, no writers
 236  232                   *      - No writers (or writer is myself), and one of:
 237  233                   *              - No readers
 238  234                   *              - One reader, and it's us
 239  235                   *              - N readers, but all blocked on the mutex
 240  236                   */
 241  237                  if (
 242      -                        (rw->writer_count == 0 && rw->reader_count == 0) ||
 243      -                        ((rw->writer_count == 0 || rw->writer.id == myself) &&
 244      -                                (rw->reader_count == 0) ||
 245      -                                (rw->reader_count == 1 &&
 246      -                                        rw->reader.id == myself))) {
      238 +                    (rw->writer_count == 0 && rw->reader_count == 0) ||
      239 +                    (((rw->writer_count == 0 || rw->writer.id == myself) &&
      240 +                    (rw->reader_count == 0)) ||
      241 +                    (rw->reader_count == 1 &&
      242 +                    rw->reader.id == myself))) {
 247  243                          break;
 248  244                  }
 249  245                  /*
 250  246                   * Provided that all readers are blocked on the mutex
 251  247                   * we break a potential dead-lock by acquiring the
 252  248                   * write lock.
 253  249                   */
 254  250                  if (all_readers_blocked) {
 255  251                          if (rw->writer_count == 0 || rw->writer.id == myself) {
 256  252                                  break;
↓ open down ↓ 384 lines elided ↑ open up ↑
 641  637          ret = mutex_unlock(&rw->mutex);
 642  638          return ((ret == 0) ? EBUSY : ret);
 643  639  }
 644  640  
 645  641  
 646  642  int
 647  643  __nisdb_destroy_lock(__nisdb_rwlock_t *rw) {
 648  644  
 649  645          int             ret;
 650  646          pthread_t       myself = pthread_self();
 651      -        __nisdb_rl_t    *rr;
 652  647  
 653  648  
 654  649          if (rw == 0) {
 655  650  #ifdef  NISDB_MT_DEBUG
 656  651                  abort();
 657  652  #endif  /* NISDB_MT_DEBUG */
 658  653                  return (EFAULT);
 659  654          }
 660  655  
 661  656          if (rw->destroyed != 0)
↓ open down ↓ 5 lines elided ↑ open up ↑
 667  662          if (rw->destroyed != 0) {
 668  663                  (void) mutex_unlock(&rw->mutex);
 669  664                  return (ESHUTDOWN);
 670  665          }
 671  666  
 672  667          /*
 673  668           * Only proceed if if there are neither readers nor writers
 674  669           * other than this thread. Also, no nested locks may be in
 675  670           * effect.
 676  671           */
 677      -        if ((rw->writer_count > 0 &&
 678      -                        (rw->writer.id != myself || rw->writer.count != 1) ||
 679      -                (rw->reader_count > 0 &&
 680      -                        !(rw->reader_count == 1 && rw->reader.id == myself &&
 681      -                                rw->reader.count == 1))) ||
 682      -                (rw->writer_count > 0 && rw->reader_count > 0)) {
      672 +        if (((rw->writer_count > 0 &&
      673 +            (rw->writer.id != myself || rw->writer.count != 1)) ||
      674 +            (rw->reader_count > 0 &&
      675 +            !(rw->reader_count == 1 && rw->reader.id == myself &&
      676 +            rw->reader.count == 1))) ||
      677 +            (rw->writer_count > 0 && rw->reader_count > 0)) {
 683  678  #ifdef  NISDB_MT_DEBUG
 684  679                  abort();
 685  680  #endif  /* NISDB_MT_DEBUG */
 686  681                  (void) mutex_unlock(&rw->mutex);
 687  682                  return (ENOLCK);
 688  683          }
 689  684  
 690  685          /*
 691  686           * Mark lock destroyed, so that any thread waiting on the mutex
 692  687           * will know what's what. Of course, this is a bit iffy, since
↓ open down ↓ 50 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX