| Index: src/untrusted/init/auto_lock.h
|
| diff --git a/src/untrusted/init/auto_lock.h b/src/untrusted/init/auto_lock.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4d38395804a699e9eb88d3ce0a8ce4aed67cfcb6
|
| --- /dev/null
|
| +++ b/src/untrusted/init/auto_lock.h
|
| @@ -0,0 +1,43 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef NATIVE_CLIENT_SRC_UNTRUSTED_INIT_AUTO_LOCK_H_
|
| +#define NATIVE_CLIENT_SRC_UNTRUSTED_INIT_AUTO_LOCK_H_
|
| +
|
| +#include <pthread.h>
|
| +#include "sdk_util/macros.h"
|
| +#include "sdk_util/simple_lock.h"
|
| +
|
| +namespace nacl {
|
| +
|
| +// This macro is provided to allow us to quickly instrument locking for
|
| +// debugging purposes.
|
| +#define AUTO_LOCK(lock) \
|
| + ::nacl::AutoLock Lock##__LINE__(lock);
|
| +
|
| +class AutoLock {
|
| + public:
|
| + AutoLock(const SimpleLock& lock) {
|
| + lock_ = lock.mutex();
|
| + pthread_mutex_lock(lock_);
|
| + }
|
| +
|
| + ~AutoLock() {
|
| + Unlock();
|
| + }
|
| +
|
| + void Unlock() {
|
| + if (lock_) pthread_mutex_unlock(lock_);
|
| + lock_ = NULL;
|
| + }
|
| +
|
| + private:
|
| + pthread_mutex_t* lock_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AutoLock);
|
| +};
|
| +
|
| +} // namespace nacl
|
| +
|
| +#endif
|
|
|