OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-matrix commits / cf4422b

Bug fix the new count-api.
Had an unexpected bad interaction with multiple atomspaces.
cf4422be9c40cd0ab3b025926efd7ee2c679930d
by Linas Vepstas <linasvepstas@gmail.com> · 2023-03-13T01:48:25.000Z

Changed files (1) +18 -11

opencog/matrix/count-api.scm +18 -11
……@@ -367,20 +367,27 @@
367367 (count-obj 'get-count PAIR))
368368
369369 (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))
372374
373375 ; Fully thread-safe fetch-and-increment.
374376 (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))
384391
385392 ; Return the observed count for the pair (L-ATOM, R-ATOM).
386393 ; Be careful to not create tha pair, if it doesn't exist.