Hi Robert, hi others,

i feel much better, i got the performance issue located. There is something odd in OpenThreads and i am not sure if this raise the trouble i am looking for many hours.
on the dual cores the framerate is now pritty good, unfortunately i have no access to the second computer. but at the moment it runs.

i just changed few lines in the latest CVS version of OpenThreads:
win32mutexprivatedata.h


#ifndef _WINDOWS_
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0400  // was missing : adegli
#include <windows.h>
#endif

win32mutex.cpp


static void _S_nsec_sleep(int __log_nsec) {

    if (__log_nsec <= 20) {
        SwitchToThread(); //Sleep(0); // adegli replaced it Sleep by SwitchToThread
     } else {
        Sleep(1 << (__log_nsec - 20));
     }
}


i hope it will run now on all systems :-) but i will continue testing

/adegli


2006/7/13, Adrian Egli < [EMAIL PROTECTED]>:
thanks for the nice inputs, i will try my best

2006/7/13, Martin Naylor <[EMAIL PROTECTED]>:

I would also get a knife or sword ready, just in case sys admin catches you
;-).
Be careful about local polices in place about your PC's, in can get you
fired quickly, although I don't know your situation.
Ask an Admin?

Martin.

> screwdriver handy though!
>
> John Donovan
> Sony Computer Entertainment Europe
> http://www.scee.com
>
>
>
> **********************************************************************
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> [EMAIL PROTECTED]
>
> This footnote also confirms that this email message has been checked
> for all known viruses.
>
> **********************************************************************
> Sony Computer Entertainment Europe
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://openscenegraph.net/mailman/listinfo/osg-users
> http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/


//
// OpenThread library, Copyright (C) 2002 - 2003  The Open Thread Group
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//
// Win32Mutex.c++ - C++ Mutex class .
// The idea for it is borrowed from SGI STL
// It looks like it's hard to use win32 CRITICALL_SECTIONS withour introducing race 
// conditions on InitializeCriticalSection() . So we use spin mutex here.
// ~~~~~~~~~~~~~~~~
//

#include <OpenThreads/Mutex>
#include "Win32MutexPrivateData.h"
using namespace OpenThreads;

Win32MutexPrivateData::~Win32MutexPrivateData()
{
}



template <int instance>
struct WIN32MutexSpin {

  enum { __low_max = 30, __high_max = 1000 };
  // Low if we suspect uniprocessor, high for multiprocessor.
  static unsigned __max;
  static unsigned __last;
};

template <int instance>
unsigned WIN32MutexSpin <instance>::__max = WIN32MutexSpin <instance>::__low_max;

template <int instance>
unsigned WIN32MutexSpin <instance>::__last = 0;



static void _S_nsec_sleep(int __log_nsec) {
	
    if (__log_nsec <= 20) {
        SwitchToThread(); //Sleep(0); // adegli replaced it Sleep by SwitchToThread
	} else {
        Sleep(1 << (__log_nsec - 20));
	}
}

#if defined(_MSC_VER) && _MSC_VER <= 1300
	template WIN32MutexSpin <0>;
#endif

//----------------------------------------------------------------------------
//
// Decription: Constructor
//
// Use: public.
//
Mutex::Mutex() {
    Win32MutexPrivateData *pd = new Win32MutexPrivateData();
    pd->mutex  = 0;
    _prvData = static_cast<void *>(pd);
}

//----------------------------------------------------------------------------
//
// Decription: Destructor
//
// Use: public.
//
Mutex::~Mutex() {
    unlock();
    delete static_cast<Win32MutexPrivateData*>(_prvData);
}
//----------------------------------------------------------------------------
//
// Decription: lock the mutex
//
// Use: public.
//
int Mutex::lock() {
    Win32MutexPrivateData *pd =
        static_cast<Win32MutexPrivateData*>(_prvData);

    volatile unsigned long* lock = &pd->mutex;
	// InterlockedExchange returns old value
	// if old_value  == 0 mutex wasn't locked , now it is
	if( !InterlockedExchange((long*)lock, 1L)) {
       return 0;
    }

    unsigned my_spin_max = WIN32MutexSpin<0>::__max;
    unsigned my_last_spins = WIN32MutexSpin<0>::__last;
    volatile unsigned junk = 17;      
    unsigned i;

    for (i = 0; i < my_spin_max; i++) {
      if (i < my_last_spins/2 || *lock) {
        junk *= junk; junk *= junk;
        junk *= junk; junk *= junk;
        continue;
      }

      if (!InterlockedExchange((long*)lock, 1L)) {
        // got it!
        // Spinning worked.  Thus we're probably not being scheduled
        // against the other process with which we were contending.
        // Thus it makes sense to spin longer the next time.
        WIN32MutexSpin<0>::__last = i;
        WIN32MutexSpin<0>::__max = WIN32MutexSpin<0>::__high_max;
        return 0;
      }
    }
    // We are probably being scheduled against the other process.  Sleep.
    WIN32MutexSpin<0>::__max = WIN32MutexSpin<0>::__low_max;
    for (i = 0 ;; ++i) {
      int __log_nsec = i + 6;
      if (__log_nsec > 27) __log_nsec = 27;
      if (!InterlockedExchange((long*)lock, 1L)) {
        return 0;
      }
      _S_nsec_sleep(__log_nsec);
    }
	return -1;
}

//----------------------------------------------------------------------------
//
// Decription: unlock the mutex
//
// Use: public.
//
int Mutex::unlock() {
    Win32MutexPrivateData *pd =
        static_cast<Win32MutexPrivateData*>(_prvData);

    volatile unsigned long* lock = &pd->mutex;
    *lock = 0;
    // This is not sufficient on many multiprocessors, since
    // writes to protected variables and the lock may be reordered.
	return 0;
}

//----------------------------------------------------------------------------
//
// Decription: test if the mutex may be locked
//
// Use: public.
//
int Mutex::trylock() {
    Win32MutexPrivateData *pd =
        static_cast<Win32MutexPrivateData*>(_prvData);

    volatile unsigned long* lock = &pd->mutex;

	if( !InterlockedExchange((long*)lock, 1L)) {
      return 1; // TRUE
    }

	return 0; // FALSE

}
//
// OpenThread library, Copyright (C) 2002 - 2003  The Open Thread Group
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//
// Win32MutexPrivateData.h - Private data structure for Mutex
// ~~~~~~~~~~~~~~~~~~~~~~~~~
//

#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 {
    friend class Mutex;
    friend class Condition;

private:

    Win32MutexPrivateData() {};

    ~Win32MutexPrivateData();

    volatile unsigned long mutex;

};

}

#endif // !_Win32MUTEXPRIVATEDATA_H_





_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to