support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 3c8a3f259b
641 changed files with 10349 additions and 9523 deletions

View File

@@ -7,40 +7,39 @@ using namespace std;
#include <mutex>
#define barrier() __asm__ volatile ("lwsync")
#define barrier() __asm__ volatile("lwsync")
// method 1 operator new + placement new
//singleton *instance() {
// singleton *instance() {
// if (p == nullptr) {
// lock_guard<mutex> guard(lock_);
// if (p == nullptr) {
// singleton *tmp = static_cast<singleton *>(operator new(sizeof(singleton)));
// new(p)singleton();
// p = tmp;
// singleton *tmp = static_cast<singleton *>(operator
// new(sizeof(singleton))); new(p)singleton(); p = tmp;
// }
// }
// return p;
//}
class singleton {
private:
singleton() {}
singleton() {}
static singleton *p;
static mutex lock_;
static singleton *p;
static mutex lock_;
public:
static singleton *instance();
static singleton *instance();
};
singleton *singleton::p = nullptr;
singleton *singleton::instance() {
if (p == nullptr) {
lock_guard<mutex> guard(lock_);
barrier();
if (p == nullptr) {
lock_guard<mutex> guard(lock_);
barrier();
if (p == nullptr) {
p = new singleton();
}
p = new singleton();
}
return p;
}
return p;
}