[Stackless-checkins] CVS: slpdev/src/2.3/dev/Stackless/module channelobject.c, 1.48, 1.49 scheduling.c, 1.97, 1.98

Christian Tismer tismer at centera.de
Mon May 24 19:42:16 CEST 2004


Update of /home/cvs/slpdev/src/2.3/dev/Stackless/module
In directory centera.de:/tmp/cvs-serv32488/Stackless/module

Modified Files:
	channelobject.c scheduling.c 
Log Message:
Stackless 3.1 passes all tests, again.
Re-implemented the old channel behavior (prefer receiver)
Added new flags to channels which control  behavor.
Extended the C API.
Nice result:
Thread communication is 8 times slower than soft channels!

Index: channelobject.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/module/channelobject.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** channelobject.c	24 May 2004 01:45:38 -0000	1.48
--- channelobject.c	24 May 2004 17:42:14 -0000	1.49
***************
*** 131,135 ****
  		c->chan_weakreflist = NULL;
  		*(int*)&c->flags = 0;
! 		c->flags.preference = 0;//!!-1; /* default fast receive */
  	}
  	return c;
--- 131,135 ----
  		c->chan_weakreflist = NULL;
  		*(int*)&c->flags = 0;
! 		c->flags.preference = -1; /* default fast receive */
  	}
  	return c;
***************
*** 147,155 ****
  
  static PyObject *
! channel_get_queue(PyChannelObject *channel)
  {
! 	PyObject *ret = (PyObject*) channel->head;
  
! 	if (ret == (PyObject *) channel)
  		ret = Py_None;
  	Py_INCREF(ret);
--- 147,155 ----
  
  static PyObject *
! channel_get_queue(PyChannelObject *self)
  {
! 	PyObject *ret = (PyObject*) self->head;
  
! 	if (ret == (PyObject *) self)
  		ret = Py_None;
  	Py_INCREF(ret);
***************
*** 157,163 ****
  }
  
  static PyGetSetDef channel_getsetlist[] = {
! 	{"queue", (getter)channel_get_queue, NULL,
! 	"the chain of waiting tasklets."},
  	{0}
  };
--- 157,263 ----
  }
  
+ PyObject *
+ PyChannel_GetQueue(PyChannelObject *self)
+ {
+ 	return channel_get_queue(self);
+ }
+ 
+ static PyObject *
+ channel_get_closing(PyChannelObject *self)
+ {
+ 	return PyBool_FromLong(self->flags.closing);
+ }
+ 
+ int
+ PyChannel_GetClosing(PyChannelObject *self)
+ {
+ 	return self->flags.closing;
+ }
+ 
+ static PyObject *
+ channel_get_closed(PyChannelObject *self)
+ {
+ 	return PyBool_FromLong(self->flags.closing && self->balance == 0);
+ }
+ 
+ int
+ PyChannel_GetClosed(PyChannelObject *self)
+ {
+ 	return self->flags.closing && self->balance == 0;
+ }
+ 
+ 
+ static PyObject *
+ channel_get_preference(PyChannelObject *self)
+ {
+ 	return PyInt_FromLong(self->flags.preference);
+ }
+ 
+ static int
+ channel_set_preference(PyChannelObject *self, PyObject *value)
+ {
+ 	int val;
+ 
+ 	if (!PyInt_Check(value))
+ 		TYPE_ERROR("preference must be set to an integer", -1);
+ 	val = PyInt_AS_LONG(value);
+ 	self->flags.preference = val > 0 ? 1 : val < 0 ? -1 : 0;
+ 	return 0;
+ }
+ 
+ int
+ PyChannel_GetPreference(PyChannelObject *self)
+ {
+ 	return self->flags.preference;
+ }
+ 
+ void
+ PyChannel_SetPreference(PyChannelObject *self, int val)
+ {
+ 	self->flags.preference = val > 0 ? 1 : val < 0 ? -1 : 0;
+ }
+ 
+ static PyObject *
+ channel_get_schedule_all(PyChannelObject *self)
+ {
+ 	return PyInt_FromLong(self->flags.schedule_all);
+ }
+ 
+ static int
+ channel_set_schedule_all(PyChannelObject *self, PyObject *value)
+ {
+ 	if (!PyInt_Check(value))
+ 		TYPE_ERROR("preference must be set to a bool or integer", -1);
+ 	self->flags.schedule_all = PyInt_AsLong(value) ? 1 : 0;
+ 	return 0;
+ }
+ 
+ int
+ PyChannel_GetScheduleAll(PyChannelObject *self)
+ {
+ 	return self->flags.schedule_all;
+ }
+ 
+ void
+ PyChannel_SetScheduleAll(PyChannelObject *self, int val)
+ {
+ 	self->flags.schedule_all = val ? 1 : 0;
+ }
+ 
  static PyGetSetDef channel_getsetlist[] = {
! 	{"queue",		(getter)channel_get_queue, NULL,
! 	 "the chain of waiting tasklets."},
! 	{"closing",		(getter)channel_get_closing, NULL,
! 	 "True when close was called."},
! 	{"closed",		(getter)channel_get_closed, NULL,
! 	 "True when close was called and the channel is empty.."},
! 	{"preference",		(getter)channel_get_preference,
! 				(setter)channel_set_preference,
! 	 "-1 prefer receiver (default), 1 prefer sender, 0 don't\n"
! 	 "prefer anything. See also schedule_all"},
! 	{"schedule_all",	(getter)channel_get_schedule_all,
! 				(setter)channel_set_schedule_all,
! 	 "schedule to the next runnable on any channel action.\n"
! 	 "overrides preference."},
  	{0}
  };
