Author: ArcRiley Date: 2008-03-18 18:03:08 -0400 (Tue, 18 Mar 2008) New Revision: 1169
Modified: trunk/pysoy/src/_internals/Children.pxi trunk/pysoy/src/_internals/soy._internals.pxd Log: No Ticket : * renamed Children._up and _down to _raise and _lower * added mutex locks for _raise _lower etc * separated internal and external C functions in Children * reformatted the .pxd Modified: trunk/pysoy/src/_internals/Children.pxi =================================================================== --- trunk/pysoy/src/_internals/Children.pxi 2008-03-18 22:02:47 UTC (rev 1168) +++ trunk/pysoy/src/_internals/Children.pxi 2008-03-18 22:03:08 UTC (rev 1169) @@ -28,33 +28,60 @@ The lock and unlock methods control the mutex. ''' - def __cinit__(self) : + ############################################################################ + # + # Python functions + # + + def __cinit__(self, name='') : + cdef int _i, _l + # self._size = 1 self._current = 0 self._iters = 0 self._list = <void**> py.PyMem_Malloc(sizeof(void*)) self._lockMain = py.PyThread_allocate_lock() self._lockIter = py.PyThread_allocate_lock() + # + # Copy name to self._name + _l = len(name) + self._name = <char*> py.PyMem_Malloc(len(name)+1) + for _i from 0 <= _i < _l : + self._name[_i] = name[_i] + self._name[_l] = 0 + def __dealloc__(self) : py.PyMem_Free(self._list) py.PyThread_free_lock(self._lockMain) py.PyThread_free_lock(self._lockIter) - cdef void _iterStart(self) : - py.PyThread_acquire_lock(self._lockMain, 1) - py.PyThread_acquire_lock(self._lockIter, 1) - self._iters = self._iters + 1 - py.PyThread_release_lock(self._lockIter) - py.PyThread_release_lock(self._lockMain) + ############################################################################ + # + # Internal C functions + # - cdef void _iterDone(self) : - py.PyThread_acquire_lock(self._lockIter, 1) - self._iters = self._iters - 1 - py.PyThread_release_lock(self._lockIter) - + cdef int _index(self, void* _child) : + cdef int _i + for _i from 0 <= _i < self._current : + if self._list[_i] == _child : + return _i + return -1 + + cdef void _swap(self, int _first, int _second) : + cdef void* _sibling + _sibling = self._list[_first] + self._list[_first] = self._list[_second] + self._list[_second] = _sibling + + + ############################################################################ + # + # External C functions + # + cdef void _append(self, void* _child) : py.PyThread_acquire_lock(self._lockMain, 1) # @@ -70,66 +97,80 @@ py.PyThread_release_lock(self._lockMain) - cdef void _remove(self, void* _child) : - cdef int _i, _index + cdef void _bottom(self, void* _child) : + cdef int _index py.PyThread_acquire_lock(self._lockMain, 1) - # - # Wait until all iterations are complete - while self._iters != 0 : - _sleep(1) _index = self._index(_child) - if _index == -1 : - py.PyThread_release_lock(self._lockMain) - return - for _i from _index <= _i < (self._current - 1) : - self._list[_i] = self._list[_i + 1] - self._current = self._current - 1 + if _index > 0 : + self._swap(_index, 0) py.PyThread_release_lock(self._lockMain) - cdef int _index(self, void* _child) : - cdef int _i - for _i from 0 <= _i < self._current : - if self._list[_i] == _child : - return _i - return -1 + cdef void _empty(self) : + py.PyThread_acquire_lock(self._lockMain, 1) + py.PyMem_Free(self._list) + self._size = 1 + self._current = 0 + self._list = <void**> py.PyMem_Malloc(sizeof(void*)) + py.PyThread_release_lock(self._lockMain) - cdef void _swap(self, int _first, int _second) : - cdef void* _sibling - _sibling = self._list[_first] - self._list[_first] = self._list[_second] - self._list[_second] = _sibling - cdef void _down(self, void* _child) : + cdef void _iterDone(self) : + py.PyThread_acquire_lock(self._lockIter, 1) + self._iters = self._iters - 1 + py.PyThread_release_lock(self._lockIter) + + + cdef void _iterStart(self) : + py.PyThread_acquire_lock(self._lockMain, 1) + py.PyThread_acquire_lock(self._lockIter, 1) + self._iters = self._iters + 1 + py.PyThread_release_lock(self._lockIter) + py.PyThread_release_lock(self._lockMain) + + + cdef void _lower(self, void* _child) : cdef int _index + py.PyThread_acquire_lock(self._lockMain, 1) _index = self._index(_child) if _index > 0 : self._swap(_index, _index - 1) - cdef void _up(self, void* _child) : + + cdef void _raise(self, void* _child) : cdef int _index + py.PyThread_acquire_lock(self._lockMain, 1) _index = self._index(_child) if _index == -1 : return if _index < self._current-1 : self._swap(_index, _index + 1) + py.PyThread_release_lock(self._lockMain) + + cdef void _remove(self, void* _child) : + cdef int _i, _index + py.PyThread_acquire_lock(self._lockMain, 1) + # + # Wait until all iterations are complete + while self._iters != 0 : + _sleep(1) + _index = self._index(_child) + if _index == -1 : + py.PyThread_release_lock(self._lockMain) + return + for _i from _index <= _i < (self._current - 1) : + self._list[_i] = self._list[_i + 1] + self._current = self._current - 1 + py.PyThread_release_lock(self._lockMain) + + cdef void _top(self, void* _child) : cdef int _index + py.PyThread_acquire_lock(self._lockMain, 1) _index = self._index(_child) if _index == -1 : return if _index < self._current - 1 : self._swap(_index, self._current - 1) - - cdef void _bottom(self, void* _child) : - cdef int _index - _index = self._index(_child) - if _index > 0 : - self._swap(_index, 0) - - cdef void _empty(self) : - py.PyMem_Free(self._list) - self._size = 1 - self._current = 0 - self._list = <void**> py.PyMem_Malloc(sizeof(void*)) + py.PyThread_release_lock(self._lockMain) Modified: trunk/pysoy/src/_internals/soy._internals.pxd =================================================================== --- trunk/pysoy/src/_internals/soy._internals.pxd 2008-03-18 22:02:47 UTC (rev 1168) +++ trunk/pysoy/src/_internals/soy._internals.pxd 2008-03-18 22:03:08 UTC (rev 1169) @@ -21,62 +21,74 @@ cdef class AsyncQueue : cdef glib.GAsyncQueue* _asyncqueue - cdef void _push(self, void*) - cdef object _pop(self) + cdef void _push ( self, void* ) + cdef object _pop ( self ) + cdef class Children : - cdef int _size - cdef int _current - cdef int _iters - cdef void** _list - cdef void* _lockMain - cdef void* _lockIter - cdef void _iterStart ( self ) - cdef void _iterDone ( self ) - cdef void _append ( self, void* ) - cdef int _index ( self, void* ) - cdef void _swap ( self, int, int ) - cdef void _up ( self, void* ) - cdef void _down ( self, void* ) - cdef void _top ( self, void* ) - cdef void _bottom ( self, void* ) - cdef void _remove ( self, void* ) - cdef void _empty ( self ) + # C variables + cdef int _size + cdef int _current + cdef int _iters + cdef void** _list + cdef char* _name + # Mutex locks + cdef void* _lockMain + cdef void* _lockIter + # Internal C functions + cdef int _index ( self, void* ) + cdef void _swap ( self, int, int ) + # External C functions + cdef void _append ( self, void* ) + cdef void _bottom ( self, void* ) + cdef void _empty ( self ) + cdef void _iterDone ( self ) + cdef void _iterStart ( self ) + cdef void _lower ( self, void* ) + cdef void _raise ( self, void* ) + cdef void _remove ( self, void* ) + cdef void _top ( self, void* ) + cdef class Loadable : - cdef object _source - cdef int _state - cdef int _coreLoad(self, void*, int) - cdef int _save(self, void*, int) - cdef int _ready(self) + cdef object _source + cdef int _state + cdef int _coreLoad ( self, void*, int ) + cdef int _save ( self, void*, int ) + cdef int _ready ( self ) + cdef class Loopable : - cdef int _loop(self) + cdef int _loop ( self ) + cdef class LoopThread : - cdef long _threadID - cdef int _size - cdef int _current - cdef int _running - cdef int _wake - cdef void** _list - cdef void * _listLock - cdef void * _loopLock - cdef object _name - cdef object _active - cdef object _active_limbo_lock - cdef void _loop ( self ) - cdef void _append ( self, void* ) - cdef void _remove ( self, void* ) + cdef long _threadID + cdef int _size + cdef int _current + cdef int _running + cdef int _wake + cdef void** _list + cdef void * _listLock + cdef void * _loopLock + cdef object _name + cdef object _active + cdef object _active_limbo_lock + cdef void _loop ( self ) + cdef void _append ( self, void* ) + cdef void _remove ( self, void* ) + cdef class PointerSet : cdef glib.GHashTable* _hashtable - cdef void _insert(self, void*) - cdef int _has_key(self, void*) - cdef int _remove(self, void*) - cdef void _empty(self) - cdef void _foreach(self, glib.GHFunc, void*) + cdef void _insert ( self, void* ) + cdef int _has_key ( self, void* ) + cdef int _remove ( self, void* ) + cdef void _empty ( self ) + cdef void _foreach ( self, glib.GHFunc, void* ) -cdef void _sleep ( unsigned int ) -cdef double _time ( ) -cdef AsyncQueue _getQueue ( ) + +# Extension-level C functions +cdef void _sleep ( unsigned int ) +cdef double _time ( ) +cdef AsyncQueue _getQueue ( ) _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn