Extracted SemaphoreLocker into it's own file.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32904 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -19,46 +19,14 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <SymLink.h>
|
#include <SymLink.h>
|
||||||
|
|
||||||
#include "AutoLocker.h"
|
|
||||||
#include "InstallerWindow.h"
|
#include "InstallerWindow.h"
|
||||||
// TODO: For PACKAGES_DIRECTORY and VAR_DIRECTORY, not so nice...
|
// TODO: For PACKAGES_DIRECTORY and VAR_DIRECTORY, not so nice...
|
||||||
|
#include "SemaphoreLocker.h"
|
||||||
|
|
||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
|
|
||||||
// SemaphoreLocking
|
|
||||||
class SemaphoreLocking {
|
|
||||||
public:
|
|
||||||
inline bool Lock(sem_id* lockable)
|
|
||||||
{
|
|
||||||
return acquire_sem(*lockable) == B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Unlock(sem_id* lockable)
|
|
||||||
{
|
|
||||||
release_sem(*lockable);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// SemaphoreLocker
|
|
||||||
class SemaphoreLocker : public AutoLocker<sem_id, SemaphoreLocking> {
|
|
||||||
public:
|
|
||||||
inline SemaphoreLocker(sem_id semaphore, bool alreadyLocked = false,
|
|
||||||
bool lockIfNotLocked = true)
|
|
||||||
:
|
|
||||||
AutoLocker<sem_id, SemaphoreLocking>(),
|
|
||||||
fSem(semaphore)
|
|
||||||
{
|
|
||||||
SetTo(&fSem, alreadyLocked, lockIfNotLocked);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
sem_id fSem;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CopyEngine::CopyEngine(const BMessenger& messenger, BMessage* message)
|
CopyEngine::CopyEngine(const BMessenger& messenger, BMessage* message)
|
||||||
:
|
:
|
||||||
fBufferQueue(),
|
fBufferQueue(),
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class BFile;
|
|||||||
class BMessage;
|
class BMessage;
|
||||||
class BMessenger;
|
class BMessenger;
|
||||||
|
|
||||||
|
|
||||||
class CopyEngine {
|
class CopyEngine {
|
||||||
public:
|
public:
|
||||||
CopyEngine(const BMessenger& messenger,
|
CopyEngine(const BMessenger& messenger,
|
||||||
@@ -109,4 +110,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // COPY_ENGINE_2_H
|
#endif // COPY_ENGINE_H
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2008-2009, Stephan Aßmus <[email protected]>
|
||||||
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _SEMAPHORE_LOCKER_H
|
||||||
|
#define _SEMAPHORE_LOCKER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "AutoLocker.h"
|
||||||
|
|
||||||
|
|
||||||
|
class SemaphoreLocking {
|
||||||
|
public:
|
||||||
|
inline bool Lock(sem_id* lockable)
|
||||||
|
{
|
||||||
|
return acquire_sem(*lockable) == B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Unlock(sem_id* lockable)
|
||||||
|
{
|
||||||
|
release_sem(*lockable);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SemaphoreLocker : public AutoLocker<sem_id, SemaphoreLocking> {
|
||||||
|
public:
|
||||||
|
inline SemaphoreLocker(sem_id semaphore, bool alreadyLocked = false,
|
||||||
|
bool lockIfNotLocked = true)
|
||||||
|
:
|
||||||
|
AutoLocker<sem_id, SemaphoreLocking>(),
|
||||||
|
fSem(semaphore)
|
||||||
|
{
|
||||||
|
SetTo(&fSem, alreadyLocked, lockIfNotLocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
sem_id fSem;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _SEMAPHORE_LOCKER_H
|
||||||
Reference in New Issue
Block a user