Esempio n. 1
0
/*!
    \internal

    Setup the semaphore
 */
HANDLE QSystemLockPrivate::handle()
{
    // don't allow making handles on empty keys
    if (key.isEmpty())
        return 0;

    // Create it if it doesn't already exists.
    if (semaphore == 0) {
        QString safeName = makeKeyFileName();
        semaphore = CreateSemaphore(0, MAX_LOCKS, MAX_LOCKS, (wchar_t*)safeName.utf16());

        if (semaphore == 0) {
            setErrorString(QLatin1String("QSystemLockPrivate::handle"));
            return 0;
        }
    }

    if (semaphoreLock == 0) {
        QString safeLockName = QSharedMemoryPrivate::makePlatformSafeKey(key + QLatin1String("lock"), QLatin1String("qipc_systemlock_"));
        semaphoreLock = CreateSemaphore(0, 1, 1, (wchar_t*)safeLockName.utf16());

        if (semaphoreLock == 0) {
            setErrorString(QLatin1String("QSystemLockPrivate::handle"));
            return 0;
        }
    }

    return semaphore;
}
int QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode)
{
    if (semaphore.Handle()) {
        return semaphore.Handle();
    }

    // don't allow making handles on empty keys
    if (key.isEmpty())
        return 0;

    QString safeName = makeKeyFileName();
    TPtrC name(qt_QString2TPtrC(safeName));
    int err = KErrAlreadyExists;
    int tryCount = 10;
    // Sort out race conditions by retrying several times until existing handle is acquired.
    // Sometimes opening can fail inexplicably with KErrPermissionDenied many times in a row.
    while (err != KErrNoMemory && err != KErrNone && tryCount-- >= 0) {
        err = semaphore.CreateGlobal(name, initialValue, EOwnerProcess);
        if (err != KErrNoMemory && err != KErrNone)
            err = semaphore.OpenGlobal(name,EOwnerProcess);
    }
    if (err){
        setErrorString(QLatin1String("QSystemSemaphore::handle"),err);
        return 0;
    }
    return semaphore.Handle();
}
Esempio n. 3
0
/*!
    \internal

    Setup the semaphore
 */
HANDLE QSystemLockPrivate::handle()
{
    // don't allow making handles on empty keys
    if (key.isEmpty())
        return 0;

    // Create it if it doesn't already exists.
    if (semaphore == 0) {
        QString safeName = makeKeyFileName();
        QT_WA({
            semaphore = CreateSemaphoreW(0, MAX_LOCKS, MAX_LOCKS, (TCHAR*)safeName.utf16());
        }, {
Esempio n. 4
0
HANDLE QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode)
{
    // don't allow making handles on empty keys
    if (key.isEmpty())
        return 0;

    // Create it if it doesn't already exists.
    if (semaphore == 0) {
        QString safeName = makeKeyFileName();
        QT_WA({
            semaphore = CreateSemaphoreW(0, initialValue, MAXLONG, (TCHAR*)safeName.utf16());
        }, {
HANDLE QSystemSemaphorePrivate::handle(QSystemSemaphore::AccessMode)
{
    // don't allow making handles on empty keys
    if (key.isEmpty())
        return 0;

    // Create it if it doesn't already exists.
    if (semaphore == 0) {
        QString safeName = makeKeyFileName();
        semaphore = CreateSemaphore(0, initialValue, MAXLONG, (wchar_t*)safeName.utf16());
        if (semaphore == NULL)
            setErrorString(QLatin1String("QSystemSemaphore::handle"));
    }

    return semaphore;
}