1 // 2 // Mutex_VX.cpp 3 // 4 // Library: Foundation 5 // Package: Threading 6 // Module: Mutex 7 // 8 // Copyright (c) 2004-2011, Applied Informatics Software Engineering GmbH. 9 // and Contributors. 10 // 11 // SPDX-License-Identifier: BSL-1.0 12 // 13 14 15 #include "Poco/Mutex_VX.h" 16 #include <sysLib.h> 17 18 19 namespace Poco { 20 21 MutexImpl()22MutexImpl::MutexImpl() 23 { 24 _sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY); 25 if (_sem == 0) 26 throw Poco::SystemException("cannot create mutex"); 27 } 28 29 MutexImpl(bool fast)30MutexImpl::MutexImpl(bool fast) 31 { 32 if (fast) 33 { 34 _sem = semBCreate(SEM_Q_PRIORITY, SEM_FULL); 35 } 36 else 37 { 38 _sem = semMCreate(SEM_INVERSION_SAFE | SEM_Q_PRIORITY); 39 } 40 if (_sem == 0) 41 throw Poco::SystemException("cannot create mutex"); 42 } 43 44 ~MutexImpl()45MutexImpl::~MutexImpl() 46 { 47 semDelete(_sem); 48 } 49 50 tryLockImpl(long milliseconds)51bool MutexImpl::tryLockImpl(long milliseconds) 52 { 53 int ticks = milliseconds*sysClkRateGet()/1000; 54 return semTake(_sem, ticks) == OK; 55 } 56 57 FastMutexImpl()58FastMutexImpl::FastMutexImpl(): MutexImpl(true) 59 { 60 } 61 62 ~FastMutexImpl()63FastMutexImpl::~FastMutexImpl() 64 { 65 } 66 67 68 } // namespace Poco 69