Files
2024-09-23 12:00:04 -04:00

68 lines
2.3 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 {
/// The limits number of threads that can access the shared resource simultaneously.
class ONIXS_FIXENGINE_API Semaphore
{
public:
/// Initializes the instance with the given value of
/// the "count". The @param count indicates the initial "count"
/// for the semaphore. The state of the semaphore is signaled
/// when its count is greater than zero and
/// non-signaled when it is zero.
Semaphore(unsigned int count = 1);
/// Destructs the object.
~Semaphore();
/// Decrements the semaphore "counter" by one.
/// If the semaphore "counter" is already zero,
/// blocks the thread until the semaphore "count"
/// becomes greater than zero.
void acquire();
/// Tries to acquire the semaphore object. If
/// its "counter" is already zero, returns
/// @c false. In all cases, it doesn't block
/// the thread and quites immediately.
bool tryAcquire();
/// Increments the semaphore "counter" by one.
/// If there are other threads waiting for
/// the object, it blocks one the them.
void release();
private:
// Implementation details.
void * impl_;
// Copying & assignment is prohibited.
Semaphore(const Semaphore &);
Semaphore & operator = (const Semaphore &);
};
}
}