1193
1187
in_data->type= new_lock_type;
1194
1188
check_locks(lock,"after downgrading lock",0);
1197
switch (old_lock_type)
1201
case TL_WRITE_LOW_PRIORITY:
1203
Previous lock was exclusive we are now ready to start up most waiting
1206
switch (new_lock_type)
1208
case TL_WRITE_ALLOW_READ:
1209
/* Still cannot start WRITE operations. Can only start readers. */
1210
start_readers= TRUE;
1213
case TL_WRITE_LOW_PRIORITY:
1215
Still cannot start anything, but new requests are no longer
1219
case TL_WRITE_ALLOW_WRITE:
1221
We can start both writers and readers.
1223
start_writers= TRUE;
1224
start_readers= TRUE;
1226
case TL_WRITE_CONCURRENT_INSERT:
1227
case TL_WRITE_DELAYED:
1229
This routine is not designed for those. Lock will be downgraded
1230
but no start of waiters will occur. This is not the optimal but
1231
should be a correct behaviour.
1238
case TL_WRITE_DELAYED:
1239
case TL_WRITE_CONCURRENT_INSERT:
1241
This routine is not designed for those. Lock will be downgraded
1242
but no start of waiters will occur. This is not the optimal but
1243
should be a correct behaviour.
1246
case TL_WRITE_ALLOW_READ:
1247
DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE);
1249
Previously writers were not allowed to start, now it is ok to
1250
start them again. Readers are already allowed so no reason to
1253
start_writers= TRUE;
1262
At this time the only active writer can be ourselves. Thus we need
1263
not worry about that there are other concurrent write operations
1264
active on the table. Thus we only need to worry about starting
1266
We also only come here with TL_WRITE_ALLOW_WRITE as the new
1267
lock type, thus we can start other writers also of the same type.
1268
If we find a lock at exclusive level >= TL_WRITE_LOW_PRIORITY we
1269
don't start any more operations that would be mean those operations
1270
will have to wait for things started afterwards.
1272
DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE);
1273
for (data=lock->write_wait.data; data ; data= next)
1276
All WRITE requests compatible with new lock type are also
1280
if (start_writers && data->type == new_lock_type)
1282
pthread_cond_t *cond= data->cond;
1284
It is ok to start this waiter.
1285
Move from being first in wait queue to be last in write queue.
1287
if (((*data->prev)= data->next))
1288
data->next->prev= data->prev;
1290
lock->write_wait.last= data->prev;
1291
data->prev= lock->write.last;
1292
lock->write.last= &data->next;
1294
check_locks(lock, "Started write lock after downgrade",0);
1296
pthread_cond_signal(cond);
1301
We found an incompatible lock, we won't start any more write
1302
requests to avoid letting writers pass other writers in the
1305
start_writers= FALSE;
1306
if (data->type >= TL_WRITE_LOW_PRIORITY)
1309
We have an exclusive writer in the queue so we won't start
1312
start_readers= FALSE;
1319
DBUG_ASSERT(new_lock_type == TL_WRITE_ALLOW_WRITE ||
1320
new_lock_type == TL_WRITE_ALLOW_READ);
1322
When we come here we know that the write locks are
1323
TL_WRITE_ALLOW_WRITE or TL_WRITE_ALLOW_READ. This means that reads
1326
for (data=lock->read_wait.data; data ; data=next)
1330
All reads are ok to start now except TL_READ_NO_INSERT when
1331
write lock is TL_WRITE_ALLOW_READ.
1333
if (new_lock_type != TL_WRITE_ALLOW_READ ||
1334
data->type != TL_READ_NO_INSERT)
1336
pthread_cond_t *cond= data->cond;
1337
if (((*data->prev)= data->next))
1338
data->next->prev= data->prev;
1340
lock->read_wait.last= data->prev;
1341
data->prev= lock->read.last;
1342
lock->read.last= &data->next;
1345
if (data->type == TL_READ_NO_INSERT)
1346
lock->read_no_write_count++;
1347
check_locks(lock, "Started read lock after downgrade",0);
1349
pthread_cond_signal(cond);
1353
check_locks(lock,"after starting waiters after downgrading lock",0);
1355
1190
pthread_mutex_unlock(&lock->mutex);
1356
1191
DBUG_VOID_RETURN;