-
Notifications
You must be signed in to change notification settings - Fork 122
Split mutex.h into .h and .cc files #751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
315c1a9
Split mutex.h into .h and .cc files
dconeybe efe86d7
user_secure_windows_internal.cc: reorder includes to make lint happy
dconeybe 52725c5
user_secure_fake_internal.cc: add missing include: app/src/log.h
dconeybe 88bed53
Add missing include to noop_persistence_manager.cc: app/src/assert.h
dconeybe f634583
Merge main branch at 4b090f4d84b4fc73e9c19a8f5cc1db931e0e122e
dconeybe 83a8028
Empty commit to re-trigger GitHub Actions.
dconeybe e1ed0bb
Empty commit to re-trigger GitHub Actions.
dconeybe 2badd11
Merge main branch at 65f30685c53c4cf9d819e686e64136151c92f7a9 to pick…
dconeybe 280d7d1
Merge main branch at 483c74a4047a46a676204dc9f03893302bbcc81d
dconeybe 8b3e7e0
Empty commit to re-trigger GitHub Actions.
dconeybe 439382b
Empty commit to re-trigger GitHub Actions.
dconeybe 7f70ba5
Add documentation for Mutex::Acquire() and Mutex::Release()
dconeybe 0683feb
Invert the #if FIREBASE_PLATFORM_WINDOWS checks, since it is more int…
dconeybe 3a13469
Remove an unnecessary NOLINTNEXTLINE comment
dconeybe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <errno.h> | ||
#include <pthread.h> | ||
|
||
#include "app/src/assert.h" | ||
#include "app/src/mutex.h" | ||
|
||
namespace firebase { | ||
|
||
Mutex::Mutex(Mode mode) { | ||
pthread_mutexattr_t attr; | ||
int ret = pthread_mutexattr_init(&attr); | ||
FIREBASE_ASSERT(ret == 0); | ||
if (mode & kModeRecursive) { | ||
ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); | ||
FIREBASE_ASSERT(ret == 0); | ||
} | ||
ret = pthread_mutex_init(&mutex_, &attr); | ||
FIREBASE_ASSERT(ret == 0); | ||
ret = pthread_mutexattr_destroy(&attr); | ||
FIREBASE_ASSERT(ret == 0); | ||
} | ||
|
||
Mutex::~Mutex() { | ||
int ret = pthread_mutex_destroy(&mutex_); | ||
FIREBASE_ASSERT(ret == 0); | ||
(void)ret; | ||
} | ||
|
||
void Mutex::Acquire() { | ||
int ret = pthread_mutex_lock(&mutex_); | ||
if (ret == EINVAL) { | ||
return; | ||
} | ||
#if defined(__APPLE__) | ||
// Lock / unlock will fail in a static initializer on OSX and iOS. | ||
FIREBASE_ASSERT(ret == 0 || ret == EINVAL); | ||
#else | ||
FIREBASE_ASSERT(ret == 0); | ||
#endif // defined(__APPLE__) | ||
(void)ret; | ||
} | ||
|
||
void Mutex::Release() { | ||
int ret = pthread_mutex_unlock(&mutex_); | ||
#if defined(__APPLE__) | ||
// Lock / unlock will fail in a static initializer on OSX and iOS. | ||
FIREBASE_ASSERT(ret == 0 || ret == EINVAL); | ||
#else | ||
FIREBASE_ASSERT(ret == 0); | ||
#endif // defined(__APPLE__) | ||
(void)ret; | ||
} | ||
|
||
} // namespace firebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <windows.h> | ||
|
||
#include "app/src/assert.h" | ||
#include "app/src/include/firebase/internal/platform.h" | ||
#include "app/src/mutex.h" | ||
|
||
namespace firebase { | ||
|
||
Mutex::Mutex(Mode mode) : mode_(mode) { | ||
if (mode & kModeRecursive) { | ||
synchronization_object_ = CreateMutex(nullptr, FALSE, nullptr); | ||
} else { | ||
synchronization_object_ = CreateSemaphore(nullptr, 1, 1, nullptr); | ||
} | ||
} | ||
|
||
Mutex::~Mutex() { CloseHandle(synchronization_object_); } | ||
|
||
void Mutex::Acquire() { | ||
DWORD ret = WaitForSingleObject(synchronization_object_, INFINITE); | ||
FIREBASE_ASSERT(ret == WAIT_OBJECT_0); | ||
(void)ret; | ||
} | ||
|
||
void Mutex::Release() { | ||
if (mode_ & kModeRecursive) { | ||
ReleaseMutex(synchronization_object_); | ||
} else { | ||
ReleaseSemaphore(synchronization_object_, 1, 0); | ||
} | ||
} | ||
|
||
} // namespace firebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but maybe add a short comment above each one as long as we're in here.