| … | … | @@ -367,20 +367,27 @@ |
| 367 | 367 | (count-obj 'get-count PAIR)) |
| 368 | 368 | |
| 369 | 369 | (define (set-count PAIR CNT) |
| 370 | | (count-obj 'set-count PAIR CNT) |
| 371 | | (store-value PAIR cnt-key)) |
| 370 | ; FYI count-obj returns a pair which might be PAIR, or it |
| 371 | ; might be a copy of PAIR. If its a copy, its in a different |
| 372 | ; AtomSpace. Store that one, and not the original. |
| 373 | (store-value (count-obj 'set-count PAIR CNT) cnt-key)) |
| 372 | 374 | |
| 373 | 375 | ; Fully thread-safe fetch-and-increment. |
| 374 | 376 | (define (inc-count PAIR CNT) |
| 375 | | (if (not (equal? cnt-type (cog-value-type PAIR cnt-key))) |
| 376 | | (begin |
| 377 | | (lock-mutex mtx) |
| 378 | | (if (not (equal? cnt-type (cog-value-type PAIR cnt-key))) |
| 379 | | (fetch-value PAIR cnt-key)) |
| 380 | | (count-obj 'inc-count PAIR CNT) |
| 381 | | (unlock-mutex mtx)) |
| 382 | | (count-obj 'inc-count PAIR CNT)) |
| 383 | | (store-value PAIR cnt-key)) |
| 377 | ; FYI count-obj returns a pair which might be PAIR, or it |
| 378 | ; might be a copy of PAIR. If its a copy, its in a different |
| 379 | ; AtomSpace. Store that one, and not the original. |
| 380 | (define ipr |
| 381 | (if (not (equal? cnt-type (cog-value-type PAIR cnt-key))) |
| 382 | (begin |
| 383 | (lock-mutex mtx) |
| 384 | (if (not (equal? cnt-type (cog-value-type PAIR cnt-key))) |
| 385 | (fetch-value PAIR cnt-key)) |
| 386 | (let ((npr (count-obj 'inc-count PAIR CNT))) |
| 387 | (unlock-mutex mtx) |
| 388 | npr)) |
| 389 | (count-obj 'inc-count PAIR CNT))) |
| 390 | (store-value ipr cnt-key)) |
| 384 | 391 | |
| 385 | 392 | ; Return the observed count for the pair (L-ATOM, R-ATOM). |
| 386 | 393 | ; Be careful to not create tha pair, if it doesn't exist. |