Reviewed By: jvillard Differential Revision: D4818713 fbshipit-source-id: eb11909master
parent
c10d2ed32d
commit
491cc2587b
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
int normal_life_ok(pthread_mutex_t* m) {
|
||||||
|
if (pthread_mutex_init(m, 0))
|
||||||
|
return 0;
|
||||||
|
if (pthread_mutex_lock(m))
|
||||||
|
return 0;
|
||||||
|
if (pthread_mutex_unlock(m))
|
||||||
|
return 0;
|
||||||
|
if (pthread_mutex_destroy(m))
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int normal_ok2() {
|
||||||
|
pthread_mutex_t m;
|
||||||
|
normal_life_ok(&m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FN_double_lock_bad(pthread_mutex_t* m) {
|
||||||
|
pthread_mutex_lock(m);
|
||||||
|
pthread_mutex_lock(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void double_lock_uninit_bad() {
|
||||||
|
pthread_mutex_t m;
|
||||||
|
FN_double_lock_bad(&m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void double_lock_bad2() {
|
||||||
|
pthread_mutex_t m;
|
||||||
|
pthread_mutex_init(&m, 0);
|
||||||
|
FN_double_lock_bad(&m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void double_unlock_bad(pthread_mutex_t* m) {
|
||||||
|
pthread_mutex_unlock(m);
|
||||||
|
pthread_mutex_unlock(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void double_unlock_bad2() {
|
||||||
|
pthread_mutex_t m;
|
||||||
|
pthread_mutex_init(&m, 0);
|
||||||
|
pthread_mutex_lock(&m);
|
||||||
|
double_unlock_bad(&m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void double_init_bad(pthread_mutex_t* m) {
|
||||||
|
pthread_mutex_init(m, 0);
|
||||||
|
pthread_mutex_init(m, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Already reported in double_init_bad
|
||||||
|
void double_init_ok() {
|
||||||
|
pthread_mutex_t m;
|
||||||
|
double_init_bad(&m);
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// Spinlocks do not exist on mac
|
||||||
|
typedef struct {
|
||||||
|
int __whatever;
|
||||||
|
} pthread_spinlock_t;
|
||||||
|
extern int pthread_spin_init(pthread_spinlock_t *__lock, int __pshared);
|
||||||
|
extern int pthread_spin_destroy (pthread_spinlock_t *__lock);
|
||||||
|
extern int pthread_spin_lock (pthread_spinlock_t *__lock);
|
||||||
|
extern int pthread_spin_trylock (pthread_spinlock_t *__lock);
|
||||||
|
extern int pthread_spin_unlock (pthread_spinlock_t *__lock);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void spinlock_double_lock_bad(pthread_spinlock_t* m) {
|
||||||
|
pthread_spin_lock(m);
|
||||||
|
pthread_spin_lock(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
void spinlock_double_lock_bad2() {
|
||||||
|
pthread_spinlock_t m;
|
||||||
|
spinlock_double_lock_bad(&m);
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 - present Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
void alarm1(std::timed_mutex& m) {
|
||||||
|
m.lock();
|
||||||
|
m.lock();
|
||||||
|
}
|
Loading…
Reference in new issue