Lunchbox  1.15.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
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

 TimedLock ()
 Construct a new timed lock. More...
 
 ~TimedLock ()
 Destruct the lock. More...
 
bool set (const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
 Set the lock. More...
 
void unset ()
 Release the lock. More...
 
bool trySet ()
 Attempt to set the lock. More...
 
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 <lunchbox/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::TimedLock::TimedLock ( )

Construct a new timed lock.

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

Destruct the lock.

Version
1.0

Member Function Documentation

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
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
bool lunchbox::TimedLock::trySet ( )

Attempt to set the lock.

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

Release the lock.

Version
1.0

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