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:
Robert Osfield
2010-04-22 16:01:38 +00:00
parent 25bc487763
commit f67942cf03
10 changed files with 114 additions and 143 deletions

View File

@@ -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)

View File

@@ -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 */

View File

@@ -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>

View File

@@ -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

View File

@@ -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"

View File

@@ -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 {

View File

@@ -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"

View File

@@ -345,7 +345,9 @@ std::string& osg::getGLExtensionDisableString()
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif // WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX
#endif // NOMINMAX
@@ -375,10 +377,10 @@ void* osg::getGLExtensionFuncPtr(const char *funcName)
#if defined(WIN32)
#if defined(OSG_GLES2_AVAILABLE)
static HMODULE hmodule = GetModuleHandle("libGLESv2.dll");
static HMODULE hmodule = GetModuleHandle(TEXT("libGLESv2.dll"));
return convertPointerType<void*, PROC>(GetProcAddress(hmodule, funcName));
#elif defined(OSG_GLES1_AVAILABLE)
static HMODULE hmodule = GetModuleHandle("libgles_cm.dll");
static HMODULE hmodule = GetModuleHandleA(TEXT("libgles_cm.dll"));
return convertPointerType<void*, PROC>(GetProcAddress(hmodule, funcName));
#else
return convertPointerType<void*, PROC>(wglGetProcAddress(funcName));

View File

@@ -157,11 +157,21 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindow)
__void__setCursor__MouseCursor,
"Set mouse cursor to a specific shape. ",
"");
I_Method1(void, setSyncToVBlank, IN, bool, on,
Properties::VIRTUAL,
__void__setSyncToVBlank__bool,
"Create a new mouse cursor from the usual bitmap data. ",
"Set sync-to-vblank. ");
I_Method0(bool, getSyncToVBlank,
Properties::NON_VIRTUAL,
__bool__getSyncToVBlank,
"",
"");
I_Method0(bool, valid,
Properties::VIRTUAL,
__bool__valid,
"Create a new mouse cursor from the usual bitmap data. ",
"Return whether a valid and usable GraphicsContext has been created. ");
"Return whether a valid and usable GraphicsContext has been created. ",
"");
I_Method0(bool, realizeImplementation,
Properties::VIRTUAL,
__bool__realizeImplementation,
@@ -223,6 +233,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindow)
I_SimpleProperty(osgGA::EventQueue *, EventQueue,
__osgGA_EventQueue_P1__getEventQueue,
__void__setEventQueue__osgGA_EventQueue_P1);
I_SimpleProperty(bool, SyncToVBlank,
__bool__getSyncToVBlank,
__void__setSyncToVBlank__bool);
I_SimpleProperty(bool, WindowDecoration,
__bool__getWindowDecoration,
__void__setWindowDecoration__bool);
@@ -269,8 +282,8 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindowEmbedded)
I_Method0(bool, valid,
Properties::VIRTUAL,
__bool__valid,
"Create a new mouse cursor from the usual bitmap data. ",
"Return whether a valid and usable GraphicsContext has been created. ");
"Return whether a valid and usable GraphicsContext has been created. ",
"");
I_Method0(bool, realizeImplementation,
Properties::VIRTUAL,
__bool__realizeImplementation,

View File

@@ -444,6 +444,16 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::StatsHandler)
__int__getKeyEventPrintsOutStats,
"",
"");
I_Method1(void, setKeyEventToggleVSync, IN, int, key,
Properties::NON_VIRTUAL,
__void__setKeyEventToggleVSync__int,
"",
"");
I_Method0(int, getKeyEventToggleVSync,
Properties::NON_VIRTUAL,
__int__getKeyEventToggleVSync,
"",
"");
I_Method0(double, getBlockMultiplier,
Properties::NON_VIRTUAL,
__double__getBlockMultiplier,
@@ -531,6 +541,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::StatsHandler)
I_SimpleProperty(int, KeyEventPrintsOutStats,
__int__getKeyEventPrintsOutStats,
__void__setKeyEventPrintsOutStats__int);
I_SimpleProperty(int, KeyEventToggleVSync,
__int__getKeyEventToggleVSync,
__void__setKeyEventToggleVSync__int);
I_SimpleProperty(int, KeyEventTogglesOnScreenStats,
__int__getKeyEventTogglesOnScreenStats,
__void__setKeyEventTogglesOnScreenStats__int);