1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
6 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
9 #include "sdk_util/macros.h"
16 * A pthread mutex object, with automatic initialization and destruction.
17 * Should be used with AutoLock where possible.
22 pthread_mutex_init(&lock_
, NULL
);
26 pthread_mutex_destroy(&lock_
);
29 void Lock() const { pthread_mutex_lock(&lock_
); }
30 void Unlock() const { pthread_mutex_unlock(&lock_
); }
32 pthread_mutex_t
* mutex() const { return &lock_
; }
35 mutable pthread_mutex_t lock_
;
37 DISALLOW_COPY_AND_ASSIGN(SimpleLock
);
40 } // namespace sdk_util
42 #endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_