Changeset 1169 for trunk/pysoy/src/_internals
- Timestamp:
- 03/18/08 18:03:08 (10 months ago)
- Location:
- trunk/pysoy/src/_internals
- Files:
-
- 2 modified
-
Children.pxi (modified) (6 diffs)
-
soy._internals.pxd (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pysoy/src/_internals/Children.pxi
r1083 r1169 29 29 ''' 30 30 31 def __cinit__(self) : 31 ############################################################################ 32 # 33 # Python functions 34 # 35 36 def __cinit__(self, name='') : 37 cdef int _i, _l 38 # 32 39 self._size = 1 33 40 self._current = 0 … … 36 43 self._lockMain = py.PyThread_allocate_lock() 37 44 self._lockIter = py.PyThread_allocate_lock() 45 # 46 # Copy name to self._name 47 _l = len(name) 48 self._name = <char*> py.PyMem_Malloc(len(name)+1) 49 for _i from 0 <= _i < _l : 50 self._name[_i] = name[_i] 51 self._name[_l] = 0 52 38 53 39 54 def __dealloc__(self) : … … 42 57 py.PyThread_free_lock(self._lockIter) 43 58 44 cdef void _iterStart(self) : 45 py.PyThread_acquire_lock(self._lockMain, 1) 46 py.PyThread_acquire_lock(self._lockIter, 1) 47 self._iters = self._iters + 1 48 py.PyThread_release_lock(self._lockIter) 49 py.PyThread_release_lock(self._lockMain) 59 60 ############################################################################ 61 # 62 # Internal C functions 63 # 64 65 cdef int _index(self, void* _child) : 66 cdef int _i 67 for _i from 0 <= _i < self._current : 68 if self._list[_i] == _child : 69 return _i 70 return -1 50 71 51 72 52 cdef void _iterDone(self) : 53 py.PyThread_acquire_lock(self._lockIter, 1) 54 self._iters = self._iters - 1 55 py.PyThread_release_lock(self._lockIter) 56 73 cdef void _swap(self, int _first, int _second) : 74 cdef void* _sibling 75 _sibling = self._list[_first] 76 self._list[_first] = self._list[_second] 77 self._list[_second] = _sibling 78 79 80 ############################################################################ 81 # 82 # External C functions 83 # 57 84 58 85 cdef void _append(self, void* _child) : … … 68 95 self._list[self._current] = <void*> _child 69 96 self._current = self._current + 1 97 py.PyThread_release_lock(self._lockMain) 98 99 100 cdef void _bottom(self, void* _child) : 101 cdef int _index 102 py.PyThread_acquire_lock(self._lockMain, 1) 103 _index = self._index(_child) 104 if _index > 0 : 105 self._swap(_index, 0) 106 py.PyThread_release_lock(self._lockMain) 107 108 109 cdef void _empty(self) : 110 py.PyThread_acquire_lock(self._lockMain, 1) 111 py.PyMem_Free(self._list) 112 self._size = 1 113 self._current = 0 114 self._list = <void**> py.PyMem_Malloc(sizeof(void*)) 115 py.PyThread_release_lock(self._lockMain) 116 117 118 cdef void _iterDone(self) : 119 py.PyThread_acquire_lock(self._lockIter, 1) 120 self._iters = self._iters - 1 121 py.PyThread_release_lock(self._lockIter) 122 123 124 cdef void _iterStart(self) : 125 py.PyThread_acquire_lock(self._lockMain, 1) 126 py.PyThread_acquire_lock(self._lockIter, 1) 127 self._iters = self._iters + 1 128 py.PyThread_release_lock(self._lockIter) 129 py.PyThread_release_lock(self._lockMain) 130 131 132 cdef void _lower(self, void* _child) : 133 cdef int _index 134 py.PyThread_acquire_lock(self._lockMain, 1) 135 _index = self._index(_child) 136 if _index > 0 : 137 self._swap(_index, _index - 1) 138 139 140 cdef void _raise(self, void* _child) : 141 cdef int _index 142 py.PyThread_acquire_lock(self._lockMain, 1) 143 _index = self._index(_child) 144 if _index == -1 : 145 return 146 if _index < self._current-1 : 147 self._swap(_index, _index + 1) 70 148 py.PyThread_release_lock(self._lockMain) 71 149 … … 88 166 89 167 90 cdef int _index(self, void* _child) :91 cdef int _i92 for _i from 0 <= _i < self._current :93 if self._list[_i] == _child :94 return _i95 return -196 97 cdef void _swap(self, int _first, int _second) :98 cdef void* _sibling99 _sibling = self._list[_first]100 self._list[_first] = self._list[_second]101 self._list[_second] = _sibling102 103 cdef void _down(self, void* _child) :104 cdef int _index105 _index = self._index(_child)106 if _index > 0 :107 self._swap(_index, _index - 1)108 109 cdef void _up(self, void* _child) :110 cdef int _index111 _index = self._index(_child)112 if _index == -1 :113 return114 if _index < self._current-1 :115 self._swap(_index, _index + 1)116 117 168 cdef void _top(self, void* _child) : 118 169 cdef int _index 170 py.PyThread_acquire_lock(self._lockMain, 1) 119 171 _index = self._index(_child) 120 172 if _index == -1 : … … 122 174 if _index < self._current - 1 : 123 175 self._swap(_index, self._current - 1) 124 125 cdef void _bottom(self, void* _child) : 126 cdef int _index 127 _index = self._index(_child) 128 if _index > 0 : 129 self._swap(_index, 0) 130 131 cdef void _empty(self) : 132 py.PyMem_Free(self._list) 133 self._size = 1 134 self._current = 0 135 self._list = <void**> py.PyMem_Malloc(sizeof(void*)) 176 py.PyThread_release_lock(self._lockMain) -
trunk/pysoy/src/_internals/soy._internals.pxd
r1079 r1169 22 22 cdef class AsyncQueue : 23 23 cdef glib.GAsyncQueue* _asyncqueue 24 cdef void _push(self, void*) 25 cdef object _pop(self) 24 cdef void _push ( self, void* ) 25 cdef object _pop ( self ) 26 26 27 27 28 cdef class Children : 28 cdef int _size 29 cdef int _current 30 cdef int _iters 31 cdef void** _list 32 cdef void* _lockMain 33 cdef void* _lockIter 34 cdef void _iterStart ( self ) 35 cdef void _iterDone ( self ) 36 cdef void _append ( self, void* ) 37 cdef int _index ( self, void* ) 38 cdef void _swap ( self, int, int ) 39 cdef void _up ( self, void* ) 40 cdef void _down ( self, void* ) 41 cdef void _top ( self, void* ) 42 cdef void _bottom ( self, void* ) 43 cdef void _remove ( self, void* ) 44 cdef void _empty ( self ) 29 # C variables 30 cdef int _size 31 cdef int _current 32 cdef int _iters 33 cdef void** _list 34 cdef char* _name 35 # Mutex locks 36 cdef void* _lockMain 37 cdef void* _lockIter 38 # Internal C functions 39 cdef int _index ( self, void* ) 40 cdef void _swap ( self, int, int ) 41 # External C functions 42 cdef void _append ( self, void* ) 43 cdef void _bottom ( self, void* ) 44 cdef void _empty ( self ) 45 cdef void _iterDone ( self ) 46 cdef void _iterStart ( self ) 47 cdef void _lower ( self, void* ) 48 cdef void _raise ( self, void* ) 49 cdef void _remove ( self, void* ) 50 cdef void _top ( self, void* ) 51 45 52 46 53 cdef class Loadable : 47 cdef object _source 48 cdef int _state 49 cdef int _coreLoad(self, void*, int) 50 cdef int _save(self, void*, int) 51 cdef int _ready(self) 54 cdef object _source 55 cdef int _state 56 cdef int _coreLoad ( self, void*, int ) 57 cdef int _save ( self, void*, int ) 58 cdef int _ready ( self ) 59 52 60 53 61 cdef class Loopable : 54 cdef int _loop(self) 62 cdef int _loop ( self ) 63 55 64 56 65 cdef class LoopThread : 57 cdef long _threadID 58 cdef int _size 59 cdef int _current 60 cdef int _running 61 cdef int _wake 62 cdef void** _list 63 cdef void * _listLock 64 cdef void * _loopLock 65 cdef object _name 66 cdef object _active 67 cdef object _active_limbo_lock 68 cdef void _loop ( self ) 69 cdef void _append ( self, void* ) 70 cdef void _remove ( self, void* ) 66 cdef long _threadID 67 cdef int _size 68 cdef int _current 69 cdef int _running 70 cdef int _wake 71 cdef void** _list 72 cdef void * _listLock 73 cdef void * _loopLock 74 cdef object _name 75 cdef object _active 76 cdef object _active_limbo_lock 77 cdef void _loop ( self ) 78 cdef void _append ( self, void* ) 79 cdef void _remove ( self, void* ) 80 71 81 72 82 cdef class PointerSet : 73 83 cdef glib.GHashTable* _hashtable 74 cdef void _insert (self, void*)75 cdef int _has_key (self, void*)76 cdef int _remove (self, void*)77 cdef void _empty (self)78 cdef void _foreach (self, glib.GHFunc, void*)84 cdef void _insert ( self, void* ) 85 cdef int _has_key ( self, void* ) 86 cdef int _remove ( self, void* ) 87 cdef void _empty ( self ) 88 cdef void _foreach ( self, glib.GHFunc, void* ) 79 89 80 cdef void _sleep ( unsigned int ) 81 cdef double _time ( ) 82 cdef AsyncQueue _getQueue ( ) 90 91 # Extension-level C functions 92 cdef void _sleep ( unsigned int ) 93 cdef double _time ( ) 94 cdef AsyncQueue _getQueue ( )
