code clean
This commit is contained in:
@@ -19,55 +19,26 @@
|
||||
|
||||
#include "piconditionlock.h"
|
||||
#ifdef WINDOWS
|
||||
#include "synchapi.h"
|
||||
# include <synchapi.h>
|
||||
#else
|
||||
#include "pthread.h"
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIConditionLock)
|
||||
#ifdef WINDOWS
|
||||
CRITICAL_SECTION
|
||||
CRITICAL_SECTION
|
||||
#else
|
||||
pthread_mutex_t
|
||||
pthread_mutex_t
|
||||
#endif
|
||||
nativeHandle;
|
||||
nativeHandle;
|
||||
PRIVATE_DEFINITION_END(PIConditionLock)
|
||||
|
||||
|
||||
PIConditionLock::PIConditionLock() {
|
||||
#ifdef WINDOWS
|
||||
PIConditionLock::PIConditionLock() {
|
||||
InitializeCriticalSection(&PRIVATE->nativeHandle);
|
||||
}
|
||||
|
||||
|
||||
PIConditionLock::~PIConditionLock() {
|
||||
DeleteCriticalSection(&PRIVATE->nativeHandle);
|
||||
}
|
||||
|
||||
|
||||
void PIConditionLock::lock() {
|
||||
EnterCriticalSection(&PRIVATE->nativeHandle);
|
||||
}
|
||||
|
||||
|
||||
void PIConditionLock::unlock() {
|
||||
LeaveCriticalSection(&PRIVATE->nativeHandle);
|
||||
}
|
||||
|
||||
|
||||
void *PIConditionLock::handle() {
|
||||
return &PRIVATE->nativeHandle;
|
||||
}
|
||||
|
||||
|
||||
bool PIConditionLock::tryLock() {
|
||||
return TryEnterCriticalSection(&PRIVATE->nativeHandle) != 0;
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
PIConditionLock::PIConditionLock() {
|
||||
pthread_mutexattr_t attr;
|
||||
memset(&attr, 0, sizeof(attr));
|
||||
pthread_mutexattr_init(&attr);
|
||||
@@ -75,34 +46,50 @@ PIConditionLock::PIConditionLock() {
|
||||
memset(&(PRIVATE->nativeHandle), 0, sizeof(PRIVATE->nativeHandle));
|
||||
pthread_mutex_init(&(PRIVATE->nativeHandle), &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PIConditionLock::~PIConditionLock() {
|
||||
#ifdef WINDOWS
|
||||
DeleteCriticalSection(&PRIVATE->nativeHandle);
|
||||
#else
|
||||
pthread_mutex_destroy(&(PRIVATE->nativeHandle));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIConditionLock::lock() {
|
||||
#ifdef WINDOWS
|
||||
EnterCriticalSection(&PRIVATE->nativeHandle);
|
||||
#else
|
||||
pthread_mutex_lock(&(PRIVATE->nativeHandle));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIConditionLock::unlock() {
|
||||
#ifdef WINDOWS
|
||||
LeaveCriticalSection(&PRIVATE->nativeHandle);
|
||||
#else
|
||||
pthread_mutex_unlock(&(PRIVATE->nativeHandle));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void *PIConditionLock::handle() {
|
||||
#ifdef WINDOWS
|
||||
return &PRIVATE->nativeHandle;
|
||||
#else
|
||||
return &PRIVATE->nativeHandle;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PIConditionLock::tryLock() {
|
||||
#ifdef WINDOWS
|
||||
return TryEnterCriticalSection(&PRIVATE->nativeHandle) != 0;
|
||||
#else
|
||||
return (pthread_mutex_trylock(&(PRIVATE->nativeHandle)) == 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,28 +17,27 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piplatform.h"
|
||||
#include "piconditionvar.h"
|
||||
#include "pithread.h"
|
||||
#include "pitime.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
#undef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0600
|
||||
#include "synchapi.h"
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
# undef _WIN32_WINNT
|
||||
# define _WIN32_WINNT 0x0600
|
||||
# include <synchapi.h>
|
||||
# include <windef.h>
|
||||
# include <winbase.h>
|
||||
#endif
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIConditionVariable)
|
||||
#ifdef WINDOWS
|
||||
CONDITION_VARIABLE nativeHandle;
|
||||
CONDITION_VARIABLE nativeHandle;
|
||||
#else
|
||||
pthread_cond_t nativeHandle;
|
||||
PIConditionLock* currentLock;
|
||||
pthread_cond_t nativeHandle;
|
||||
PIConditionLock* currentLock;
|
||||
#endif
|
||||
bool isDestroying;
|
||||
bool isDestroying;
|
||||
PRIVATE_DEFINITION_END(PIConditionVariable)
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef AWRCANFLASHER_PICONDITIONLOCK_H
|
||||
#define AWRCANFLASHER_PICONDITIONLOCK_H
|
||||
#ifndef PICONDITIONLOCK_H
|
||||
#define PICONDITIONLOCK_H
|
||||
|
||||
#include "pimutex.h"
|
||||
|
||||
@@ -48,4 +48,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif //AWRCANFLASHER_PICONDITIONLOCK_H
|
||||
#endif // PICONDITIONLOCK_H
|
||||
|
||||
@@ -17,12 +17,11 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PIP_TESTS_PICONDITIONVAR_H
|
||||
#define PIP_TESTS_PICONDITIONVAR_H
|
||||
#ifndef PICONDITIONVAR_H
|
||||
#define PICONDITIONVAR_H
|
||||
|
||||
#include "piconditionlock.h"
|
||||
#include "pithread.h"
|
||||
#include "piinit.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -117,4 +116,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif //PIP_TESTS_PICONDITIONVAR_H
|
||||
#endif // PICONDITIONVAR_H
|
||||
|
||||
Reference in New Issue
Block a user