Skip to content

Commit

Permalink
2002-04-30 Dick Porter <dick@ximian.com>
Browse files Browse the repository at this point in the history
	* Completely rewrote the handle waiting code: removed the helper
	thread and its attendant complexity.  All handle waiting is now
	abstracted into the WaitForSingleObject() and
	WaitForMultipleObjects() functions.

	* Implemented inter-process sharing of handles using sysv shared
	memory.  This makes handles even more opaque, with a handle now
	just an index into an array.

2002-04-30  Dick Porter  <dick@ximian.com>

	* socket-io.c: Cope with SOCKET being an integer rather than a
	pointer now.

	* threads.c: Added Thread_free_internal, to deal with thread
	handle cleanup.  Moved calls to handle_store() and handle_remove()
	to start_wrapper(), so each can only be called once.  Allocate
	synchronisation blocks with GC_malloc(), and use GC finalisation
	to close the handles.

	* icall.c: added System.Threading.Thread::Thread_free_internal

2002-04-30  Dick Porter  <dick@ximian.com>

	* acconfig.h:
	* configure.in: Added option to disable using shared memory for
	handles

2002-04-30  Dick Porter  <dick@ximian.com>

	* shmdel.c:
	* scratch.c:
	* hps.c:
	* Makefile.am: Some tools to help debug shared memory handles:
	'hps' shows handle status, 'scratch' displays info about scratch
	data (such as handle names), 'shmdel' deletes the shared memory
	segment.

2002-04-30  Dick Porter  <dick@ximian.com>

	* interp.c: Tell glib to not abort when g_log() etc print
	recursively

2002-04-30  Dick Porter  <dick@ximian.com>

	* mono.c (main): Tell glib to not abort when g_log() etc print
	recursively

svn path=/trunk/mono/; revision=4166
  • Loading branch information
dickp committed Apr 30, 2002
1 parent 0916c59 commit 94ddc5e
Show file tree
Hide file tree
Showing 61 changed files with 3,837 additions and 2,170 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
2002-04-30 Dick Porter <dick@ximian.com>

* acconfig.h:
* configure.in: Added option to disable using shared memory for
handles

2002-04-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* configure.in: fix for conditional "THREADS_PTHREAD" was never
Expand Down
1 change: 1 addition & 0 deletions acconfig.h
Expand Up @@ -13,3 +13,4 @@
#undef NAME_DEV_RANDOM
#undef HAVE_CRYPT_RNG
#undef HAVE_BOEHM_GC
#undef DISABLE_SHARED_HANDLES
9 changes: 9 additions & 0 deletions configure.in
Expand Up @@ -432,6 +432,14 @@ else
fi
fi

AC_MSG_CHECKING([if inter-process shared handles are requested])
AC_ARG_ENABLE(shared-handles, [ --disable-shared-handles disable inter-process shared handles], try_shared_handles=$enableval, try_shared_handles=yes)
AC_MSG_RESULT($try_shared_handles)
if test "x$try_shared_handles" != "xyes"; then
AC_DEFINE(DISABLE_SHARED_HANDLES)
AC_SUBST(DISABLE_SHARED_HANDLES)
fi

TARGET="unknown"
ACCESS_UNALIGNED="yes"

Expand Down Expand Up @@ -485,6 +493,7 @@ mono/monoburg/Makefile
mono/monograph/Makefile
mono/jit/Makefile
mono/io-layer/Makefile
mono/handles/Makefile
runtime/Makefile
scripts/Makefile
man/Makefile
Expand Down
7 changes: 6 additions & 1 deletion mono/Makefile.am
@@ -1,4 +1,9 @@
# the handles dir doesn't apply to windows
if PLATFORM_WIN32
SUBDIRS = utils io-layer monoburg metadata cil dis \
arch monograph interpreter jit tests benchmark

else
SUBDIRS = utils io-layer monoburg metadata cil dis \
arch monograph interpreter jit tests benchmark handles
endif

7 changes: 7 additions & 0 deletions mono/handles/.cvsignore
@@ -0,0 +1,7 @@
.deps
.libs
Makefile
Makefile.in
hps
scratch
shmdel
10 changes: 10 additions & 0 deletions mono/handles/ChangeLog
@@ -0,0 +1,10 @@
2002-04-30 Dick Porter <dick@ximian.com>

* shmdel.c:
* scratch.c:
* hps.c:
* Makefile.am: Some tools to help debug shared memory handles:
'hps' shows handle status, 'scratch' displays info about scratch
data (such as handle names), 'shmdel' deletes the shared memory
segment.

28 changes: 28 additions & 0 deletions mono/handles/Makefile.am
@@ -0,0 +1,28 @@

