About the Blog

Back to Scriptionary

The Scriptionary blog is part of the Scriptionary wiki. Informal news and information will be announced here.

More…

Advertisement

Popular Tags

The tag with the most posts is the largest and vice versa.

CriticalSection wrapper class

22 August 2008 - 11:09, By E. Luten

What: A C++ wrapper around both WINAPI (Microsoft Windows) and PThreads (POSIX threads) functionality.
Why: To abstract cross platform functionality.
Remarks: On windows, CRITICAL_SECTION objects cannot be shared cross-process. This means that the class is tied to your application or DLL process. Comments are in Doxygen/Javadoc style.

#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <pthread.h>
#endif

/**
 * @class A wrapper-class around Critical Section functionality, WIN32 & PTHREADS.
 */
class CriticalSection
{
public:
	/**
	 * @brief CriticalSection class constructor.
	 */
	explicit CriticalSection(void)
	{
	#ifdef _WIN32
		if (0 == InitializeCriticalSectionAndSpinCount(&this->m_cSection, 0))
			throw("Could not create a CriticalSection");
	#else
		if (pthread_mutex_init(&this->m_cSection, NULL) != 0)
			throw("Could not create a CriticalSection");
	#endif
	}; // CriticalSection()

	/**
	 * @brief CriticalSection class destructor
	 */
	~CriticalSection(void)
	{
		this->WaitForFinish(); // acquire ownership
	#ifdef _WIN32
		DeleteCriticalSection(&this->m_cSection);
	#else
		pthread_mutex_destroy(&this->m_cSection);
	#endif
	}; // ~CriticalSection()

	/**
	 * @fn void WaitForFinish(void)
	 * @brief Waits for the critical section to unlock.
	 * This function puts the waiting thread in a waiting
	 * state.
	 * @see TryEnter()
	 * @return void
	 */
	void WaitForFinish(void)
	{
		while(!this->TryEnter())
		{
		#ifdef _WIN32
			Sleep(1); // put waiting thread to sleep for 1ms
		#else
			usleep(1000); // put waiting thread to sleep for 1ms (1000us)
		#endif
		};
	}; // WaitForFinish()

	/**
	 * @fn void Enter(void)
	 * @brief Wait for unlock and enter the CriticalSection object.
	 * @see TryEnter()
	 * @return void
	 */
	void Enter(void)
	{
		this->WaitForFinish(); // acquire ownership
	#ifdef _WIN32
		EnterCriticalSection(&this->m_cSection);
	#else
		pthread_mutex_lock(&this->m_cSection);
	#endif
	}; // Enter()

	/**
	 * @fn void Leave(void)
	 * @brief Leaves the critical section object.
	 * This function will only work if the current thread
	 * holds the current lock on the CriticalSection object
	 * called by Enter()
	 * @see Enter()
	 * @return void
	 */
	void Leave(void)
	{
	#ifdef _WIN32
		LeaveCriticalSection(&this->m_cSection);
	#else
		pthread_mutex_unlock(&this->m_cSection);
	#endif
	}; // Leave()

	/**
	 * @fn bool TryEnter(void)
	 * @brief Attempt to enter the CriticalSection object
	 * @return bool(true) on success, bool(false) if otherwise
	 */
	bool TryEnter(void)
	{
		// Attempt to acquire ownership:
	#ifdef _WIN32
		return(TRUE == TryEnterCriticalSection(&this->m_cSection));
	#else
		return(0 == pthread_mutex_trylock(&this->m_cSection));
	#endif
	}; // TryEnter()

private:
#ifdef _WIN32
	CRITICAL_SECTION m_cSection; //!< internal system critical section object (windows)
#else
	pthread_mutex_t m_cSection; //!< internal system critical section object (*nix)
#endif
}; // class CriticalSection

No Comments | Tags: Tagged with:

DirectX SDK August 2008

16 August 2008 - 3:12, By E. Luten

Hot off the press, get it now: DirectX SDK August 2008

No Comments | Tags: Tagged with:

Preliminary view of DirectX 11

15 August 2008 - 12:51, By E. Luten

Following is a list of the major features that have been announced to be included in Direct3D 11, the next generation Graphics API included in the DirectX SDK. In my opinion, the changes (rather, additions) brought into this API are excellent so far. It seems as if the API has finally grown up and is in no way, shape or form comparable with older DX versions and deprecates OpenGL 3.0 at this point.

Major Direct3D 11 Features:

  1. Compatibility: Ability to run on previous generation hardware (9, 10, 10.1)
  2. Multithreading: Resources may be created asynchronously on separate threads.
  3. Tesselation: Allows for subdivision surface operations (Fixed Function, not programmable)
  4. Compute Shaders: Allows for general programming on the CPU, much like NVIDIA’s CUDA.
  5. No Overhaul: Direct3D 11 is a superset of Direct3D 10, no learning curve as with 9 → 10.

A DX11 preview should appear in your November 2008 DirectX SDK. Keep your eyes on this page for GDC 2008 DirectX 11 papers.

Notes
1. Although you may use the Direct3D 11 SDK on older hardware features will naturally be limited to the hardware itself.

No Comments | Tags: Tagged with:

“Don’t worry, it’s just a warning.”

15 August 2008 - 10:34, By E. Luten

I don’t like Visual Basic, yet in many Microsoft shops, VB is still being used especially in combination with ASP.NET. The problem with Visual Basic is that it’s not very strongly typed. Conventions are often thrown out of the window and Senior VB developers often hold their seniority as experience which, is more fiction than fact.

How many more times do I have to see Functions which don’t return anything and should have been declared as Subs.

Or: Variable 'XYZ' is used before it has been assigned a value.
Or: Variable declaration without an 'As' clause; type of Object assumed.

Visual Basic ErrorsUgh. You’d think that people with 15 years of development experience wouldn’t dismiss this kind of stuff and just do the right thing.

No Comments | Tags: Tagged with:

OpenGL 3.0 - 1 hour after

11 August 2008 - 9:57, By E. Luten

Artistic License?

Once upon a time there was a little old API, struggling for its life amongst the giants of software. Little old OpenGL knew that in order to survive it had to adapt to a strange, bewildering and new environment; it was a strange new world indeed. For two years, rumors of old OpenGL’s struggles reached the user-groups and there was much rejoicing indeed. But on one faithful day, August the 11th of 2008, OpenGL perished. Its age and idleness had (as with all things good and bad) caught up with him and slayed little old OpenGL in its path.

After reading the spec and looking desperately for the promised object model, I felt quite like a (self-censored) taking the newsletters seriously and writing about them so explicitly.

For those who haven’t read the specification yet, it’s OpenGL 2.1 plus and minus some stuff, hardly the fruition of two years labor. The anticipation that followed the initial announcement of OpenGL 3.0’s Object Model was tremendous. For the first time in a long time, people started noticing OpenGL again and maybe a place for it in modern multimedia applications such as PC games besides id Software’s titles.

Alas, it was not to be. Woe is me for my old API is truly dead. D3D, hello.

No Comments | Tags: Tagged with:

Pages: 1 2 Next