Path: blob/master/3rdparty/openexr/IlmThread/IlmThreadWin32.cpp
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2005, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////3334//-----------------------------------------------------------------------------35//36// class Thread -- implementation for Windows37//38//-----------------------------------------------------------------------------394041#include "IlmThread.h"42#include "Iex.h"43#include <iostream>44#include <assert.h>4546namespace IlmThread {474849bool50supportsThreads ()51{52return true;53}5455namespace {5657unsigned __stdcall58threadLoop (void * t)59{60reinterpret_cast<Thread*>(t)->run();61_endthreadex (0);62return 0;63}6465} // namespace666768Thread::Thread ()69{70// empty71}727374Thread::~Thread ()75{76DWORD status = ::WaitForSingleObject (_thread, INFINITE);77assert (status == WAIT_OBJECT_0);78bool ok = ::CloseHandle (_thread) != FALSE;79assert (ok);80}818283void84Thread::start ()85{86unsigned id;87_thread = (HANDLE)::_beginthreadex (0, 0, &threadLoop, this, 0, &id);8889if (_thread == 0)90Iex::throwErrnoExc ("Cannot create new thread (%T).");91}929394} // namespace IlmThread959697