noinst_PROGRAMS = hps scratch shmdel

INCLUDES = \
-I$(top_srcdir) \
$(GMODULE_CFLAGS) \
$(GLIB_CFLAGS)

hps_LDADD = \
../io-layer/libwapi.a \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
-lm

scratch_LDADD = \
../io-layer/libwapi.a \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
-lm

shmdel_LDADD = \
../io-layer/libwapi.a \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
-lm

EXTRA_DIST = ChangeLog

196 changes: 196 additions & 0 deletions mono/handles/hps.c
@@ -0,0 +1,196 @@
#include <config.h>
#include <glib.h>

#include <mono/io-layer/io-layer.h>

/* We're digging into handle internals here... */
#include <mono/io-layer/handles-private.h>
#include <mono/io-layer/wapi-private.h>

static const guchar *unused_details (struct _WapiHandleShared *handle);
static const guchar *file_details (struct _WapiHandleShared *handle);
static const guchar *console_details (struct _WapiHandleShared *handle);
static const guchar *thread_details (struct _WapiHandleShared *handle);
static const guchar *sem_details (struct _WapiHandleShared *handle);
static const guchar *mutex_details (struct _WapiHandleShared *handle);
static const guchar *event_details (struct _WapiHandleShared *handle);
static const guchar *socket_details (struct _WapiHandleShared *handle);
static const guchar *find_details (struct _WapiHandleShared *handle);
static const guchar *process_details (struct _WapiHandleShared *handle);

/* This depends on the ordering of the enum WapiHandleType in
* io-layer/wapi-private.h
*/
static const char *typename[]={
"Unused",
"File",
"Console",
"Thread",
"Sem",
"Mutex",
"Event",
"Socket",
"Find",
"Process",
"Error!!"
};

/* So does this... */
static const guchar * (*details[])(struct _WapiHandleShared *)=
{
unused_details,
file_details,
console_details,
thread_details,
sem_details,
mutex_details,
event_details,
socket_details,
find_details,
process_details,
unused_details,
};

int main (int argc, char **argv)
{
guint32 idx;
guint32 scratch_size;

_wapi_shared_data=_wapi_shm_attach (&scratch_size);

_wapi_handle_shared_lock ();

/* Make sure index 0 is actually unused */
for(idx=0; idx<_WAPI_MAX_HANDLES; idx++) {
struct _WapiHandleShared *shared=&_wapi_shared_data->handles[idx];

if(shared->type!=WAPI_HANDLE_UNUSED) {
g_print ("%4x [%7s] %4u %s (%s)\n", idx,
typename[shared->type], shared->ref,
shared->signalled?"Sg":"Un",
details[shared->type](shared));
}
}

_wapi_handle_shared_unlock ();

exit (0);
}

static const guchar *unused_details (struct _WapiHandleShared *handle)
{
return("unused details");
}

static const guchar *file_details (struct _WapiHandleShared *handle)
{
static guchar buf[80];
guchar *name;
struct _WapiHandle_file *file=&handle->u.file;

name=_wapi_handle_scratch_lookup_as_string (file->filename);

g_snprintf (buf, sizeof(buf),
"[%20s] acc: %c%c%c, shr: %c%c%c, attrs: %5u",
name==NULL?(guchar *)"":name,
file->fileaccess&GENERIC_READ?'R':'.',
file->fileaccess&GENERIC_WRITE?'W':'.',
file->fileaccess&GENERIC_EXECUTE?'X':'.',
file->sharemode&FILE_SHARE_READ?'R':'.',
file->sharemode&FILE_SHARE_WRITE?'W':'.',
file->sharemode&FILE_SHARE_DELETE?'D':'.',
file->attrs);

if(name!=NULL) {
g_free (name);
}

return(buf);
}

static const guchar *console_details (struct _WapiHandleShared *handle)
{
return(file_details (handle));
}

static const guchar *thread_details (struct _WapiHandleShared *handle)
{
static guchar buf[80];
struct _WapiHandle_thread *thr=&handle->u.thread;

g_snprintf (buf, sizeof(buf),
"proc: %p, state: %d, exit: %u, join: %s",
thr->process_handle, thr->state, thr->exitstatus,
thr->joined?"TRUE":"FALSE");

return(buf);
}

static const guchar *sem_details (struct _WapiHandleShared *handle)
{
static guchar buf[80];
struct _WapiHandle_sem *sem=&handle->u.sem;

g_snprintf (buf, sizeof(buf), "val: %5u, max: %5d",
sem->val, sem->max);

return(buf);
}

