Skip to content

Commit a7342a8

Browse files
authored
Fixes for packaging steps (#215)
- Replaced std mutex with our own app mutex in app/src/heartbeat_date_storage_desktop.cc. - Removed heartbeat code from Android builds.
1 parent 7e66247 commit a7342a8

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

app/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ set(common_SRCS
135135
src/function_registry.cc
136136
src/future.cc
137137
src/future_manager.cc
138-
src/heartbeat_date_storage_desktop.cc
139-
src/heartbeat_info_desktop.cc
140138
src/path.cc
141139
src/reference_counted_future_impl.cc
142140
src/scheduler.cc
@@ -164,11 +162,15 @@ set(app_android_SRCS
164162
set(app_ios_SRCS
165163
src/app_ios.mm
166164
src/util_ios.mm
165+
src/heartbeat_date_storage_desktop.cc
166+
src/heartbeat_info_desktop.cc
167167
src/invites/ios/invites_receiver_internal_ios.mm
168168
src/invites/ios/invites_ios_startup.mm
169169
src/uuid_ios_darwin.mm)
170170
set(app_desktop_SRCS
171171
src/app_desktop.cc
172+
src/heartbeat_date_storage_desktop.cc
173+
src/heartbeat_info_desktop.cc
172174
src/invites/stub/invites_receiver_internal_stub.cc
173175
src/variant_util.cc)
174176
if(ANDROID)

app/src/heartbeat_date_storage_desktop.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <fstream>
2020
#include <utility>
2121

22+
#include <app/src/mutex.h>
23+
2224
#include "app/src/filesystem.h"
2325

2426
namespace FIREBASE_NAMESPACE {
@@ -29,8 +31,8 @@ const char kHeartbeatDir[] = "firebase-heartbeat";
2931
const char kHeartbeatFilename[] = "HEARTBEAT_INFO_STORAGE";
3032

3133
// Returns the mutex that protects accesses to the storage file.
32-
std::mutex& FileMutex() {
33-
static std::mutex* mutex_ = new std::mutex();
34+
Mutex& FileMutex() {
35+
static Mutex* mutex_ = new Mutex(Mutex::kModeNonRecursive);
3436
return *mutex_;
3537
}
3638

@@ -47,7 +49,7 @@ std::string GetFilename(std::string& error) {
4749
} // namespace
4850

4951
HeartbeatDateStorage::HeartbeatDateStorage() : filename_(GetFilename(error_)) {
50-
std::lock_guard<std::mutex> lock(FileMutex());
52+
MutexLock lock(FileMutex());
5153

5254
// Ensure the file exists, otherwise the first attempt to read it would
5355
// fail.
@@ -69,7 +71,7 @@ bool HeartbeatDateStorage::ReadPersisted() {
6971

7072
HeartbeatMap result;
7173

72-
std::lock_guard<std::mutex> lock(FileMutex());
74+
MutexLock lock(FileMutex());
7375

7476
std::ifstream f(filename_);
7577
if (!f) {
@@ -102,7 +104,7 @@ bool HeartbeatDateStorage::ReadPersisted() {
102104
bool HeartbeatDateStorage::WritePersisted() const {
103105
if (!IsValid()) return false;
104106

105-
std::lock_guard<std::mutex> lock(FileMutex());
107+
MutexLock lock(FileMutex());
106108

107109
std::ofstream f(filename_, std::ios_base::trunc);
108110
if (!f) {

app/src/heartbeat_date_storage_desktop.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include <ctime>
2525
#include <map>
26-
#include <mutex> // NOLINT(build/c++11)
2726
#include <string>
2827

2928
namespace FIREBASE_NAMESPACE {

0 commit comments

Comments
 (0)