| … | … | @@ -18,19 +18,17 @@ |
| 18 | 18 | ; --------------------------------------------------------------------- |
| 19 | 19 | |
| 20 | 20 | ; get-count ATOM - return the raw observational count on ATOM. |
| 21 | | (define (cog-count ATOM) |
| 22 | | (cog-value-ref (cog-value ATOM (Predicate "*-TruthValueKey-*")) 2)) |
| 23 | | (define (cog-set-tv! ATOM VAL) |
| 24 | | (cog-set-value! ATOM (Predicate "*-TruthValueKey-*") VAL)) |
| 25 | | (define (cog-have-tv? ATOM) |
| 21 | ;(define (get-count ATOM) |
| 22 | ; (cog-value-ref (cog-value ATOM (Predicate "*-TruthValueKey-*")) 2)) |
| 23 | ; (define (do-set-tv! ATOM VAL) |
| 24 | ; (cog-set-value! ATOM (Predicate "*-TruthValueKey-*") VAL)) |
| 25 | (define (do-have-tv? ATOM) |
| 26 | 26 | (not (eq? #f (cog-value ATOM (Predicate "*-TruthValueKey-*"))))) |
| 27 | | (define (cog-inc-count! ATOM CNT) |
| 27 | (define (do-inc-count! ATOM CNT) |
| 28 | 28 | (cog-inc-value! ATOM (Predicate "*-TruthValueKey-*") CNT 2)) |
| 29 | 29 | |
| 30 | | (define-public (get-count ATOM) (cog-count ATOM)) |
| 31 | | |
| 32 | 30 | ; set-count ATOM CNT - Set the raw observational count on ATOM. |
| 33 | | (define (set-count ATOM CNT) (cog-set-tv! ATOM (FloatValue 1 0 CNT))) |
| 31 | ; (define (set-count ATOM CNT) (do-set-tv! ATOM (FloatValue 1 0 CNT))) |
| 34 | 32 | |
| 35 | 33 | ; --------------------------------------------------------------------- |
| 36 | 34 | |
| … | … | @@ -60,14 +58,14 @@ |
| 60 | 58 | ; so even if multiple thread increment, there will be only one |
| 61 | 59 | ; fetch. It is not multi-process-safe, e.g. when multiple |
| 62 | 60 | ; writers are using a networked CogStorageNode. |
| 63 | | (if (not (cog-have-tv? atom)) |
| 61 | (if (not (do-have-tv? atom)) |
| 64 | 62 | (begin |
| 65 | 63 | (lock-mutex *-count-upgrade-mutex-*) |
| 66 | | (if (not (cog-have-tv? atom)) |
| 64 | (if (not (do-have-tv? atom)) |
| 67 | 65 | (fetch-atom atom)) |
| 68 | | (cog-inc-count! atom CNT) |
| 66 | (do-inc-count! atom CNT) |
| 69 | 67 | (unlock-mutex *-count-upgrade-mutex-*)) |
| 70 | | (cog-inc-count! atom CNT)) |
| 68 | (do-inc-count! atom CNT)) |
| 71 | 69 | ) |
| 72 | 70 | |
| 73 | 71 | (incr-one ATM) ; increment the count on ATM |