Program Listing for File semaphore.h
↰ Return to documentation for file (include\concurrent\semaphore.h
)
/******************************************************************************
© Intel Corporation.
This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.
This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.
******************************************************************************/
#pragma once
#include <atomic>
namespace gpa {
namespace concurrent {
// wrapper around platform semaphore APIs
class Semaphore
{
public:
Semaphore(long initialValue = 0);
~Semaphore();
Semaphore(const Semaphore&) = delete;
Semaphore& operator=(const Semaphore&) = delete;
void Post();
void PostAll();
void Wait();
bool Wait(long timeoutMS);
private:
// track number of threads waiting on this semaphore
std::atomic<uint32_t> mNumWaiting;
// opaque storage for platform-specific semaphore types
struct __t
{
char m_val[64];
};
__t m_t
#if defined(__linux__)
// POSIX futex code will abort if this is not aligned
__attribute__((aligned(64)))
#endif // __linux__
;
};
} // namespace concurrent
} // namespace gpa