irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

locks.cpp
Go to the documentation of this file.
1 /* For copyright information please refer to files in the COPYRIGHT directory
2  */
3 #include "locks.hpp"
4 #include "rodsConnect.h"
5 //#include "filesystem.hpp"
6 //#include "utils.hpp"
7 #include "irods_log.hpp"
9 
10 int lockWriteMutex( const char* _inst_name, mutex_type **mutex ) {
11  std::string mutex_name;
12  irods::error ret = getMutexName( _inst_name, mutex_name );
13  if ( !ret.ok() ) {
14  rodsLog( LOG_ERROR, "lockMutex: call to getMutexName failed" );
15  return -1;
16  }
17 
18  try {
19  *mutex = new mutex_type( boost::interprocess::open_or_create, mutex_name.c_str() );
20  }
21  catch ( const boost::interprocess::interprocess_exception& ) {
22  rodsLog( LOG_ERROR, "boost::interprocess::named_mutex threw a boost::interprocess::interprocess_exception." );
23  return -1;
24  }
25  try {
26  ( *mutex )->lock();
27  }
28  catch ( const boost::interprocess::interprocess_exception& ) {
29  rodsLog( LOG_ERROR, "lock threw a boost::interprocess::interprocess_exception." );
30  return -1;
31  }
32  return 0;
33 }
34 
35 int lockReadMutex( const char* _inst_name, mutex_type **mutex ) {
36  std::string mutex_name;
37  irods::error ret = getMutexName( _inst_name, mutex_name );
38  if ( !ret.ok() ) {
39  rodsLog( LOG_ERROR, "lockMutex: call to getMutexName failed" );
40  return -1;
41  }
42 
43  try {
44  *mutex = new mutex_type( boost::interprocess::open_or_create, mutex_name.c_str() );
45  }
46  catch ( const boost::interprocess::interprocess_exception& ) {
47  rodsLog( LOG_ERROR, "boost::interprocess::named_mutex threw a boost::interprocess::interprocess_exception." );
48  return -1;
49  }
50  try {
51  ( *mutex )->lock_sharable();
52  }
53  catch ( const boost::interprocess::interprocess_exception& ) {
54  rodsLog( LOG_ERROR, "lock threw a boost::interprocess::interprocess_exception." );
55  return -1;
56  }
57  return 0;
58 }
59 
60 void unlockWriteMutex( const char* _inst_name, mutex_type **mutex ) {
61  try {
62  ( *mutex )->unlock();
63  }
64  catch ( const boost::interprocess::interprocess_exception& ) {
65  rodsLog( LOG_ERROR, "unlock threw a boost::interprocess::interprocess_exception." );
66  }
67  delete *mutex;
68 }
69 
70 void unlockReadMutex( const char* _inst_name, mutex_type **mutex ) {
71  try {
72  ( *mutex )->unlock_sharable();
73  }
74  catch ( const boost::interprocess::interprocess_exception& ) {
75  rodsLog( LOG_ERROR, "unlock threw a boost::interprocess::interprocess_exception." );
76  }
77  delete *mutex;
78 }
79 
80 /* This function can be used during initialization to remove a previously held mutex that has not been released.
81  * This should only be used when there is no other process using the mutex */
82 void resetMutex(const char* _inst_name) {
83  std::string mutex_name;
84  irods::error ret = getMutexName( _inst_name, mutex_name );
85  if ( !ret.ok() ) {
86  rodsLog( LOG_ERROR, "resetMutex: call to getMutexName failed" );
87  }
88 
89  mutex_type::remove( mutex_name.c_str() );
90 }
91 
92 irods::error getMutexName( const char* _inst_name, std::string &mutex_name ) {
93  try {
94  const auto& mutex_name_salt = irods::get_server_property<const std::string>(irods::CFG_RE_CACHE_SALT_KW);
95  mutex_name = "irods_re_cache_mutex_";
96  mutex_name += _inst_name;
97  mutex_name += "_";
98  mutex_name += mutex_name_salt;
99  } catch ( const irods::exception& e ) {
100  rodsLog( LOG_ERROR, "getMutexName: failed to retrieve re cache salt from server_properties\n%s", e.what() );
101  return irods::error(e);
102  }
103  return SUCCESS();
104 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
irods_server_properties.hpp
locks.hpp
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
rodsConnect.h
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
lockReadMutex
int lockReadMutex(const char *_inst_name, mutex_type **mutex)
Definition: locks.cpp:35
unlockWriteMutex
void unlockWriteMutex(const char *_inst_name, mutex_type **mutex)
Definition: locks.cpp:60
getMutexName
irods::error getMutexName(const char *_inst_name, std::string &mutex_name)
Definition: locks.cpp:92
mutex_type
boost::interprocess::named_sharable_mutex mutex_type
Definition: locks.hpp:11
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
resetMutex
void resetMutex(const char *_inst_name)
Definition: locks.cpp:82
irods::error
Definition: irods_error.hpp:23
irods::experimental::filesystem::client::remove
auto remove(rcComm_t &_comm, const path &_p, remove_options _opts=remove_options::none) -> bool
Definition: filesystem.cpp:699
error
int error
Definition: filesystem.cpp:101
irods::exception
Definition: irods_exception.hpp:15
irods::CFG_RE_CACHE_SALT_KW
const std::string CFG_RE_CACHE_SALT_KW("reCacheSalt")
unlockReadMutex
void unlockReadMutex(const char *_inst_name, mutex_type **mutex)
Definition: locks.cpp:70
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_log.hpp
lockWriteMutex
int lockWriteMutex(const char *_inst_name, mutex_type **mutex)
Definition: locks.cpp:10