Show
Ignore:
Timestamp:
03/18/08 18:03:08 (10 months ago)
Author:
ArcRiley
Message:

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
Location:
trunk/pysoy/src/_internals
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pysoy/src/_internals/Children.pxi

    r1083 r1169  
    2929  ''' 
    3030 
    31   def __cinit__(self) : 
     31  ############################################################################ 
     32  # 
     33  # Python functions 
     34  # 
     35 
     36  def __cinit__(self, name='') : 
     37    cdef int _i, _l 
     38    # 
    3239    self._size     = 1 
    3340    self._current  = 0 
     
    3643    self._lockMain = py.PyThread_allocate_lock() 
    3744    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 
    3853 
    3954  def __dealloc__(self) : 
     
    4257    py.PyThread_free_lock(self._lockIter) 
    4358 
    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 
    5071 
    5172 
    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  # 
    5784 
    5885  cdef void _append(self, void* _child) : 
     
    6895    self._list[self._current] = <void*> _child 
    6996    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) 
    70148    py.PyThread_release_lock(self._lockMain) 
    71149 
     
    88166 
    89167 
    90   cdef int _index(self, void* _child) : 
    91     cdef int _i 
    92     for _i from 0 <= _i < self._current : 
    93       if self._list[_i] == _child : 
    94         return _i 
    95     return -1 
    96  
    97   cdef void _swap(self, int _first, int _second) : 
    98     cdef void* _sibling 
    99     _sibling = self._list[_first] 
    100     self._list[_first] = self._list[_second] 
    101     self._list[_second] = _sibling 
    102  
    103   cdef void _down(self, void* _child) : 
    104     cdef int _index 
    105     _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 _index 
    111     _index = self._index(_child) 
    112     if _index == -1 : 
    113       return   
    114     if _index < self._current-1 : 
    115       self._swap(_index, _index + 1) 
    116  
    117168  cdef void _top(self, void* _child) : 
    118169    cdef int _index 
     170    py.PyThread_acquire_lock(self._lockMain, 1) 
    119171    _index = self._index(_child) 
    120172    if _index == -1 : 
     
    122174    if _index < self._current - 1 : 
    123175      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  
    2222cdef class AsyncQueue : 
    2323  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 
    2627 
    2728cdef 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 
    4552 
    4653cdef 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 
    5260 
    5361cdef class Loopable : 
    54   cdef int    _loop(self) 
     62  cdef int               _loop         ( self ) 
     63 
    5564 
    5665cdef 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 
    7181 
    7282cdef class PointerSet : 
    7383  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* ) 
    7989 
    80 cdef void       _sleep     ( unsigned int ) 
    81 cdef double     _time      ( ) 
    82 cdef AsyncQueue _getQueue  ( ) 
     90 
     91# Extension-level C functions 
     92cdef void                _sleep        ( unsigned int ) 
     93cdef double              _time         ( ) 
     94cdef AsyncQueue          _getQueue     ( )