o
    
۾i                     @   s(   d dl Z G dd dZG dd dZdS )    Nc                       s@   e Zd Zddeddf fddZdefddZdd	d
Z  ZS )Counterr   startreturnNc                    s   t    || _d S N)super__init__counter)selfr   	__class__ F/home/ubuntu/.local/lib/python3.10/site-packages/vllm/utils/counter.pyr      s   

zCounter.__init__c                 C   s   | j }|  j d7  _ |S )N   r   )r	   ir   r   r   __next__   s   zCounter.__next__c                 C   s
   d| _ d S )Nr   r   r	   r   r   r   reset   s   
zCounter.resetr   )r   N)__name__
__module____qualname__intr   r   r   __classcell__r   r   r
   r   r      s    r   c                       sf   e Zd ZdZddeddf fddZedefdd	ZddedefddZddedefddZ	  Z
S )AtomicCounterzAn atomic, thread-safe counterr   initialr   Nc                    s   t    || _t | _dS )z6Initialize a new atomic counter to given initial valueN)r   r   _value	threadingLock_lock)r	   r   r
   r   r   r      s   
zAtomicCounter.__init__c                 C   s   | j S r   )r   r   r   r   r   value   s   zAtomicCounter.valuer   numc                 C   s>   | j  |  j|7  _| jW  d   S 1 sw   Y  dS )z@Atomically increment the counter by num and return the new valueNr   r   r	   r!   r   r   r   inc#      $zAtomicCounter.incc                 C   s>   | j  |  j|8  _| jW  d   S 1 sw   Y  dS )z@Atomically decrement the counter by num and return the new valueNr"   r#   r   r   r   dec)   r%   zAtomicCounter.decr   )r   )r   r   r   __doc__r   r   propertyr    r$   r&   r   r   r   r
   r   r      s    r   )r   r   r   r   r   r   r   <module>   s   