static const guchar *mutex_details (struct _WapiHandleShared *handle)
{
static guchar buf[80];
guchar *name;
struct _WapiHandle_mutex *mut=&handle->u.mutex;

name=_wapi_handle_scratch_lookup_as_string (mut->name);

g_snprintf (buf, sizeof(buf), "[%20s] own: %5d:%5ld, count: %5u",
name==NULL?(guchar *)"":name, mut->pid, mut->tid,
mut->recursion);

if(name!=NULL) {
g_free (name);
}

return(buf);
}

static const guchar *event_details (struct _WapiHandleShared *handle)
{
static guchar buf[80];
struct _WapiHandle_event *event=&handle->u.event;

g_snprintf (buf, sizeof(buf), "manual: %s",
event->manual?"TRUE":"FALSE");

return(buf);
}

static const guchar *socket_details (struct _WapiHandleShared *handle)
{
/* Nothing to see here */
return("");
}

static const guchar *find_details (struct _WapiHandleShared *handle)
{
static guchar buf[80];
struct _WapiHandle_find *find=&handle->u.find;

g_snprintf (buf, sizeof(buf), "count: %5d",
find->count);

return(buf);
}

static const guchar *process_details (struct _WapiHandleShared *handle)
{
static guchar buf[80];
struct _WapiHandle_process *proc=&handle->u.process;

g_snprintf (buf, sizeof(buf), "pid: %5u",
proc->id);

return(buf);
}
71 changes: 71 additions & 0 deletions mono/handles/scratch.c
@@ -0,0 +1,71 @@
#include <config.h>
#include <glib.h>
#include <unistd.h>

#include <mono/io-layer/io-layer.h>

/* We're digging into handle internals here... */
#include <mono/io-layer/handles-private.h>
#include <mono/io-layer/wapi-private.h>

#define HDRSIZE sizeof(struct _WapiScratchHeader)

static guchar *printable (guchar *data, guint32 datalen)
{
static guchar buf[32];
guint32 i;

if(datalen>=32) {
datalen=31;
}

for(i=0; i<datalen; i++) {
if(g_ascii_isprint (data[i])) {
buf[i]=data[i];
} else {
buf[i]='.';
}
}
buf[i]='\0';

return(buf);
}

int main (int argc, char **argv)
{
guint32 idx=0;
/* Fix if this changes in shared.c */
guint32 scratch_size=0;
struct _WapiScratchHeader *hdr;

_wapi_shared_data=_wapi_shm_attach (&scratch_size);

_wapi_handle_shared_lock ();

hdr=(struct _WapiScratchHeader *)&_wapi_shared_data->scratch_base[0];
if(hdr->flags==0 && hdr->length==0) {
g_print ("Scratch space unused\n");
_wapi_handle_shared_unlock ();
exit (0);
}

while(idx<scratch_size) {
hdr=(struct _WapiScratchHeader *)&_wapi_shared_data->scratch_base[idx];
if(hdr->flags & WAPI_SHM_SCRATCH_FREE) {
g_print ("Free block at %6d (index %6d), length %6d\n",
idx, idx+HDRSIZE, hdr->length);
} else {
guchar *data=&_wapi_shared_data->scratch_base[idx+HDRSIZE];

g_print ("Used block at %6d (index %6d), length %6d, [%s]\n",
idx, idx+HDRSIZE, hdr->length,
printable (data, hdr->length));
}

idx+=(hdr->length+HDRSIZE);
}

_wapi_handle_shared_unlock ();

exit (0);
}
12 changes: 12 additions & 0 deletions mono/handles/shmdel.c
@@ -0,0 +1,12 @@
#include <config.h>
#include <glib.h>

/* We're digging into handle internals here... */
#include <mono/io-layer/shared.h>

int main (int argc, char **argv)
{
_wapi_shm_destroy ();

exit (0);
}
4 changes: 4 additions & 0 deletions mono/interpreter/ChangeLog
@@ -1,3 +1,7 @@
2002-04-30 Dick Porter <dick@ximian.com>

* interp.c: Tell glib to not abort when g_log() etc print
recursively

Mon Apr 22 16:52:03 CEST 2002 Paolo Molaro <lupus@ximian.com>

Expand Down
3 changes: 3 additions & 0 deletions mono/interpreter/interp.c
Expand Up @@ -3923,6 +3923,9 @@ main (int argc, char *argv [])
if (!file)
usage ();

g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);

mono_init_icall ();
mono_add_internal_call ("System.Array::Set", ves_array_set);
mono_add_internal_call ("System.Array::Get", ves_array_get);
Expand Down

0 comments on commit 94ddc5e

Please sign in to comment.