From Alok Priyadashi, "The attached patch fixes
- compile errors on windows when compiled with UNICODE flag - warnings for duplicate WIN32_LEAN_AND_MEAN. I think this should better fixed by adding WIN32_LEAN_AND_MEAN to vcproj preprocessor list."
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
SET(LIB_NAME OpenThreads)
|
||||
SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS})
|
||||
|
||||
ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN)
|
||||
ADD_DEFINITIONS(-D_WIN32_WINNT=0x0400)
|
||||
SOURCE_GROUP("Header Files" FILES ${LIB_PUBLIC_HEADERS})
|
||||
SET_SOURCE_FILES_PROPERTIES(${LIB_PUBLIC_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@
|
||||
#ifndef _HandleHolder_H_
|
||||
#define _HandleHolder_H_
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/************************************************************************/
|
||||
/* Class that holds HANDLES ensuring proper destruction */
|
||||
|
||||
@@ -18,12 +18,6 @@
|
||||
#ifndef _Win32BARRIERPRIVATEDATA_H_
|
||||
#define _Win32BARRIERPRIVATEDATA_H_
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <OpenThreads/Mutex>
|
||||
#include <OpenThreads/Condition>
|
||||
|
||||
|
||||
@@ -11,10 +11,8 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _WIN32VODITIONPRODUCER_CONDITION
|
||||
#define PRODUCER_CONDITION
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef _WIN32CONDITION_H_
|
||||
#define _WIN32CONDITION_H_
|
||||
|
||||
#include "Mutex.h"
|
||||
|
||||
@@ -23,85 +21,85 @@ namespace OpenThreads {
|
||||
class Win32ConditionImpl
|
||||
{
|
||||
public:
|
||||
/// number of waiters.
|
||||
long waiters_;
|
||||
/// number of waiters.
|
||||
long waiters_;
|
||||
|
||||
Condition(long max = 0L)
|
||||
{
|
||||
waiters_ = 0;
|
||||
sema_ = CreateSemaphore(NULL,0,0x7fffffff,NULL);
|
||||
waiters_done_ = CreateEvent(NULL,FALSE,FALSE,NULL);
|
||||
}
|
||||
Condition(long max = 0L)
|
||||
{
|
||||
waiters_ = 0;
|
||||
sema_ = CreateSemaphore(NULL,0,0x7fffffff,NULL);
|
||||
waiters_done_ = CreateEvent(NULL,FALSE,FALSE,NULL);
|
||||
}
|
||||
|
||||
~Condition()
|
||||
{
|
||||
// CloseHandle(sema_);
|
||||
// CloseHandle(waiters_done_);
|
||||
}
|
||||
~Condition()
|
||||
{
|
||||
// CloseHandle(sema_);
|
||||
// CloseHandle(waiters_done_);
|
||||
}
|
||||
|
||||
inline int broadcast ()
|
||||
{
|
||||
waiters_lock_.lock();
|
||||
int have_waiters = 0;
|
||||
inline int broadcast ()
|
||||
{
|
||||
waiters_lock_.lock();
|
||||
int have_waiters = 0;
|
||||
|
||||
if (waiters_ > 0)
|
||||
{
|
||||
// We are broadcasting, even if there is just one waiter...
|
||||
// Record the fact that we are broadcasting. This helps the
|
||||
// wait() method know how to optimize itself. Be sure to
|
||||
// set this with the <waiters_lock_> held.
|
||||
was_broadcast_ = 1;
|
||||
have_waiters = 1;
|
||||
}
|
||||
waiters_lock_.unlock();
|
||||
|
||||
int result = 0;
|
||||
if (have_waiters)
|
||||
{
|
||||
// Wake up all the waiters.
|
||||
ReleaseSemaphore(sema_,waiters_,NULL);
|
||||
WaitForSingleObject(waiters_done_,INFINITE) ;
|
||||
// This is okay, even without the <waiters_lock_> held because
|
||||
// no other waiter threads can wake up to access it.
|
||||
was_broadcast_ = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
if (waiters_ > 0)
|
||||
{
|
||||
// We are broadcasting, even if there is just one waiter...
|
||||
// Record the fact that we are broadcasting. This helps the
|
||||
// wait() method know how to optimize itself. Be sure to
|
||||
// set this with the <waiters_lock_> held.
|
||||
was_broadcast_ = 1;
|
||||
have_waiters = 1;
|
||||
}
|
||||
waiters_lock_.unlock();
|
||||
|
||||
int result = 0;
|
||||
if (have_waiters)
|
||||
{
|
||||
// Wake up all the waiters.
|
||||
ReleaseSemaphore(sema_,waiters_,NULL);
|
||||
WaitForSingleObject(waiters_done_,INFINITE) ;
|
||||
// This is okay, even without the <waiters_lock_> held because
|
||||
// no other waiter threads can wake up to access it.
|
||||
was_broadcast_ = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline int wait (Mutex& external_mutex)
|
||||
{
|
||||
// Prevent race conditions on the <waiters_> count.
|
||||
waiters_lock_.lock();
|
||||
waiters_++;
|
||||
waiters_lock_.unlock();
|
||||
|
||||
int result = 0;
|
||||
|
||||
inline int wait (Mutex& external_mutex)
|
||||
{
|
||||
// Prevent race conditions on the <waiters_> count.
|
||||
waiters_lock_.lock();
|
||||
waiters_++;
|
||||
waiters_lock_.unlock();
|
||||
|
||||
int result = 0;
|
||||
|
||||
external_mutex.unlock();
|
||||
|
||||
DWORD dwResult = WaitForSingleObject(sema_,INFINITE);
|
||||
if(dwResult != WAIT_OBJECT_0)
|
||||
result = (int)dwResult;
|
||||
|
||||
// Reacquire lock to avoid race conditions on the <waiters_> count.
|
||||
waiters_lock_.lock();
|
||||
|
||||
// We're ready to return, so there's one less waiter.
|
||||
waiters_--;
|
||||
|
||||
int last_waiter = was_broadcast_ && waiters_ == 0;
|
||||
|
||||
// Release the lock so that other collaborating threads can make
|
||||
// progress.
|
||||
waiters_lock_.unlock();
|
||||
|
||||
if (result != -1 && last_waiter)
|
||||
SetEvent(waiters_done_);
|
||||
|
||||
external_mutex.lock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
DWORD dwResult = WaitForSingleObject(sema_,INFINITE);
|
||||
if(dwResult != WAIT_OBJECT_0)
|
||||
result = (int)dwResult;
|
||||
|
||||
// Reacquire lock to avoid race conditions on the <waiters_> count.
|
||||
waiters_lock_.lock();
|
||||
|
||||
// We're ready to return, so there's one less waiter.
|
||||
waiters_--;
|
||||
|
||||
int last_waiter = was_broadcast_ && waiters_ == 0;
|
||||
|
||||
// Release the lock so that other collaborating threads can make
|
||||
// progress.
|
||||
waiters_lock_.unlock();
|
||||
|
||||
if (result != -1 && last_waiter)
|
||||
SetEvent(waiters_done_);
|
||||
|
||||
external_mutex.lock();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
@@ -122,38 +120,6 @@ protected:
|
||||
size_t was_broadcast_;
|
||||
|
||||
};
|
||||
#else
|
||||
#include <pthread.h>
|
||||
|
||||
namespace Producer {
|
||||
|
||||
class PR_EXPORT Condition
|
||||
{
|
||||
public:
|
||||
/// number of waiters.
|
||||
Condition(long max)
|
||||
{
|
||||
pthread_cond_init( &_cond, 0L );
|
||||
}
|
||||
|
||||
~Condition()
|
||||
{
|
||||
}
|
||||
|
||||
inline int broadcast ()
|
||||
{
|
||||
return pthread_cond_broadcast(&_cond);
|
||||
}
|
||||
|
||||
inline int wait (Mutex& external_mutex)
|
||||
{
|
||||
return pthread_cond_wait(&_cond);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
pthread_cond_t _cond;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -19,12 +19,6 @@
|
||||
#ifndef _WIN32CONDITIONPRIVATEDATA_H_
|
||||
#define _WIN32CONDITIONPRIVATEDATA_H_
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <OpenThreads/ScopedLock>
|
||||
|
||||
#include "Win32ThreadPrivateData.h"
|
||||
|
||||
@@ -19,12 +19,8 @@
|
||||
#ifndef _Win32MUTEXPRIVATEDATA_H_
|
||||
#define _Win32MUTEXPRIVATEDATA_H_
|
||||
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WIN32_WINNT 0x0400 // was missing : adegli
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace OpenThreads {
|
||||
|
||||
class Win32MutexPrivateData {
|
||||
|
||||
@@ -17,12 +17,6 @@
|
||||
#ifndef _Win32PRIVATEDATA_H_
|
||||
#define _Win32PRIVATEDATA_H_
|
||||
|
||||
#ifndef _WINDOWS_
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <OpenThreads/Thread>
|
||||
#include <OpenThreads/Block>
|
||||
#include "HandleHolder.h"
|
||||
|
||||
Reference in New Issue
Block a user