Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/media/libcubeb/src/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 1 kB image not shown  

Quelle  cubeb_utils_unix.h   Sprache: C

 
/*
 * Copyright © 2016 Mozilla Foundation
 *
 * This program is made available under an ISC-style license.  See the
 * accompanying file LICENSE for details.
 */


#if !defined(CUBEB_UTILS_UNIX)
#define CUBEB_UTILS_UNIX

#include <errno.h>
#include <pthread.h>
#include <stdio.h>

/* This wraps a critical section to track the owner in debug mode. */
class owned_critical_section {
public:
  owned_critical_section()
  {
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
#ifndef NDEBUG
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK);
#else
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
#endif

#ifndef NDEBUG
    int r =
#endif
        pthread_mutex_init(&mutex, &attr);
#ifndef NDEBUG
    assert(r == 0);
#endif

    pthread_mutexattr_destroy(&attr);
  }

  ~owned_critical_section()
  {
#ifndef NDEBUG
    int r =
#endif
        pthread_mutex_destroy(&mutex);
#ifndef NDEBUG
    assert(r == 0);
#endif
  }

  void lock()
  {
#ifndef NDEBUG
    int r =
#endif
        pthread_mutex_lock(&mutex);
#ifndef NDEBUG
    assert(r == 0 && "Deadlock");
#endif
  }

  void unlock()
  {
#ifndef NDEBUG
    int r =
#endif
        pthread_mutex_unlock(&mutex);
#ifndef NDEBUG
    assert(r == 0 && "Unlocking unlocked mutex");
#endif
  }

  void assert_current_thread_owns()
  {
#ifndef NDEBUG
    int r = pthread_mutex_lock(&mutex);
    assert(r == EDEADLK);
#endif
  }

private:
  pthread_mutex_t mutex;

  // Disallow copy and assignment because pthread_mutex_t cannot be copied.
  owned_critical_section(const owned_critical_section &);
  owned_critical_section & operator=(const owned_critical_section &);
};

#endif /* CUBEB_UTILS_UNIX */

Messung V0.5
C=98 H=94 G=95

¤ Dauer der Verarbeitung: 0.8 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.