第三方框架改为仓内子集并完善构建忽略规则
完整 NIM_Duilib_Framework 仓库移至父目录,third_party 仅保留实际使用的 base、duilib、bin/resources 与许可证;.gitignore 覆盖 MSBuild 与打包产物。
This commit is contained in:
1 parent
249e8548de
commit
e1e26acc49
391 files changed
+342850
No files matched your search
@@ -0,0 +1,93 @@
|
||||
// Lock implementation and Auto lock implementation
|
||||
|
||||
#ifndef BASE_SYNCHRONIZATION_LOCK_H
|
||||
#define BASE_SYNCHRONIZATION_LOCK_H
|
||||
|
||||
#include "base/base_export.h"
|
||||
#include "base/base_config.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
#include <windows.h>
|
||||
#elif defined(OS_POSIX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
namespace nbase
|
||||
{
|
||||
|
||||
class BASE_EXPORT NLock
|
||||
{
|
||||
public:
|
||||
#if defined(OS_WIN)
|
||||
typedef CRITICAL_SECTION OSLockType;
|
||||
#elif defined(OS_POSIX)
|
||||
typedef pthread_mutex_t OSLockType;
|
||||
#endif
|
||||
|
||||
NLock();
|
||||
~NLock();
|
||||
|
||||
// If the lock is not held, take it and return true. If the lock is already
|
||||
// held by something else, immediately return false.
|
||||
bool Try();
|
||||
|
||||
// Take the lock, blocking until it is available if necessary.
|
||||
void Lock();
|
||||
|
||||
// Release the lock. This must only be called by the lock's holder: after
|
||||
// a successful call to Try, or a call to Lock.
|
||||
void Unlock();
|
||||
|
||||
// Return the native underlying lock. Not supported for Windows builds.
|
||||
#if !defined(OS_WIN)
|
||||
OSLockType* os_lock() { return &os_lock_; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
OSLockType os_lock_;
|
||||
};
|
||||
|
||||
class BASE_EXPORT NAutoLock
|
||||
{
|
||||
public:
|
||||
NAutoLock(NLock * lock)
|
||||
{
|
||||
assert(lock);
|
||||
lock_ = lock;
|
||||
lock_->Lock();
|
||||
}
|
||||
|
||||
~NAutoLock()
|
||||
{
|
||||
if (lock_)
|
||||
lock_->Unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
NLock *lock_;
|
||||
};
|
||||
|
||||
class BASE_EXPORT NAutoUnlock
|
||||
{
|
||||
public:
|
||||
NAutoUnlock(NLock * lock)
|
||||
{
|
||||
assert(lock);
|
||||
lock_ = lock;
|
||||
lock_->Unlock();
|
||||
}
|
||||
|
||||
~NAutoUnlock()
|
||||
{
|
||||
if (lock_)
|
||||
lock_->Lock();
|
||||
}
|
||||
|
||||
private:
|
||||
NLock *lock_;
|
||||
};
|
||||
|
||||
} // namespace nbase
|
||||
|
||||
#endif // BASE_SYNCHRONIZATION_LOCK_H
|
||||
Reference in new issue
Block a user