blob: 70f85f9a68e6dafd38bb7850e2c028ad9854f882 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +000011// General note: return values for the various pthread synchronization APIs
12// are explicitly ignored here. In Chromium, the same thing is done for release.
13// However, in debugging, failure in these APIs are logged. There is currently
14// no equivalent to DCHECK_EQ in WebRTC code so this is the best we can do here.
15// TODO(henrike): add logging when pthread synchronization APIs are failing.
16
ajm@google.comb5c49ff2011-08-01 17:04:04 +000017#include "critical_section_posix.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000018
19namespace webrtc {
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +000020
ajm@google.comb5c49ff2011-08-01 17:04:04 +000021CriticalSectionPosix::CriticalSectionPosix()
niklase@google.com470e71d2011-07-07 08:21:25 +000022{
23 pthread_mutexattr_t attr;
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +000024 (void) pthread_mutexattr_init(&attr);
25 (void) pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
26 (void) pthread_mutex_init(&_mutex, &attr);
niklase@google.com470e71d2011-07-07 08:21:25 +000027}
28
ajm@google.comb5c49ff2011-08-01 17:04:04 +000029CriticalSectionPosix::~CriticalSectionPosix()
niklase@google.com470e71d2011-07-07 08:21:25 +000030{
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +000031 (void) pthread_mutex_destroy(&_mutex);
niklase@google.com470e71d2011-07-07 08:21:25 +000032}
33
34void
ajm@google.comb5c49ff2011-08-01 17:04:04 +000035CriticalSectionPosix::Enter()
niklase@google.com470e71d2011-07-07 08:21:25 +000036{
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +000037 (void) pthread_mutex_lock(&_mutex);
niklase@google.com470e71d2011-07-07 08:21:25 +000038}
39
40void
ajm@google.comb5c49ff2011-08-01 17:04:04 +000041CriticalSectionPosix::Leave()
niklase@google.com470e71d2011-07-07 08:21:25 +000042{
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +000043 (void) pthread_mutex_unlock(&_mutex);
niklase@google.com470e71d2011-07-07 08:21:25 +000044}
henrike@webrtc.orgf3760dc2012-02-17 16:27:25 +000045
niklase@google.com470e71d2011-07-07 08:21:25 +000046} // namespace webrtc