10#include "kcoreaddons_debug.h"
19SharedLockId findBestSharedLock()
24 bool timeoutsSupported =
false;
25 bool pthreadsProcessShared =
false;
26 bool semaphoresProcessShared =
false;
28#ifdef KSDC_TIMEOUTS_SUPPORTED
29 timeoutsSupported = ::sysconf(_SC_TIMEOUTS) >= 200112L;
34#ifdef KSDC_THREAD_PROCESS_SHARED_SUPPORTED
36 pthread_mutex_t tempMutex;
37 std::unique_ptr<KSDCLock> tempLock;
38 if (timeoutsSupported) {
39#ifdef KSDC_TIMEOUTS_SUPPORTED
40 tempLock = std::make_unique<pthreadTimedLock>(tempMutex);
43 tempLock = std::make_unique<pthreadLock>(tempMutex);
46 tempLock->initialize(pthreadsProcessShared);
51 if (timeoutsSupported && pthreadsProcessShared) {
52 return LOCKTYPE_MUTEX;
55#ifdef KSDC_SEMAPHORES_SUPPORTED
58 std::unique_ptr<KSDCLock> tempLock;
59 if (timeoutsSupported) {
60 tempLock = std::make_unique<semaphoreTimedLock>(tempSemaphore);
62 tempLock = std::make_unique<semaphoreLock>(tempSemaphore);
65 tempLock->initialize(semaphoresProcessShared);
69 if (timeoutsSupported && semaphoresProcessShared) {
70 return LOCKTYPE_SEMAPHORE;
71 }
else if (pthreadsProcessShared) {
72 return LOCKTYPE_MUTEX;
73 }
else if (semaphoresProcessShared) {
74 return LOCKTYPE_SEMAPHORE;
78 return LOCKTYPE_SPINLOCK;
81KSDCLock *createLockFromId(SharedLockId
id, SharedLock &lock)
84#ifdef KSDC_THREAD_PROCESS_SHARED_SUPPORTED
86#ifdef KSDC_TIMEOUTS_SUPPORTED
87 if (::sysconf(_SC_TIMEOUTS) >= 200112L) {
88 return new pthreadTimedLock(lock.mutex);
91 return new pthreadLock(lock.mutex);
96#ifdef KSDC_SEMAPHORES_SUPPORTED
97 case LOCKTYPE_SEMAPHORE:
98#ifdef KSDC_TIMEOUTS_SUPPORTED
99 if (::sysconf(_SC_SEMAPHORES) >= 200112L) {
100 return new semaphoreTimedLock(lock.semaphore);
103 return new semaphoreLock(lock.semaphore);
108 case LOCKTYPE_SPINLOCK:
109 return new simpleSpinLock(lock.spinlock);
113 qCCritical(KCOREADDONS_DEBUG) <<
"Creating shell of a lock!";
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:35:20 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.