// Map the database file and signal start. // Open is not idempotent (should be called on single thread). bool file_storage::open() { // Critical Section /////////////////////////////////////////////////////////////////////////// mutex_.lock_upgrade(); if (!closed_) { mutex_.unlock_upgrade(); //--------------------------------------------------------------------- return false; } mutex_.unlock_upgrade_and_lock(); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ std::string error_name; // Initialize data_. if (!map(file_size_)) error_name = "map"; else if (madvise(data_, 0, MADV_RANDOM) == FAIL) error_name = "madvise"; else closed_ = false; mutex_.unlock(); /////////////////////////////////////////////////////////////////////////// // Keep logging out of the critical section. if (!error_name.empty()) return handle_error(error_name, filename_); log_mapping(); return true; }
// Map the database file and signal start. bool memory_map::open() { // Critical Section (internal/unconditional) /////////////////////////////////////////////////////////////////////////// mutex_.lock_upgrade(); if (!closed_) { mutex_.unlock_upgrade(); //--------------------------------------------------------------------- // Open is not idempotent (should be called on single thread). return false; } mutex_.unlock_upgrade_and_lock(); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ std::string error_name; // Initialize data_. if (!map(file_size_)) error_name = "map"; else if (madvise(data_, 0, MADV_RANDOM) == FAIL) error_name = "madvise"; else closed_ = false; mutex_.unlock(); /////////////////////////////////////////////////////////////////////////// // Keep logging out of the critical section. if (!error_name.empty()) return handle_error(error_name, filename_); log_mapping(); return true; }