1192
1187
in_data->type= new_lock_type;
1193
1188
check_locks(lock,"after downgrading lock",0);
1196
switch (old_lock_type)
1200
case TL_WRITE_LOW_PRIORITY:
1202
Previous lock was exclusive we are now ready to start up most waiting
1205
switch (new_lock_type)
1207
case TL_WRITE_ALLOW_READ:
1208
/* Still cannot start WRITE operations. Can only start readers. */
1209
start_readers= TRUE;
1212
case TL_WRITE_LOW_PRIORITY:
1214
Still cannot start anything, but new requests are no longer
1218
case TL_WRITE_ALLOW_WRITE:
1220
We can start both writers and readers.
1222
start_writers= TRUE;
1223
start_readers= TRUE;
1225
case TL_WRITE_CONCURRENT_INSERT:
1226
case TL_WRITE_DELAYED:
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.
1237
case TL_WRITE_DELAYED:
1238
case TL_WRITE_CONCURRENT_INSERT:
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.
1245
case TL_WRITE_ALLOW_READ:
1246
DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE);
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
1252
start_writers= TRUE;
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
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.
1271
DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE);
1272
for (data=lock->write_wait.data; data ; data= next)
1275
All WRITE requests compatible with new lock type are also
1279
if (start_writers && data->type == new_lock_type)
1281
pthread_cond_t *cond= data->cond;
1283
It is ok to start this waiter.
1284
Move from being first in wait queue to be last in write queue.
1286
if (((*data->prev)= data->next))
1287
data->next->prev= data->prev;
1289
lock->write_wait.last= data->prev;
1290
data->prev= lock->write.last;
1291
lock->write.last= &data->next;
1293
check_locks(lock, "Started write lock after downgrade",0);
1295
pthread_cond_signal(cond);
1300
We found an incompatible lock, we won't start any more write
1301
requests to avoid letting writers pass other writers in the
1304
start_writers= FALSE;
1305
if (data->type >= TL_WRITE_LOW_PRIORITY)
1308
We have an exclusive writer in the queue so we won't start
1311
start_readers= FALSE;
1318
DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE ||
1319
new_lock_type == TL_WRITE_ALLOW_READ);
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
1325
for (data=lock->read_wait.data; data ; data=next)
1329
All reads are ok to start now except TL_READ_NO_INSERT when
1330
write lock is TL_WRITE_ALLOW_READ.
1332
if (new_lock_type != TL_WRITE_ALLOW_READ ||
1333
data->type != TL_READ_NO_INSERT)
1335
pthread_cond_t *cond= data->cond;
1336
if (((*data->prev)= data->next))
1337
data->next->prev= data->prev;
1339
lock->read_wait.last= data->prev;
1340
data->prev= lock->read.last;
1341
lock->read.last= &data->next;
1344
if (data->type == TL_READ_NO_INSERT)
1345
lock->read_no_write_count++;
1346
check_locks(lock, "Started read lock after downgrade",0);
1348
pthread_cond_signal(cond);
1352
check_locks(lock,"after starting waiters after downgrading lock",0);
1354
1190
pthread_mutex_unlock(&lock->mutex);
1355
1191
DBUG_VOID_RETURN;