helonSY欢迎您的到来!

知识积累的殿堂,有些可能很低级,大家勿见笑,只是方便复制!

linux--lock

/****************lock**************/
#if defined(_WIN32)||defined(_WIN64)
 CRITICAL_SECTION g_Mutex;
#else
 pthread_mutex_t g_Mutex;
#endif


void InitLock()
{
#if defined(_WIN32)||defined(_WIN64)
 InitializeCriticalSection(&g_Mutex);
#else
 pthread_mutex_init(&g_Mutex,NULL);
#endif
}

void UninitLock()
{
#if defined(_WIN32)||defined(_WIN64)
 DeleteCriticalSection(&g_Mutex);
#else
 pthread_mutex_destroy(&g_Mutex);
#endif
}

void Lock()
{
#if defined(_WIN32)||defined(_WIN64)
    EnterCriticalSection(&g_Mutex);
#else
 pthread_mutex_lock(&g_Mutex);
#endif
}

void UnLock()
{
#if defined(_WIN32)||defined(_WIN64)
    LeaveCriticalSection(&g_Mutex);
#else
 pthread_mutex_unlock(&g_Mutex);
#endif
}

阅读更多
文章标签: null
个人分类: Linux C/C++
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