[Stackless-checkins] CVS: slpdev/src/2.3/dev/Stackless/module channelobject.c, 1.51, 1.52 scheduling.c, 1.108, 1.109 stacklessmodule.c, 1.176, 1.177 taskletobject.c, 1.115, 1.116

Christian Tismer tismer at centera.de
Fri Jul 9 01:16:01 CEST 2004


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

Modified Files:
	channelobject.c scheduling.c stacklessmodule.c taskletobject.c 
Log Message:
new channel methods are already there.
Meanwhile I had hacked something at
home, and I don't know if it is related.
Anyway, I get a crash, now.

Index: channelobject.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/module/channelobject.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -C2 -d -r1.51 -r1.52
*** a/channelobject.c	8 Jul 2004 18:58:29 -0000	1.51
--- b/channelobject.c	8 Jul 2004 23:15:57 -0000	1.52
***************
*** 874,877 ****
--- 874,943 ----
  }
  
+ static char channel_reduce__doc__[] =
+ "channel.__reduce__() -- currently does not distinguish threads.";
+ 
+ static PyObject *
+ channel_reduce(PyChannelObject * ch)
+ {
+ 	PyObject *tup = NULL, *lis = NULL;
+ 	PyTaskletObject *t;
+ 	int i, n;
+ 
+ 	lis = PyList_New(0);
+ 	if (lis == NULL) goto err_exit;
+ 	t = ch->head;
+ 	n = abs(ch->balance);
+ 	for (i = 0; i < n; i++) {
+ 		if (PyList_Append(lis, (PyObject *) t)) goto err_exit;
+ 		t = t->next;
+ 	}
+ 	tup = Py_BuildValue("(O()(iiO))",
+ 			    &PyChannel_Type,
+ 			    ch->balance,
+ 			    ch->flags,
+ 			    lis
+ 			    );
+ err_exit:
+ 	Py_XDECREF(lis);
+ 	return tup;
+ }
+ 
+ static char channel_setstate__doc__[] =
+ "channel.__setstate__(balance, flags, [tasklets]) -- currently does not distinguish threads.";
+ 
+ static PyObject *
+ channel_setstate(PyObject *self, PyObject *args)
+ {
+ 	PyChannelObject *ch = (PyChannelObject *) self;
+ 	PyTaskletObject *t;
+ 	PyObject *lis;
+ 	int flags, balance;
+ 	int dir;
+ 	int i, n;
+ 
+ 	if (!PyArg_ParseTuple(args, "iiO!:channel",
+ 			      &balance,
+ 			      &flags, 
+ 			      &PyList_Type, &lis))
+ 		return NULL;
+ 
+ 	channel_clear((PyObject *) ch);
+ 	n = PyList_GET_SIZE(lis);
+ 	*(int *)&ch->flags = flags;
+ 	dir = balance > 0 ? 1 : -1;
+ 
+ 	for (i = 0; i < n; i++) {
+ 		t = (PyTaskletObject *) PyList_GET_ITEM(lis, i);
+ 
+ 		if (PyTasklet_Check(t) && !t->flags.blocked) {
+ 			Py_INCREF(t);
+ 			slp_channel_insert(ch, t, dir);
+ 		}
+ 	}
+ 	Py_INCREF(self);
+ 	return self;
+ }
+ 
+ 
  static PyCMethodDef
  channel_cmethods[] = {
***************
*** 891,904 ****
  static PyMethodDef
  channel_methods[] = {
! 	{"send",	    (PCF)channel_send,		  METH_OS,
  	 channel_send__doc__},
! 	{"send_exception",  (PCF)channel_send_exception,  METH_VS,
  	 channel_send_exception__doc__},
! 	{"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__},
  	{"send_sequence",   (PCF)channel_send_sequence,	  METH_OS,
  	 channel_send__doc__},
--- 957,976 ----
  static PyMethodDef
  channel_methods[] = {
! 	{"send",	    (PCF)channel_send,		    METH_OS,
  	 channel_send__doc__},
! 	{"send_exception",  (PCF)channel_send_exception,    METH_VS,
  	 channel_send_exception__doc__},
! 	{"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__},
+ 	{"__reduce__",		(PCF)channel_reduce,	    METH_NOARGS,
+ 	 channel_reduce__doc__},
+ 	{"__reduce_ex__",	(PCF)channel_reduce,	    METH_VARARGS,
+ 	 channel_reduce__doc__},
+ 	{"__setstate__",	(PCF)channel_setstate,	    METH_O,
+ 	 channel_setstate__doc__},
  	{"send_sequence",   (PCF)channel_send_sequence,	  METH_OS,
  	 channel_send__doc__},
***************
*** 959,962 ****
--- 1031,1036 ----
  };
  
+ STACKLESS_DECLARE_METHOD(&_PyChannel_Type, tp_iternext)
+ 
  PyTypeObject *PyChannel_TypePtr = NULL;
  

Index: scheduling.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/module/scheduling.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -C2 -d -r1.108 -r1.109
*** a/scheduling.c	8 Jul 2004 18:58:29 -0000	1.108
--- b/scheduling.c	8 Jul 2004 23:15:58 -0000	1.109
***************
*** 1066,1070 ****
  	if (PyBomb_Check(retval))
  		retval = slp_bomb_explode(ts->st.current);
! 	while (ts->st.main != NULL) {
  		retval = slp_frame_dispatch_top(retval);
  		retval = tasklet_end(retval);
--- 1066,1070 ----
  	if (PyBomb_Check(retval))
  		retval = slp_bomb_explode(ts->st.current);
! 	while (ts->st.current != NULL) {
  		retval = slp_frame_dispatch_top(retval);
  		retval = tasklet_end(retval);

Index: stacklessmodule.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/module/stacklessmodule.c,v
retrieving revision 1.176
retrieving revision 1.177
diff -C2 -d -r1.176 -r1.177
*** a/stacklessmodule.c	6 Jun 2004 15:04:41 -0000	1.176
--- b/stacklessmodule.c	8 Jul 2004 23:15:58 -0000	1.177
***************
*** 272,275 ****
--- 272,304 ----
  }
  
+ static char get_thread_info__doc__[] =
+ "get_thread_info(thread_id) -- return a 3-tuple of the thread's\n\
+ main tasklet, current tasklet and runcount.\n\
+ To obtain a list of all thread infos, use\n\
+ \n\
+ map (stackless.get_thread_info, stackless.threads)";
+ 
+ static PyObject *
+ get_thread_info(PyObject *self, PyObject *args)
+ {
+ 	PyThreadState *ts = PyThreadState_GET();
+ 	PyInterpreterState *interp = ts->interp;
+ 	long id = 0;
+ 
+ 	if (!PyArg_ParseTuple(args, "|i:get_thread_info", &id))
+ 		return NULL;
+ 	for (ts = interp->tstate_head; id && ts != NULL; ts = ts->next) {
+ 		if (ts->thread_id == id)
+ 			break;
+ 	}
+ 	if (ts == NULL)
+ 		RUNTIME_ERROR("Thread id not found", NULL);
+ 
+ 	return Py_BuildValue("(OOi)",
+ 	    ts->st.main ? (PyObject *) ts->st.main : Py_None,
+ 	    ts->st.runcount ? (PyObject *) ts->st.current : Py_None,
+ 	    ts->st.runcount);
+ }
+ 
  static PyObject *
  slpmodule_reduce(PyObject *self)
***************
*** 718,721 ****
--- 747,752 ----
  	{"_pickle_moduledict",	    (PCF)slp_pickle_moduledict, METH_VARARGS,
  	 slp_pickle_moduledict__doc__},
+ 	{"get_thread_info",	    (PCF)get_thread_info,	METH_VARARGS,
+ 	 get_thread_info__doc__},
  #ifdef STACKLESS_SPY
  	{"_peek",		    (PCF)_peek,			METH_O,
***************
*** 860,863 ****
--- 891,913 ----
  }
  
+ static PyObject *
+ slpmodule_getthreads(PySlpModuleObject *mod, void *context)
+ {
+ 	PyObject *lis = PyList_New(0);
+ 	PyThreadState *ts = PyThreadState_GET();
+ 	PyInterpreterState *interp = ts->interp;
+ 
+ 	if (lis == NULL)
+ 		return NULL;
+ 
+ 	for (ts = interp->tstate_head; ts != NULL; ts = ts->next) {
+ 		PyObject *id = PyInt_FromLong(ts->thread_id);
+ 
+ 		if (id == NULL || PyList_Append(lis, id))
+ 			return NULL;
+ 	}
+ 	PyList_Reverse(lis);
+ 	return lis;
+ }
  
  
***************
*** 881,884 ****
--- 931,936 ----
  	{"uncollectables", (getter)slpmodule_getuncollectables, NULL,
  	 uncollectables__doc__},
+ 	{"threads", (getter)slpmodule_getthreads, NULL,
+ 	 "a list of all thread ids, starting with main."},
  	{0},
  };

Index: taskletobject.c
===================================================================
RCS file: /home/cvs/slpdev/src/2.3/dev/Stackless/module/taskletobject.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -C2 -d -r1.115 -r1.116
*** a/taskletobject.c	3 Jun 2004 17:07:34 -0000	1.115
--- b/taskletobject.c	8 Jul 2004 23:15:58 -0000	1.116
***************
*** 314,319 ****
--- 314,323 ----
  	TASKLET_SETVAL(t, tempval);
  	*(int *)&t->flags = flags;
+ 	/* we cannot restore blocked, must be done by a channel */
+ 	t->flags.blocked = 0;
  	/* t->nesting_level = nesting_level;
  	   XXX how do we handle this?
+ 	   XXX to be done: pickle the cstate without a ref to the task.
+ 	   XXX This should make it not runnable in the future.
  	 */
  	if (nframes > 0) {
***************
*** 1201,1204 ****
--- 1205,1214 ----
  }
  
+ static PyObject *
+ tasklet_thread_id(PyTaskletObject *task)
+ {
+ 	return PyInt_FromLong(task->cstate->tstate->thread_id);
+ }
+ 
  static PyMemberDef tasklet_members[] = {
  	{"cstate", T_OBJECT, offsetof(PyTaskletObject, cstate), READONLY,
***************
*** 1285,1288 ****
--- 1295,1301 ----
  	 "This attribute is computed."},
  
+ 	{"thread_id", (getter)tasklet_thread_id, NULL, 
+ 	 "Return the thread id of the thread the tasklet belongs to."},
+ 
  	{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