* bsd_mutex.cc (_msleep): Simplify event creation. Revert change from
2004-08-24. It should be unnecessary now. * msg.cc (client_request_msg::serve): Release process critical section as early as possible. * sem.cc (client_request_sem::serve): Ditto. * shm.cc (client_request_shm::serve): Ditto. * process.cc: Use hold and release method calls instead of EnterCriticalSection/LeaveCriticalSection calls throughout. * process.h (_hold): Rename from hold. Take filename and linenumber parameter for logging. Define matching hold macro. (release): Ditto.
This commit is contained in:
parent
3ea9de7644
commit
1f8b30497d
|
@ -1,3 +1,17 @@
|
||||||
|
2004-10-04 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* bsd_mutex.cc (_msleep): Simplify event creation. Revert change from
|
||||||
|
2004-08-24. It should be unnecessary now.
|
||||||
|
* msg.cc (client_request_msg::serve): Release process critical
|
||||||
|
section as early as possible.
|
||||||
|
* sem.cc (client_request_sem::serve): Ditto.
|
||||||
|
* shm.cc (client_request_shm::serve): Ditto.
|
||||||
|
* process.cc: Use hold and release method calls instead of
|
||||||
|
EnterCriticalSection/LeaveCriticalSection calls throughout.
|
||||||
|
* process.h (_hold): Rename from hold. Take filename and linenumber
|
||||||
|
parameter for logging. Define matching hold macro.
|
||||||
|
(release): Ditto.
|
||||||
|
|
||||||
2004-10-01 Corinna Vinschen <corinna@vinschen.de>
|
2004-10-01 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* sysv_sem.cc: Update to FreeBSD version 1.69.
|
* sysv_sem.cc: Update to FreeBSD version 1.69.
|
||||||
|
|
|
@ -180,9 +180,7 @@ _msleep (void *ident, struct mtx *mtx, int priority,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char name[64];
|
char name[64];
|
||||||
msleep_event_name (ident, name);
|
msleep_event_name (ident, name);
|
||||||
HANDLE evt = OpenEvent (EVENT_ALL_ACCESS, FALSE, name);
|
HANDLE evt = CreateEvent (NULL, TRUE, FALSE, name);
|
||||||
if (!evt)
|
|
||||||
evt = CreateEvent (NULL, TRUE, FALSE, name);
|
|
||||||
if (!evt)
|
if (!evt)
|
||||||
panic ("CreateEvent in msleep (%s) failed: %E", wmesg);
|
panic ("CreateEvent in msleep (%s) failed: %E", wmesg);
|
||||||
if (mtx)
|
if (mtx)
|
||||||
|
@ -201,7 +199,6 @@ _msleep (void *ident, struct mtx *mtx, int priority,
|
||||||
if ((priority & PCATCH)
|
if ((priority & PCATCH)
|
||||||
&& td->client->signal_arrived () != INVALID_HANDLE_VALUE)
|
&& td->client->signal_arrived () != INVALID_HANDLE_VALUE)
|
||||||
obj_cnt = 4;
|
obj_cnt = 4;
|
||||||
td->client->release ();
|
|
||||||
switch (WaitForMultipleObjects (obj_cnt, obj, FALSE, timo ?: INFINITE))
|
switch (WaitForMultipleObjects (obj_cnt, obj, FALSE, timo ?: INFINITE))
|
||||||
{
|
{
|
||||||
case WAIT_OBJECT_0: /* wakeup() has been called. */
|
case WAIT_OBJECT_0: /* wakeup() has been called. */
|
||||||
|
@ -233,7 +230,6 @@ _msleep (void *ident, struct mtx *mtx, int priority,
|
||||||
ResetEvent (evt);
|
ResetEvent (evt);
|
||||||
#endif
|
#endif
|
||||||
CloseHandle (evt);
|
CloseHandle (evt);
|
||||||
td->client->hold ();
|
|
||||||
set_priority (old_priority);
|
set_priority (old_priority);
|
||||||
if (mtx && !(priority & PDROP))
|
if (mtx && !(priority & PDROP))
|
||||||
mtx_lock (mtx);
|
mtx_lock (mtx);
|
||||||
|
|
|
@ -72,6 +72,7 @@ client_request_msg::serve (transport_layer_base *const conn,
|
||||||
}
|
}
|
||||||
if (!adjust_identity_info (&_parameters.in.ipcblk))
|
if (!adjust_identity_info (&_parameters.in.ipcblk))
|
||||||
{
|
{
|
||||||
|
client->release ();
|
||||||
conn->revert_to_self ();
|
conn->revert_to_self ();
|
||||||
error_code (EACCES);
|
error_code (EACCES);
|
||||||
msglen (0);
|
msglen (0);
|
||||||
|
@ -79,6 +80,8 @@ client_request_msg::serve (transport_layer_base *const conn,
|
||||||
}
|
}
|
||||||
/* Early revert_to_self since IPC code runs in kernel mode. */
|
/* Early revert_to_self since IPC code runs in kernel mode. */
|
||||||
conn->revert_to_self ();
|
conn->revert_to_self ();
|
||||||
|
/* sysv_msg.cc takes care of itself. */
|
||||||
|
client->release ();
|
||||||
thread td = { client, &_parameters.in.ipcblk, {-1, -1} };
|
thread td = { client, &_parameters.in.ipcblk, {-1, -1} };
|
||||||
int res;
|
int res;
|
||||||
msgop_t msgop = _parameters.in.msgop; /* Get's overwritten otherwise. */
|
msgop_t msgop = _parameters.in.msgop; /* Get's overwritten otherwise. */
|
||||||
|
@ -104,7 +107,6 @@ client_request_msg::serve (transport_layer_base *const conn,
|
||||||
/* Allocated by the call to adjust_identity_info(). */
|
/* Allocated by the call to adjust_identity_info(). */
|
||||||
if (_parameters.in.ipcblk.gidlist)
|
if (_parameters.in.ipcblk.gidlist)
|
||||||
free (_parameters.in.ipcblk.gidlist);
|
free (_parameters.in.ipcblk.gidlist);
|
||||||
client->release ();
|
|
||||||
error_code (res);
|
error_code (res);
|
||||||
if (msgop == MSGOP_msgrcv)
|
if (msgop == MSGOP_msgrcv)
|
||||||
_parameters.out.rcv = td.td_retval[0];
|
_parameters.out.rcv = td.td_retval[0];
|
||||||
|
|
|
@ -69,10 +69,12 @@ process::process (const pid_t cygpid, const DWORD winpid, HANDLE signal_arrived)
|
||||||
GetLastError ());
|
GetLastError ());
|
||||||
}
|
}
|
||||||
InitializeCriticalSection (&_access);
|
InitializeCriticalSection (&_access);
|
||||||
|
debug ("initialized (%lu)", _cygpid);
|
||||||
}
|
}
|
||||||
|
|
||||||
process::~process ()
|
process::~process ()
|
||||||
{
|
{
|
||||||
|
debug ("deleting (%lu)", _cygpid);
|
||||||
DeleteCriticalSection (&_access);
|
DeleteCriticalSection (&_access);
|
||||||
CloseHandle (_signal_arrived);
|
CloseHandle (_signal_arrived);
|
||||||
CloseHandle (_hProcess);
|
CloseHandle (_hProcess);
|
||||||
|
@ -105,7 +107,7 @@ process::add (cleanup_routine *const entry)
|
||||||
assert (entry);
|
assert (entry);
|
||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
EnterCriticalSection (&_access);
|
hold ();
|
||||||
|
|
||||||
if (!_cleaning_up)
|
if (!_cleaning_up)
|
||||||
{
|
{
|
||||||
|
@ -114,7 +116,7 @@ process::add (cleanup_routine *const entry)
|
||||||
res = true;
|
res = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LeaveCriticalSection (&_access);
|
release ();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +126,7 @@ process::remove (const cleanup_routine *const entry)
|
||||||
assert (entry);
|
assert (entry);
|
||||||
|
|
||||||
bool res = false;
|
bool res = false;
|
||||||
EnterCriticalSection (&_access);
|
hold ();
|
||||||
|
|
||||||
if (!_cleaning_up)
|
if (!_cleaning_up)
|
||||||
{
|
{
|
||||||
|
@ -148,7 +150,7 @@ process::remove (const cleanup_routine *const entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LeaveCriticalSection (&_access);
|
release ();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,13 +161,13 @@ process::remove (const cleanup_routine *const entry)
|
||||||
void
|
void
|
||||||
process::cleanup ()
|
process::cleanup ()
|
||||||
{
|
{
|
||||||
EnterCriticalSection (&_access);
|
hold ();
|
||||||
assert (!is_active ());
|
assert (!is_active ());
|
||||||
assert (!_cleaning_up);
|
assert (!_cleaning_up);
|
||||||
InterlockedExchange (&_cleaning_up, true);
|
InterlockedExchange (&_cleaning_up, true);
|
||||||
cleanup_routine *entry = _routines_head;
|
cleanup_routine *entry = _routines_head;
|
||||||
_routines_head = NULL;
|
_routines_head = NULL;
|
||||||
LeaveCriticalSection (&_access);
|
release ();
|
||||||
|
|
||||||
while (entry)
|
while (entry)
|
||||||
{
|
{
|
||||||
|
@ -275,7 +277,7 @@ process_cache::process (const pid_t cygpid, const DWORD winpid,
|
||||||
SetEvent (_cache_add_trigger);
|
SetEvent (_cache_add_trigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
EnterCriticalSection (&entry->_access); // To be released by the caller.
|
entry->hold (); // To be released by the caller.
|
||||||
LeaveCriticalSection (&_cache_write_access);
|
LeaveCriticalSection (&_cache_write_access);
|
||||||
assert (entry);
|
assert (entry);
|
||||||
assert (entry->_winpid == winpid);
|
assert (entry->_winpid == winpid);
|
||||||
|
|
|
@ -65,6 +65,9 @@ private:
|
||||||
|
|
||||||
class process_cache;
|
class process_cache;
|
||||||
|
|
||||||
|
#define hold() _hold(__FILE__,__LINE__)
|
||||||
|
#define release() _release(__FILE__,__LINE__)
|
||||||
|
|
||||||
class process
|
class process
|
||||||
{
|
{
|
||||||
friend class process_cache;
|
friend class process_cache;
|
||||||
|
@ -82,8 +85,15 @@ public:
|
||||||
|
|
||||||
bool is_active () const { return _exit_status == STILL_ACTIVE; }
|
bool is_active () const { return _exit_status == STILL_ACTIVE; }
|
||||||
|
|
||||||
void hold () { EnterCriticalSection (&_access); }
|
void _hold (const char *file, int line) {
|
||||||
void release () { LeaveCriticalSection (&_access); }
|
_log (file, line, LOG_DEBUG, "Try hold(%lu)", _cygpid);
|
||||||
|
EnterCriticalSection (&_access);
|
||||||
|
_log (file, line, LOG_DEBUG, "holding (%lu)", _cygpid);
|
||||||
|
}
|
||||||
|
void _release (const char *file, int line) {
|
||||||
|
_log (file, line, LOG_DEBUG, "leaving (%lu)", _cygpid);
|
||||||
|
LeaveCriticalSection (&_access);
|
||||||
|
}
|
||||||
|
|
||||||
bool add (cleanup_routine *);
|
bool add (cleanup_routine *);
|
||||||
bool remove (const cleanup_routine *);
|
bool remove (const cleanup_routine *);
|
||||||
|
|
|
@ -77,6 +77,8 @@ client_request_sem::serve (transport_layer_base *const conn,
|
||||||
}
|
}
|
||||||
/* Early revert_to_self since IPC code runs in kernel mode. */
|
/* Early revert_to_self since IPC code runs in kernel mode. */
|
||||||
conn->revert_to_self ();
|
conn->revert_to_self ();
|
||||||
|
/* sysv_sem.cc takes care of itself. */
|
||||||
|
client->release ();
|
||||||
thread td = { client, &_parameters.in.ipcblk, {-1, -1} };
|
thread td = { client, &_parameters.in.ipcblk, {-1, -1} };
|
||||||
int res;
|
int res;
|
||||||
switch (_parameters.in.semop)
|
switch (_parameters.in.semop)
|
||||||
|
@ -98,7 +100,6 @@ client_request_sem::serve (transport_layer_base *const conn,
|
||||||
/* Allocated by the call to adjust_identity_info(). */
|
/* Allocated by the call to adjust_identity_info(). */
|
||||||
if (_parameters.in.ipcblk.gidlist)
|
if (_parameters.in.ipcblk.gidlist)
|
||||||
free (_parameters.in.ipcblk.gidlist);
|
free (_parameters.in.ipcblk.gidlist);
|
||||||
client->release ();
|
|
||||||
error_code (res);
|
error_code (res);
|
||||||
_parameters.out.ret = td.td_retval[0];
|
_parameters.out.ret = td.td_retval[0];
|
||||||
msglen (sizeof (_parameters.out));
|
msglen (sizeof (_parameters.out));
|
||||||
|
|
|
@ -80,6 +80,8 @@ client_request_shm::serve (transport_layer_base *const conn,
|
||||||
}
|
}
|
||||||
/* Early revert_to_self since IPC code runs in kernel mode. */
|
/* Early revert_to_self since IPC code runs in kernel mode. */
|
||||||
conn->revert_to_self ();
|
conn->revert_to_self ();
|
||||||
|
/* sysv_shm.cc takes care of itself. */
|
||||||
|
client->release ();
|
||||||
thread td = { client, &_parameters.in.ipcblk, {0, 0} };
|
thread td = { client, &_parameters.in.ipcblk, {0, 0} };
|
||||||
int res;
|
int res;
|
||||||
shmop_t shmop = _parameters.in.shmop; /* Get's overwritten otherwise. */
|
shmop_t shmop = _parameters.in.shmop; /* Get's overwritten otherwise. */
|
||||||
|
@ -110,7 +112,6 @@ client_request_shm::serve (transport_layer_base *const conn,
|
||||||
/* Allocated by the call to adjust_identity_info(). */
|
/* Allocated by the call to adjust_identity_info(). */
|
||||||
if (_parameters.in.ipcblk.gidlist)
|
if (_parameters.in.ipcblk.gidlist)
|
||||||
free (_parameters.in.ipcblk.gidlist);
|
free (_parameters.in.ipcblk.gidlist);
|
||||||
client->release ();
|
|
||||||
error_code (res);
|
error_code (res);
|
||||||
if (shmop == SHMOP_shmat)
|
if (shmop == SHMOP_shmat)
|
||||||
_parameters.out.ptr = td.td_retval[0];
|
_parameters.out.ptr = td.td_retval[0];
|
||||||
|
|
Loading…
Reference in New Issue