summaryrefslogtreecommitdiffstats
path: root/gl/glthread/lock.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2026-03-26 12:53:53 +0100
committerGitHub <noreply@github.com>2026-03-26 12:53:53 +0100
commit13e14a6bfd9f29cbfeab0c5161d2a994f97532e7 (patch)
tree3aa7186fe092e42783dc7e981dc39a74ea61c466 /gl/glthread/lock.c
parent9d8503f90ef25b2cecd324dc118e441f40233ea8 (diff)
downloadmonitoring-plugins-13e14a6bfd9f29cbfeab0c5161d2a994f97532e7.tar.gz
Update/gnulib 2026 03 (#2247)
* Sync with the 202601-stable Gnulib code (4a3650d887) * Ignore more deps stuff in gnulib * Remove autogenerated gnulib files * Ignore more gnulib generated headers
Diffstat (limited to 'gl/glthread/lock.c')
-rw-r--r--gl/glthread/lock.c68
1 files changed, 18 insertions, 50 deletions
diff --git a/gl/glthread/lock.c b/gl/glthread/lock.c
index dace4fda..cfb9393c 100644
--- a/gl/glthread/lock.c
+++ b/gl/glthread/lock.c
@@ -1,5 +1,5 @@
1/* Locking in multithreaded situations. 1/* Locking in multithreaded situations.
2 Copyright (C) 2005-2025 Free Software Foundation, Inc. 2 Copyright (C) 2005-2026 Free Software Foundation, Inc.
3 3
4 This file is free software: you can redistribute it and/or modify 4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as 5 it under the terms of the GNU Lesser General Public License as
@@ -255,15 +255,13 @@ glthread_recursive_lock_destroy (gl_recursive_lock_t *lock)
255# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP 255# if defined PTHREAD_RWLOCK_INITIALIZER || defined PTHREAD_RWLOCK_INITIALIZER_NP
256 256
257# if !HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER 257# if !HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER
258 /* glibc with bug https://sourceware.org/bugzilla/show_bug.cgi?id=13701 */ 258 /* glibc with bug https://sourceware.org/PR13701 */
259 259
260int 260int
261glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock) 261glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock)
262{ 262{
263 pthread_rwlockattr_t attributes; 263 pthread_rwlockattr_t attributes;
264 int err; 264 int err = pthread_rwlockattr_init (&attributes);
265
266 err = pthread_rwlockattr_init (&attributes);
267 if (err != 0) 265 if (err != 0)
268 return err; 266 return err;
269 /* Note: PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP is the only value that 267 /* Note: PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP is the only value that
@@ -286,9 +284,7 @@ glthread_rwlock_init_for_glibc (pthread_rwlock_t *lock)
286int 284int
287glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) 285glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
288{ 286{
289 int err; 287 int err = pthread_rwlock_init (&lock->rwlock, NULL);
290
291 err = pthread_rwlock_init (&lock->rwlock, NULL);
292 if (err != 0) 288 if (err != 0)
293 return err; 289 return err;
294 lock->initialized = 1; 290 lock->initialized = 1;
@@ -300,9 +296,7 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
300{ 296{
301 if (!lock->initialized) 297 if (!lock->initialized)
302 { 298 {
303 int err; 299 int err = pthread_mutex_lock (&lock->guard);
304
305 err = pthread_mutex_lock (&lock->guard);
306 if (err != 0) 300 if (err != 0)
307 return err; 301 return err;
308 if (!lock->initialized) 302 if (!lock->initialized)
@@ -326,9 +320,7 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
326{ 320{
327 if (!lock->initialized) 321 if (!lock->initialized)
328 { 322 {
329 int err; 323 int err = pthread_mutex_lock (&lock->guard);
330
331 err = pthread_mutex_lock (&lock->guard);
332 if (err != 0) 324 if (err != 0)
333 return err; 325 return err;
334 if (!lock->initialized) 326 if (!lock->initialized)
@@ -358,11 +350,9 @@ glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
358int 350int
359glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) 351glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
360{ 352{
361 int err;
362
363 if (!lock->initialized) 353 if (!lock->initialized)
364 return EINVAL; 354 return EINVAL;
365 err = pthread_rwlock_destroy (&lock->rwlock); 355 int err = pthread_rwlock_destroy (&lock->rwlock);
366 if (err != 0) 356 if (err != 0)
367 return err; 357 return err;
368 lock->initialized = 0; 358 lock->initialized = 0;
@@ -376,9 +366,7 @@ glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
376int 366int
377glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) 367glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
378{ 368{
379 int err; 369 int err = pthread_mutex_init (&lock->lock, NULL);
380
381 err = pthread_mutex_init (&lock->lock, NULL);
382 if (err != 0) 370 if (err != 0)
383 return err; 371 return err;
384 err = pthread_cond_init (&lock->waiting_readers, NULL); 372 err = pthread_cond_init (&lock->waiting_readers, NULL);
@@ -395,9 +383,7 @@ glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
395int 383int
396glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) 384glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
397{ 385{
398 int err; 386 int err = pthread_mutex_lock (&lock->lock);
399
400 err = pthread_mutex_lock (&lock->lock);
401 if (err != 0) 387 if (err != 0)
402 return err; 388 return err;
403 /* Test whether only readers are currently running, and whether the runcount 389 /* Test whether only readers are currently running, and whether the runcount
@@ -422,9 +408,7 @@ glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
422int 408int
423glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) 409glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
424{ 410{
425 int err; 411 int err = pthread_mutex_lock (&lock->lock);
426
427 err = pthread_mutex_lock (&lock->lock);
428 if (err != 0) 412 if (err != 0)
429 return err; 413 return err;
430 /* Test whether no readers or writers are currently running. */ 414 /* Test whether no readers or writers are currently running. */
@@ -449,9 +433,7 @@ glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
449int 433int
450glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) 434glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
451{ 435{
452 int err; 436 int err = pthread_mutex_lock (&lock->lock);
453
454 err = pthread_mutex_lock (&lock->lock);
455 if (err != 0) 437 if (err != 0)
456 return err; 438 return err;
457 if (lock->runcount < 0) 439 if (lock->runcount < 0)
@@ -505,9 +487,7 @@ glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
505int 487int
506glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) 488glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
507{ 489{
508 int err; 490 int err = pthread_mutex_destroy (&lock->lock);
509
510 err = pthread_mutex_destroy (&lock->lock);
511 if (err != 0) 491 if (err != 0)
512 return err; 492 return err;
513 err = pthread_cond_destroy (&lock->waiting_readers); 493 err = pthread_cond_destroy (&lock->waiting_readers);
@@ -531,9 +511,7 @@ int
531glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) 511glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
532{ 512{
533 pthread_mutexattr_t attributes; 513 pthread_mutexattr_t attributes;
534 int err; 514 int err = pthread_mutexattr_init (&attributes);
535
536 err = pthread_mutexattr_init (&attributes);
537 if (err != 0) 515 if (err != 0)
538 return err; 516 return err;
539 err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); 517 err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
@@ -560,9 +538,7 @@ int
560glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) 538glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
561{ 539{
562 pthread_mutexattr_t attributes; 540 pthread_mutexattr_t attributes;
563 int err; 541 int err = pthread_mutexattr_init (&attributes);
564
565 err = pthread_mutexattr_init (&attributes);
566 if (err != 0) 542 if (err != 0)
567 return err; 543 return err;
568 err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); 544 err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
@@ -589,9 +565,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
589{ 565{
590 if (!lock->initialized) 566 if (!lock->initialized)
591 { 567 {
592 int err; 568 int err = pthread_mutex_lock (&lock->guard);
593
594 err = pthread_mutex_lock (&lock->guard);
595 if (err != 0) 569 if (err != 0)
596 return err; 570 return err;
597 if (!lock->initialized) 571 if (!lock->initialized)
@@ -621,11 +595,9 @@ glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
621int 595int
622glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) 596glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
623{ 597{
624 int err;
625
626 if (!lock->initialized) 598 if (!lock->initialized)
627 return EINVAL; 599 return EINVAL;
628 err = pthread_mutex_destroy (&lock->recmutex); 600 int err = pthread_mutex_destroy (&lock->recmutex);
629 if (err != 0) 601 if (err != 0)
630 return err; 602 return err;
631 lock->initialized = 0; 603 lock->initialized = 0;
@@ -639,9 +611,7 @@ glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
639int 611int
640glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) 612glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
641{ 613{
642 int err; 614 int err = pthread_mutex_init (&lock->mutex, NULL);
643
644 err = pthread_mutex_init (&lock->mutex, NULL);
645 if (err != 0) 615 if (err != 0)
646 return err; 616 return err;
647 lock->owner = (pthread_t) 0; 617 lock->owner = (pthread_t) 0;
@@ -655,9 +625,7 @@ glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
655 pthread_t self = pthread_self (); 625 pthread_t self = pthread_self ();
656 if (lock->owner != self) 626 if (lock->owner != self)
657 { 627 {
658 int err; 628 int err = pthread_mutex_lock (&lock->mutex);
659
660 err = pthread_mutex_lock (&lock->mutex);
661 if (err != 0) 629 if (err != 0)
662 return err; 630 return err;
663 lock->owner = self; 631 lock->owner = self;