73 lines
2.4 KiB
C++
73 lines
2.4 KiB
C++
/*
|
|
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
|
|
*
|
|
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
|
|
* and international copyright treaties.
|
|
*
|
|
* Access to and use of the software is governed by the terms of the applicable OnixS Software
|
|
* Services Agreement (the Agreement) and Customer end user license agreements granting
|
|
* a non-assignable, non-transferable and non-exclusive license to use the software
|
|
* for it's own data processing purposes under the terms defined in the Agreement.
|
|
*
|
|
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
|
|
* of this source code or associated reference material to any other location for further reproduction
|
|
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
|
|
*
|
|
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
|
|
* the terms of the Agreement is a violation of copyright law.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <OnixS/FIXEngine/ABI.h>
|
|
|
|
namespace OnixS {
|
|
namespace Threading {
|
|
/// Protects a resources from the simultaneous access by multiple threads.
|
|
///
|
|
/// Only one thread at a time can own the instance of this class.
|
|
///
|
|
/// This implementation is optimized for locking threads that are in the same process.
|
|
///
|
|
/// @note It is NOT suitable for use for the interprocess synchronization.
|
|
/// @note The recursive locking is NOT supported.
|
|
class ONIXS_FIXENGINE_API Mutex
|
|
{
|
|
public:
|
|
friend ONIXS_FIXENGINE_API_DECL(class, Condition);
|
|
|
|
/// Initializes the instance.
|
|
Mutex();
|
|
|
|
/// Destructs the instance.
|
|
~Mutex();
|
|
|
|
/// Acquires the lock ownership. If the Mutex already
|
|
/// occupied by the other thread, blocks the current
|
|
/// thread and waits until it will be released
|
|
/// by the owner.
|
|
void acquire();
|
|
|
|
/// Acquires the lock ownership if the Mutex is not
|
|
/// owned by any thread. If the Mutex is already
|
|
/// owned by the other thread, returns @c false.
|
|
/// In either cases it doesn't block thread and
|
|
/// quites immediately.
|
|
bool tryAcquire();
|
|
|
|
/// Releases the ownership (lock) and
|
|
/// unblocks one of waiting threads.
|
|
void release();
|
|
|
|
private:
|
|
// Implementation details.
|
|
void * impl_;
|
|
|
|
// Copying and assignment are prohibited.
|
|
|
|
Mutex(const Mutex &);
|
|
Mutex & operator = (const Mutex &);
|
|
};
|
|
}
|
|
}
|