Mercurial > hg > orthanc-databases
comparison Framework/PostgreSQL/PostgreSQLDatabase.cpp @ 418:a7f0f27fe33c pg-transactions
wip: advisory lock around CreateInstance: not ok see WO-139
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 27 Jun 2023 15:17:39 +0200 |
parents | 3d6886f3e5b3 |
children | dbf811b1bb43 |
comparison
equal
deleted
inserted
replaced
417:15bfd9a76f8d | 418:a7f0f27fe33c |
---|---|
316 } | 316 } |
317 | 317 |
318 | 318 |
319 PostgreSQLDatabase::TransientAdvisoryLock::TransientAdvisoryLock( | 319 PostgreSQLDatabase::TransientAdvisoryLock::TransientAdvisoryLock( |
320 PostgreSQLDatabase& database, | 320 PostgreSQLDatabase& database, |
321 int32_t lock) : | 321 int32_t lock, |
322 unsigned int retries, | |
323 unsigned int retryInterval) : | |
322 database_(database), | 324 database_(database), |
323 lock_(lock) | 325 lock_(lock) |
324 { | 326 { |
325 bool locked = true; | 327 bool locked = true; |
326 | 328 |
327 for (unsigned int i = 0; i < 10; i++) | 329 for (unsigned int i = 0; i < retries; i++) |
328 { | 330 { |
329 if (database_.AcquireAdvisoryLock(lock_)) | 331 if (database_.AcquireAdvisoryLock(lock_)) |
330 { | 332 { |
331 locked = false; | 333 locked = false; |
332 break; | 334 break; |
333 } | 335 } |
334 else | 336 else |
335 { | 337 { |
336 boost::this_thread::sleep(boost::posix_time::milliseconds(500)); | 338 boost::this_thread::sleep(boost::posix_time::milliseconds(retryInterval)); |
337 } | 339 } |
338 } | 340 } |
339 | 341 |
340 if (locked) | 342 if (locked) |
341 { | 343 { |