***************
*** 312,315 ****
--- 412,417 ----
  	assert(abs(dir) == 1);
  
+ 	TASKLET_SETVAL(source, arg);
+ 
  	/* note that notify might release the GIL. */
  	/* XXX for the moment, we notify late on interthread */
***************
*** 317,322 ****
  		NOTIFY_CHANNEL(self, source, dir, cando, NULL);
  
- 	TASKLET_SETVAL(source, arg);
- 
  	if (cando) {
  		/* communication 1): there is somebody waiting */
--- 419,422 ----
***************
*** 511,517 ****
  
  static PyObject *
! channel_receive(PyObject *myself)
  {
! 	return impl_channel_receive((PyChannelObject*)myself);
  }
  
--- 611,645 ----
  
  static PyObject *
! channel_receive(PyObject *self)
  {
! 	return impl_channel_receive((PyChannelObject*)self);
! }
! 
! 
! static char channel_close__doc__[] =
! "channel.close() -- stops the channel from enlarging its queue.\n\
! \n\
! If the channel is not empty, the flag 'closing' becomes true.\n\
! If the channel is empty, the flag 'closed' becomes true.";
! 
! static PyObject *
! channel_close(PyChannelObject *self)
! {
! 	self->flags.closing = 1;
! 
! 	Py_INCREF(Py_None);
! 	return Py_None;
! }
! 
! static char channel_open__doc__[] =
! "channel.open() -- reopen a channel. See channel.close.";
! 
! static PyObject *
! channel_open(PyChannelObject *self)
! {
! 	self->flags.closing = 0;
! 
! 	Py_INCREF(Py_None);
! 	return Py_None;
  }
  
***************
*** 526,533 ****
  
  #define PCF PyCFunction
- //!! debug: disable stackless for now
- //#undef METH_STACKLESS
- //#define METH_STACKLESS 0
- //!!
  #define METH_KS METH_KEYWORDS | METH_STACKLESS
  #define METH_VS METH_VARARGS | METH_STACKLESS
--- 654,657 ----
***************
*** 543,546 ****
--- 667,674 ----
  	{"receive",	    (PCF)channel_receive,	  METH_NS,
  	 channel_receive__doc__},
+ 	{"close",	    (PCF)channel_close,		  METH_NOARGS,
+ 	channel_close__doc__},
+ 	{"open",	    (PCF)channel_open,		  METH_NOARGS,
+ 	channel_open__doc__},
  	{NULL,		    NULL}             /* sentinel */
  };

Index: scheduling.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/module/scheduling.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -C2 -d -r1.97 -r1.98
*** scheduling.c	24 May 2004 01:59:34 -0000	1.97
--- scheduling.c	24 May 2004 17:42:14 -0000	1.98
***************
*** 879,884 ****
--- 879,886 ----
  	 * Therefore, we enforce a soft-switch.
  	 */
+ 	PyThreadState *ts = PyThreadState_GET();
  	PyObject *retval;
  
+ 	(void *) ts; /* keep gcc quiet */
  	/* we should have no nesting level */
  	assert(ts->st.nesting_level == 0);


_______________________________________________
Stackless-checkins mailing list
Stackless-checkins at stackless.com
http://www.stackless.com/mailman/listinfo/stackless-checkins



More information about the Stackless-checkins mailing list