~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/thr_lock.c

  • Committer: Monty Taylor
  • Date: 2008-07-02 14:48:53 UTC
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: monty@inaugust.com-20080702144853-itrmls4ae3h07lbr
Removed everything marked TO_BE_REMOVED.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1179
1179
#ifndef DBUG_OFF
1180
1180
  enum thr_lock_type old_lock_type= in_data->type;
1181
1181
#endif
1182
 
#ifdef TO_BE_REMOVED
1183
 
  THR_LOCK_DATA *data, *next;
1184
 
  bool start_writers= FALSE;
1185
 
  bool start_readers= FALSE;
1186
 
#endif
1187
1182
  DBUG_ENTER("thr_downgrade_write_only_lock");
1188
1183
 
1189
1184
  pthread_mutex_lock(&lock->mutex);
1192
1187
  in_data->type= new_lock_type;
1193
1188
  check_locks(lock,"after downgrading lock",0);
1194
1189
 
1195
 
#if TO_BE_REMOVED
1196
 
  switch (old_lock_type)
1197
 
  {
1198
 
    case TL_WRITE_ONLY:
1199
 
    case TL_WRITE:
1200
 
    case TL_WRITE_LOW_PRIORITY:
1201
 
    /*
1202
 
      Previous lock was exclusive we are now ready to start up most waiting
1203
 
      threads.
1204
 
    */
1205
 
      switch (new_lock_type)
1206
 
      {
1207
 
        case TL_WRITE_ALLOW_READ:
1208
 
        /* Still cannot start WRITE operations. Can only start readers.  */
1209
 
          start_readers= TRUE;
1210
 
          break;
1211
 
        case TL_WRITE:
1212
 
        case TL_WRITE_LOW_PRIORITY:
1213
 
        /*
1214
 
           Still cannot start anything, but new requests are no longer
1215
 
           aborted.
1216
 
        */
1217
 
          break;
1218
 
        case TL_WRITE_ALLOW_WRITE:
1219
 
        /*
1220
 
          We can start both writers and readers.
1221
 
        */
1222
 
          start_writers= TRUE;
1223
 
          start_readers= TRUE;
1224
 
          break;
1225
 
        case TL_WRITE_CONCURRENT_INSERT:
1226
 
        case TL_WRITE_DELAYED:
1227
 
        /*
1228
 
          This routine is not designed for those. Lock will be downgraded
1229
 
          but no start of waiters will occur. This is not the optimal but
1230
 
          should be a correct behaviour.
1231
 
        */
1232
 
          break;
1233
 
        default:
1234
 
          DBUG_ASSERT(0);
1235
 
      }
1236
 
      break;
1237
 
    case TL_WRITE_DELAYED:
1238
 
    case TL_WRITE_CONCURRENT_INSERT:
1239
 
    /*
1240
 
      This routine is not designed for those. Lock will be downgraded
1241
 
      but no start of waiters will occur. This is not the optimal but
1242
 
      should be a correct behaviour.
1243
 
    */
1244
 
      break;
1245
 
    case TL_WRITE_ALLOW_READ:
1246
 
      DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE);
1247
 
      /*
1248
 
        Previously writers were not allowed to start, now it is ok to
1249
 
        start them again. Readers are already allowed so no reason to
1250
 
        handle them.
1251
 
      */
1252
 
      start_writers= TRUE;
1253
 
      break;
1254
 
    default:
1255
 
      DBUG_ASSERT(0);
1256
 
      break;
1257
 
  }
1258
 
  if (start_writers)
1259
 
  {
1260
 
    /*
1261
 
      At this time the only active writer can be ourselves. Thus we need
1262
 
      not worry about that there are other concurrent write operations
1263
 
      active on the table. Thus we only need to worry about starting
1264
 
      waiting operations.
1265
 
      We also only come here with TL_WRITE_ALLOW_WRITE as the new
1266
 
      lock type, thus we can start other writers also of the same type.
1267
 
      If we find a lock at exclusive level >= TL_WRITE_LOW_PRIORITY we
1268
 
      don't start any more operations that would be mean those operations
1269
 
      will have to wait for things started afterwards.
1270
 
    */
1271
 
    DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE);
1272
 
    for (data=lock->write_wait.data; data ; data= next)
1273
 
    {
1274
 
      /*
1275
 
        All WRITE requests compatible with new lock type are also
1276
 
        started
1277
 
      */
1278
 
      next= data->next;
1279
 
      if (start_writers && data->type == new_lock_type)
1280
 
      {
1281
 
        pthread_cond_t *cond= data->cond;
1282
 
        /*
1283
 
          It is ok to start this waiter.
1284
 
          Move from being first in wait queue to be last in write queue.
1285
 
        */
1286
 
        if (((*data->prev)= data->next))
1287
 
          data->next->prev= data->prev;
1288
 
        else
1289
 
          lock->write_wait.last= data->prev;
1290
 
        data->prev= lock->write.last;
1291
 
        lock->write.last= &data->next;
1292
 
        data->next= 0;
1293
 
        check_locks(lock, "Started write lock after downgrade",0);
1294
 
        data->cond= 0;
1295
 
        pthread_cond_signal(cond);
1296
 
      }
1297
 
      else
1298
 
      {
1299
 
        /*
1300
 
          We found an incompatible lock, we won't start any more write
1301
 
          requests to avoid letting writers pass other writers in the
1302
 
          queue.
1303
 
        */
1304
 
        start_writers= FALSE;
1305
 
        if (data->type >= TL_WRITE_LOW_PRIORITY)
1306
 
        {
1307
 
          /*
1308
 
            We have an exclusive writer in the queue so we won't start
1309
 
            readers either.
1310
 
          */
1311
 
          start_readers= FALSE;
1312
 
        }
1313
 
      }
1314
 
    }
1315
 
  }
1316
 
  if (start_readers)
1317
 
  {
1318
 
    DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE ||
1319
 
                new_lock_type == TL_WRITE_ALLOW_READ);
1320
 
    /*
1321
 
      When we come here we know that the write locks are
1322
 
      TL_WRITE_ALLOW_WRITE or TL_WRITE_ALLOW_READ. This means that reads
1323
 
      are ok
1324
 
    */
1325
 
    for (data=lock->read_wait.data; data ; data=next)
1326
 
    {
1327
 
      next= data->next;
1328
 
      /*
1329
 
        All reads are ok to start now except TL_READ_NO_INSERT when
1330
 
        write lock is TL_WRITE_ALLOW_READ.
1331
 
      */
1332
 
      if (new_lock_type != TL_WRITE_ALLOW_READ ||
1333
 
          data->type != TL_READ_NO_INSERT)
1334
 
      {
1335
 
        pthread_cond_t *cond= data->cond;
1336
 
        if (((*data->prev)= data->next))
1337
 
          data->next->prev= data->prev;
1338
 
        else
1339
 
          lock->read_wait.last= data->prev;
1340
 
        data->prev= lock->read.last;
1341
 
        lock->read.last= &data->next;
1342
 
        data->next= 0;
1343
 
 
1344
 
        if (data->type == TL_READ_NO_INSERT)
1345
 
          lock->read_no_write_count++;
1346
 
        check_locks(lock, "Started read lock after downgrade",0);
1347
 
        data->cond= 0;
1348
 
        pthread_cond_signal(cond);
1349
 
      }
1350
 
    }
1351
 
  }
1352
 
  check_locks(lock,"after starting waiters after downgrading lock",0);
1353
 
#endif
1354
1190
  pthread_mutex_unlock(&lock->mutex);
1355
1191
  DBUG_VOID_RETURN;
1356
1192
}