20101119
来源:互联网 发布:青银金融租赁 知乎 编辑:程序博客网 时间:2024/05/16 18:24
template<class T>
class ThreadSafe_U
{
public:
ThreadSafe_U(){
cnt = 0;
InitializeCriticalSection(&cs);
mp = (T)NULL;
}
~ThreadSafe_U(){
Lock();
DeleteCriticalSection(&cs);
}
public:
inline void Lock(){
EnterCriticalSection(&cs);
cnt++;
//printf("/nU lock~ %d/n", cnt);
}
inline BOOL tryLock(){
if(TryEnterCriticalSection(&cs)){
cnt++;
return TRUE;
}
return FALSE;
}
inline void Unlock(){
LeaveCriticalSection(&cs);
cnt--;
if(cnt<=0)cnt=0;
}
T getVal(){
T p;
Lock(); p = mp; Unlock();
return p;
}
T setVal(T pSet){
T p;
Lock(); p = mp = pSet; Unlock();
return p;
}
private:
T mp;
CRITICAL_SECTION cs;
int cnt;
};
#include "tools.h"
static inline void Loginfo_uu(const TCHAR* tszLogfilename, const TCHAR* tszFormat, ...)
{
va_list va;
TCHAR *pTsz;
TCHAR tszInfo[1024];
TCHAR tszFilepath[MAX_PATH];
tcscpy(tszFilepath, _T("//storage card//"));
tcscat(tszFilepath, tszLogfilename);
HANDLE hFile = CreateFile(tszFilepath, GENERIC_READ|GENERIC_WRITE,// Access (read-write) mode
0, // Share mode
NULL, // Pointer to the security attribute
OPEN_ALWAYS,// How to open the
0, // Port attributes
NULL); // Handle to port with attribute to copy
if(ISVALIDHANDLE(hFile))
{
SYSTEMTIME systime;
GetLocalTime(&systime);
tcsprintf(tszInfo, _T("[%d/%d/%d %d:%d:%d]:"), systime.wYear, systime.wMonth, systime.wDay,
systime.wHour, systime.wMinute, systime.wSecond);
pTsz = tszInfo+ tcslen(tszInfo);
if(pTsz)
{
va_start(va, tszFormat);
_vstprintf(pTsz, tszFormat, va);
va_end(va);
}
tcscat(tszInfo, L"/r/n");
SetFilePointer(hFile, 0, 0, FILE_END);
DWORD dwWrited = tcslen(tszInfo)*sizeof(TCHAR);
WriteFile(hFile, tszInfo, tcslen(tszInfo)*sizeof(TCHAR), &dwWrited, NULL);
SetEndOfFile(hFile);
CloseHandle(hFile);
hFile =0;
}//else
// printf("Log Error Code %d/n", GetLastError());
}
- 20101119
- Linux 两台机器互拷文件
- 在线好几个iphone图标
- 工控产品 友坚UT-S3C6410开发板 667MHz主频,Camera回显、H264/MPEG-4视频高效率编码
- gridview设定列宽
- 如何注册系统服务
- 20101119
- 寻找BDC OKCODE的方法
- Repair what you can — but when you must fail, fail noisily and as soon as possible. —Basics of The UNIX Philosophy 修复你能修好的—但是如果
- C++从入门到精通
- SAP标准OK Code Values 列表
- WCF 及 Silverlight 中使用 Session
- 参考:ODBC Drivers error(ODBC数据库驱动错误代码)原因解释
- Asp.Net 备份和恢复SQL SERVER 数据库
- CUDA, 用于大量数据的超级运算:第一节