Partly reverts c9e761649, which removed the synchronizatiion of
credential requests (eg. in a project that has multiple layers from the
same postgresql database without credentials) and led to multiple
concurrent requests for the same credentials.
Some of which were silently discarded, when events processed in the
dialogs exec() event loop tried to reinvoke the dialog and caused
invalid layers.
Authentications caused by network requests can still cause this.
The credential cache is now guarded by a separate mutex.
Remove responsibility for credentials mutex locking from external
callers and handle appropriate locks internally. This allows the
mutex lock to be much "tighter" and avoids deadlocks when
credentials are requested while an existing credentials dialog
is being shown.
(No mutex is required protecting the credentials dialog itself
as this is ALWAYS shown in the main thread)
Fixes#20826