617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan/*******************************************************************************
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Copyright (C) 2004-2008 Intel Corp. All rights reserved.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * Redistribution and use in source and binary forms, with or without
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * modification, are permitted provided that the following conditions are met:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * - Redistributions of source code must retain the above copyright notice,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * this list of conditions and the following disclaimer.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * - Redistributions in binary form must reproduce the above copyright notice,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * this list of conditions and the following disclaimer in the documentation
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * and/or other materials provided with the distribution.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * - Neither the name of Intel Corp. nor the names of its
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * contributors may be used to endorse or promote products derived from this
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * software without specific prior written permission.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan * POSSIBILITY OF SUCH DAMAGE.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan *******************************************************************************/
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan//////////////////////////////////////////////////////////////////////////
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// This file contains an OS independent interface for thread manipulation
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// A Thread class is defined for easy usage.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// Option 1: Construct an instance of the "Thread" class with an external
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// callback function. When calling the "start" method, the thread will be
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// started on the callback function
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// Option 2: Subclass the "Thread" class and reimplement the virtual "run"
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// method. When calling the "start" method, the thread will be started
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// on the "run" function.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// Implementation overview:
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// Calling the "start" method will start the new thread, which will call the
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// "run" method. The default implementation of the "run" method will call
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan// the Callback function given in the constructor.
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan//////////////////////////////////////////////////////////////////////////
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan Thread(CallbackFunction func = NULL, void *param = NULL);
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan // wait for the thread to complete; return true if the thread completed,
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan // false on timeout
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan bool wait(unsigned long msecs = WAIT_INFINITE) const;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan // start the new thread, return true on success
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan // true if the thread is in running state
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan bool running() const;
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan // measure the time (in msecs) from thread start-time
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan // return ID for the current thread
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan static unsigned long currentThread();
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan // put the current thread to sleep
617e2443dfc17fe44fd44c0675d6aad2ffc9df42Mark Logan#endif //_LAD_THREAD_H