<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def compare_and_set(self, oldval, newval):
        '''
        Given `oldval` and `newval`, sets the atom's value to `newval` if and
        only if `oldval` is the atom's current value. Returns `True` upon
        success, otherwise `False`.

        :param oldval: The old expected value.
        :param newval: The new value which will be set if and only if `oldval`
            equals the current value.
        '''
        ret = self._state.compare_and_set(oldval, newval)
        if ret:
            self.notify_watches(oldval, newval)

        return ret