35 using namespace basis;
44 #define LOG(tp) printf("%s%s\n", time_stamp::notarize(true).s(), astring(tp).s())
51 {
return root_part +
"_app_lock"; }
59 filename::detooth_filename(clean_name);
63 astring tmp_dir =
"/tmp/rendezvous";
66 return tmp_dir +
"/ren_" + clean_name;
70 rendezvous::rendezvous(
const astring &root_name)
73 _root_name(new
astring(root_name))
75 #ifdef DEBUG_RENDEZVOUS
81 FILE *locking_file = fopen(real_name.
s(),
"wb");
83 #ifdef DEBUG_RENDEZVOUS
84 LOG(
astring(
"failure to create locking file ") + real_name
85 +
": " + critical_events::system_error_text(critical_events::system_error()) );
90 _handle = locking_file;
93 _handle = CreateMutex(
NULL_POINTER,
false, to_unicode_temp(lock_name));
100 #ifdef DEBUG_RENDEZVOUS
102 LOG(
"okay, into destructor for rendezvous.");
107 int ret = lockf(
fileno((FILE *)_handle), F_ULOCK,
sizeof(
int));
109 #ifdef DEBUG_RENDEZVOUS
110 LOG(
"failure to get lock on file.");
122 fclose((FILE *)_handle);
127 if (_handle) CloseHandle((
HANDLE)_handle);
143 #ifdef DEBUG_RENDEZVOUS
149 int command = F_TLOCK;
151 int ret = lockf(
fileno((FILE *)_handle), command,
sizeof(
int));
153 #ifdef DEBUG_RENDEZVOUS
154 LOG(
"failure to get lock on file.");
158 #ifdef DEBUG_RENDEZVOUS
159 LOG(
"okay, got lock on shared mem.");
167 int ret = WaitForSingleObject((
HANDLE)_handle, timing);
168 if ( (ret == WAIT_ABANDONED) || (ret == WAIT_TIMEOUT) )
return false;
169 else if (ret != WAIT_OBJECT_0) {
170 #ifdef DEBUG_RENDEZVOUS
171 LOG(
"got an unanticipated error from waiting for the mutex.");
183 #ifdef DEBUG_RENDEZVOUS
189 int ret = lockf(
fileno((FILE *)_handle), F_ULOCK,
sizeof(
int));
191 #ifdef DEBUG_RENDEZVOUS
192 LOG(
"failure to get lock on file.");
197 ReleaseMutex((
HANDLE)_handle);
201 #ifdef DEBUG_RENDEZVOUS
202 LOG(
"okay, rendezvous wasn't locked.");
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
locking_methods
different ways that the lock() attempt can be made.
virtual void repeal_lock()
bool lock(locking_methods how=ENDLESS_WAIT)
grab the lock, if possible.
bool healthy() const
returns true if the rendezvous object is operable.
void unlock()
releases a previously acquired lock.
virtual void establish_lock()
const basis::astring & root_name() const
returns the root name passed in the constructor.
virtual ~rendezvous()
any lock held is released and the lower level structures freed.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
A platform independent way to obtain the timestamp of a file.
astring general_lock_name(const astring &root_part)
astring unix_rendez_file(const astring &lock_name)
Support for unicode builds.
Aids in achievement of platform independence.