Lunchbox  1.11.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lunchbox::TimedLock Class Reference

A mutex with timeout capabilities. More...

#include <timedLock.h>

+ Inheritance diagram for lunchbox::TimedLock:
+ Collaboration diagram for lunchbox::TimedLock:

Public Member Functions

LUNCHBOX_API TimedLock ()
 Construct a new timed lock. More...
 
LUNCHBOX_API ~TimedLock ()
 Destruct the lock. More...
 
LUNCHBOX_API bool set (const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
 Set the lock. More...
 
LUNCHBOX_API void unset ()
 Release the lock. More...
 
LUNCHBOX_API bool trySet ()
 Attempt to set the lock. More...
 
LUNCHBOX_API bool isSet ()
 Test if the lock is set. More...
 

Detailed Description

A mutex with timeout capabilities.

Deprecated:
Use boost::timed_lock

Example:

/* Copyright (c) 2006-2013, Stefan Eilemann <eile@equalizergraphics.com>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
* by the Free Software Foundation.
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <test.h>
#include <lunchbox/clock.h>
#include <lunchbox/timedLock.h>
#include <iostream>
int main( int, char** )
{
TEST( lock.set( ));
TEST( !lock.set( 1000 ));
float time = clock.getTimef();
TESTINFO( time > 999.0f, "was: " << time );
TESTINFO( time < 1100.0f, "was: " << time );
clock.reset();
TEST( !lock.set( 100 ));
time = clock.getTimef();
TESTINFO( time > 99.0f, "was: " << time );
TESTINFO( time < 200.0f, "was: " << time );
return EXIT_SUCCESS;
}

Definition at line 35 of file timedLock.h.

Constructor & Destructor Documentation

LUNCHBOX_API lunchbox::TimedLock::TimedLock ( )

Construct a new timed lock.

Version
1.0
LUNCHBOX_API lunchbox::TimedLock::~TimedLock ( )

Destruct the lock.

Version
1.0

Member Function Documentation

LUNCHBOX_API bool lunchbox::TimedLock::isSet ( )

Test if the lock is set.

Returns
true if the lock is set, false if it is not set.
Version
1.0
LUNCHBOX_API bool lunchbox::TimedLock::set ( const uint32_t  timeout = LB_TIMEOUT_INDEFINITE)

Set the lock.

Parameters
timeoutthe timeout in milliseconds to wait for the lock, or LB_TIMEOUT_INDEFINITE to wait indefinitely.
Returns
true if the lock was acquired, false if not.
Version
1.0
LUNCHBOX_API bool lunchbox::TimedLock::trySet ( )

Attempt to set the lock.

Returns
true if the lock was acquired, false if not.
Version
1.0
LUNCHBOX_API void lunchbox::TimedLock::unset ( )

Release the lock.

Version
1.0

The documentation for this class was generated from the following file: