Windows: Fix PsychWaitCondition and PsychTimedWaitCondition hopefully for good.

There was still a potential race, where a thread could SetEvent()
the condition variable in a PsychSignalCondition() call, while
Psych(Timed)WaitCondition() would just decide to ResetEvent() the
condition variable after unlocking the associated mutex, so a
signal could get lost:

OLD:

Signaller:        Receiver:
WaitonLock        Holdlock
---               Unlock
Lock              ---
SetEvent          ---
---               ResetEvent(!)
---               WaitEvent !! Forever !!
Unlock

Now we ResetEvent() while still under lock protection,
so signaller can only lock -> SetEvent after we've
done ResetEvent -> unlock, ie., our reset can't undo
the almost simultaneous SetEvent() of the signaller and
the signal can't get lost.

Similar logic applies to resetting the "auto-reset" event
after we've regained the lock, for increased determinism.

Hilariously: Auto-Reset events on Windows only auto-reset if
they released at least one waiting thread, but they don't
auto-reset if no thread was waiting at SetEvent() time.
(Really?!? WTF!)

This should make signalling more Posix like, ie., more like
pthread_cond_signal() / pthread_cond_(timed)wait() on OS/X
and Linux.

For best results(tm) we will reorder all PsychSignalCondition()
calls in client code to first signal, then unlock.



git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2546 f5efbe48-b203-0410-9429-fc5e098e5a54
Place all PsychSignalCondition() calls before PsychUnlockMutex()

Signal condition variables while still holding the mutex lock
associated with them during Psych(Timed)WaitCondition().

This is supposed to improve determinism of scheduling a tiny
bit and possibly help the most broken OS in existence.

Posix (== Linux & OS/X) do not need this, but Posix recommends it
for deterministic scheduling:

Quote: "The pthread_cond_signal() or pthread_cond_broadcast()
functions may be called by a thread whether or not it currently
owns the mutex that threads calling pthread_cond_wait() or
pthread_cond_timedwait() have associated with the condition
variable during their waits; however, if predictable scheduling
behaviour is required, then that mutex is locked by the thread
calling pthread_cond_signal() or pthread_cond_broadcast()."

MS-Windows otoh is sufficiently f$#@$# to probably need this
much more urgently so it can better limp along with the real operating
systems.

-> Needs rebuild of Screen, PsychHID, PsychPortAudio to take effect.



git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2547 f5efbe48-b203-0410-9429-fc5e098e5a54
PortAudio: Replace pa_dither.[ch] with 64-Bit clean version from upstream Rev. 1418

Revision 1418 of upstream...

<http://www.assembla.com/code/portaudio/subversion/changesets/1418>

... fixes the audio dithering functions to work correctly on
64-Bit systems. This (so far untested) should fix the
loud white-noise heard in BasicSoundOutputDemo on 64-Bit
Ubuntu 12.04-LTS. BasicSoundOutputDemo is our only demo
which uses reqlatencyclass == 0, ie., no low-latency mode,
ie., dithering enabled --> White noise on 64-Bit Linux.

Let's see how this works out. Maybe this was related to the
static noise  bug on CentOS from Psychtoolbox forum message #13331?



git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2548 f5efbe48-b203-0410-9429-fc5e098e5a54
Fix so that it runs.  A bit more testing wouldn't hurt.  DHB

git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2549 f5efbe48-b203-0410-9429-fc5e098e5a54
Add test of irradiance to troland conversion. DHB

git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2550 f5efbe48-b203-0410-9429-fc5e098e5a54
moglmorpher: Add stricter parameter validation for 'addMesh'

Makes sure nobody passes in vertices, normals, texcoords or
vertex colors of wrong component count.



git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2551 f5efbe48-b203-0410-9429-fc5e098e5a54
PsychHID/OSX: Fixes and start of a GetChar mapping mode.

- Some important fixes.
- Half-Done HID code -> ASCII code remapping. This is just
  such a pain on the Apple OS, i couldn't stand it anymore!
  Will be finished another time.



git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2552 f5efbe48-b203-0410-9429-fc5e098e5a54
Screen, PsychPortAudio, PsychHID for OSX Intel Octave & Matlab rebuilt.



git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2553 f5efbe48-b203-0410-9429-fc5e098e5a54
Screen, PsychHID, PsychPortAudio for Windows Matlab R2007a & Octave rebuilt.
Screen, PsychHID, PsychPortAudio for Linux 64-Bit Matlab & Octave rebuilt.

-> PsychPortAudio contains Portaudio dithering fixes for 64-Bit Linux.



git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2554 f5efbe48-b203-0410-9429-fc5e098e5a54
Linux: Screen, PsychPortAudio, PsychHID for 32-Bit Octave & Matlab rebuilt.

git-svn-id: https://psychtoolbox-3.googlecode.com/svn/trunk@2555 f5efbe48-b203-0410-9429-fc5e098e5a54