Fixed semaphores being duplicated needlessly.

This commit is contained in:
Thulinma 2014-07-17 16:25:10 +02:00
parent 933586661f
commit eea2c8b0db
2 changed files with 10 additions and 10 deletions

View file

@ -572,13 +572,13 @@ namespace IPC {
} }
///\brief Creates a semaphore guard, locks the semaphore on call ///\brief Creates a semaphore guard, locks the semaphore on call
semGuard::semGuard(semaphore thisSemaphore) : mySemaphore(thisSemaphore) { semGuard::semGuard(semaphore * thisSemaphore) : mySemaphore(thisSemaphore) {
mySemaphore.wait(); mySemaphore->wait();
} }
///\brief Destructs a semaphore guard, unlocks the semaphore on call ///\brief Destructs a semaphore guard, unlocks the semaphore on call
semGuard::~semGuard() { semGuard::~semGuard() {
mySemaphore.post(); mySemaphore->post();
} }
///\brief Default constructor, erases all the values ///\brief Default constructor, erases all the values
@ -641,7 +641,7 @@ namespace IPC {
///\brief Creates the next page with the correct size ///\brief Creates the next page with the correct size
void sharedServer::newPage() { void sharedServer::newPage() {
semGuard tmpGuard(mySemaphore); semGuard tmpGuard(&mySemaphore);
sharedPage tmp(std::string(baseName + (char)(myPages.size() + (int)'A')), (4096 << myPages.size()), true); sharedPage tmp(std::string(baseName + (char)(myPages.size() + (int)'A')), (4096 << myPages.size()), true);
myPages.insert(tmp); myPages.insert(tmp);
tmp.master = false; tmp.master = false;
@ -654,7 +654,7 @@ namespace IPC {
DEBUG_MSG(DLVL_WARN, "Can't remove last page for %s", baseName.c_str()); DEBUG_MSG(DLVL_WARN, "Can't remove last page for %s", baseName.c_str());
return; return;
} }
semGuard tmpGuard(mySemaphore); semGuard tmpGuard(&mySemaphore);
myPages.erase((*myPages.rbegin())); myPages.erase((*myPages.rbegin()));
} }
@ -802,7 +802,7 @@ namespace IPC {
DEBUG_MSG(DLVL_FAIL, "Creating semaphore failed: %s", strerror(errno)); DEBUG_MSG(DLVL_FAIL, "Creating semaphore failed: %s", strerror(errno));
return; return;
} }
semGuard tmpGuard(mySemaphore); semGuard tmpGuard(&mySemaphore);
myPage.init(rhs.myPage.name, rhs.myPage.len, rhs.myPage.master); myPage.init(rhs.myPage.name, rhs.myPage.len, rhs.myPage.master);
offsetOnPage = rhs.offsetOnPage; offsetOnPage = rhs.offsetOnPage;
} }
@ -822,7 +822,7 @@ namespace IPC {
DEBUG_MSG(DLVL_FAIL, "Creating copy of semaphore %s failed: %s", baseName.c_str(), strerror(errno)); DEBUG_MSG(DLVL_FAIL, "Creating copy of semaphore %s failed: %s", baseName.c_str(), strerror(errno));
return; return;
} }
semGuard tmpGuard(mySemaphore); semGuard tmpGuard(&mySemaphore);
myPage.init(rhs.myPage.name, rhs.myPage.len, rhs.myPage.master); myPage.init(rhs.myPage.name, rhs.myPage.len, rhs.myPage.master);
offsetOnPage = rhs.offsetOnPage; offsetOnPage = rhs.offsetOnPage;
} }
@ -842,7 +842,7 @@ namespace IPC {
DEBUG_MSG(DLVL_FAIL, "Creating semaphore %s failed: %s", baseName.c_str(), strerror(errno)); DEBUG_MSG(DLVL_FAIL, "Creating semaphore %s failed: %s", baseName.c_str(), strerror(errno));
return; return;
} }
semGuard tmpGuard(mySemaphore); semGuard tmpGuard(&mySemaphore);
char * empty = 0; char * empty = 0;
if (!hasCounter) { if (!hasCounter) {
empty = (char *)malloc(payLen * sizeof(char)); empty = (char *)malloc(payLen * sizeof(char));

View file

@ -71,11 +71,11 @@ namespace IPC {
///\brief A class used as a semaphore guard ///\brief A class used as a semaphore guard
class semGuard { class semGuard {
public: public:
semGuard(semaphore thisSemaphore); semGuard(semaphore * thisSemaphore);
~semGuard(); ~semGuard();
private: private:
///\brief The semaphore to guard. ///\brief The semaphore to guard.
semaphore mySemaphore; semaphore * mySemaphore;
}; };
#if !defined __APPLE__ #if !defined __APPLE__