-
Notifications
You must be signed in to change notification settings - Fork 28
Implementation of mechanisms for synchronisation of memory access at the knowledge level #483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 12 commits
9d8d7fa
bbd5206
1d0fc23
29cd498
84f8bac
ba1ff66
6e28a24
1a5d43d
2967adc
a4df08d
c433d47
06a7dcb
a418e36
5ca1034
c3e7cb1
f97767e
fd3440b
8e01f63
96e1c8f
af0f29a
ae7903c
e6e59d8
795c295
61b1539
cfd7d8d
6cf6c41
90fb0e5
8f972be
6143ff4
63c29a9
6c0bcee
40e6e49
fbea119
04b869b
2d56991
7f4f263
271ad88
21f83c7
1a46dac
9e5440d
37dd131
a32c7e4
43a1959
9d6304b
9cc97a1
2ce15b7
5ce3646
6310a81
e71d400
0911739
a06434e
8d97092
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include "sc_element_version.h" | ||
|
|
||
| #include <sc-store/sc_element.h> | ||
| #include <sc-core/sc-base/sc_allocator.h> | ||
|
|
||
| sc_element_version * sc_element_create_new_version(sc_element * element, sc_uint64 version_id, sc_type modified_fields) | ||
| { | ||
| if (element == NULL) | ||
| return NULL; | ||
|
|
||
| sc_element_version * new_version = sc_mem_new(sc_element_version, 1); | ||
| if (new_version == NULL) | ||
| return NULL; | ||
|
|
||
| new_version->data = element; | ||
| new_version->version_id = version_id; | ||
| new_version->prev_version = element->versions.tail; | ||
| new_version->next_version = NULL; | ||
| new_version->is_committed = SC_FALSE; | ||
| new_version->modified_fields = modified_fields; | ||
|
|
||
| if (element->versions.tail) | ||
| element->versions.tail->next_version = new_version; | ||
| else | ||
| element->versions.head = new_version; | ||
|
|
||
| element->versions.tail = new_version; | ||
|
|
||
| return new_version; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #ifndef SC_ELEMENT_VERSION_H | ||
| #define SC_ELEMENT_VERSION_H | ||
|
|
||
| #include <sc-core/sc_types.h> | ||
|
|
||
| typedef struct sc_element_version | ||
| { | ||
| sc_element* data; | ||
| sc_uint64 version_id; | ||
| struct sc_element_version * prev_version; | ||
| struct sc_element_version * next_version; | ||
| sc_bool is_committed; | ||
| sc_type modified_fields; | ||
| } sc_element_version; | ||
|
|
||
| typedef struct sc_version_chain | ||
| { | ||
| sc_element_version * head; | ||
| sc_element_version * tail; | ||
| } sc_version_chain; | ||
|
|
||
| typedef enum | ||
| { | ||
| SC_ELEMENT_FLAGS_MODIFIED = 1 << 0, | ||
| SC_ELEMENT_ARCS_MODIFIED = 1 << 1, | ||
| SC_ELEMENT_CONTENT_MODIFIED = 1 << 2, | ||
| SC_ELEMENT_LINKS_MODIFIED = 1 << 3 | ||
| } SC_ELEMENT_MODIFIED_FLAGS; | ||
|
|
||
| sc_element_version * sc_element_create_new_version(sc_element * element, sc_uint64 version_id, sc_type modified_fields); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||||||||||
| #include "sc_transaction.h" | ||||||||||||||
|
|
||||||||||||||
| #include <sc-core/sc-base/sc_allocator.h> | ||||||||||||||
|
|
||||||||||||||
| sc_transaction * sc_transaction_new(sc_uint64 const * txn_id) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that an int pointer is not needed here |
||||||||||||||
| { | ||||||||||||||
| if (txn_id == NULL) | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, use |
||||||||||||||
| return NULL; | ||||||||||||||
|
|
||||||||||||||
| sc_transaction * txn = sc_mem_new(sc_transaction, 1); | ||||||||||||||
| if (txn == NULL) | ||||||||||||||
| return NULL; | ||||||||||||||
|
|
||||||||||||||
| txn->transaction_id = *txn_id; | ||||||||||||||
| txn->is_committed = SC_FALSE; | ||||||||||||||
|
|
||||||||||||||
| txn->elements = sc_mem_new(sc_list, 1); | ||||||||||||||
| if (txn->elements == NULL) | ||||||||||||||
| { | ||||||||||||||
| sc_mem_free(txn); | ||||||||||||||
| return NULL; | ||||||||||||||
| } | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
|
|
||||||||||||||
| txn->transaction_buffer = sc_mem_new(sc_transaction_buffer, 1); | ||||||||||||||
| if (txn->transaction_buffer == NULL) | ||||||||||||||
| { | ||||||||||||||
| sc_mem_free(txn->elements); | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| sc_mem_free(txn); | ||||||||||||||
| return NULL; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| sc_transaction_buffer_initialize(txn->transaction_buffer); | ||||||||||||||
| sc_list_init(&txn->elements); | ||||||||||||||
|
|
||||||||||||||
| return txn; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void sc_transaction_destroy(sc_transaction * txn) | ||||||||||||||
| { | ||||||||||||||
| if (txn != NULL) | ||||||||||||||
| { | ||||||||||||||
| sc_list_clear(txn->elements); | ||||||||||||||
|
NikitaZotov marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| sc_mem_free(txn); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void sc_transaction_add_element(sc_transaction * txn, sc_element * element) {} | ||||||||||||||
|
|
||||||||||||||
| void sc_transaction_commit(sc_transaction * txn) {} | ||||||||||||||
|
|
||||||||||||||
| void sc_transaction_rollback(sc_transaction * txn) {} | ||||||||||||||
|
|
||||||||||||||
| sc_bool sc_transaction_validate(sc_transaction * txn) | ||||||||||||||
| { | ||||||||||||||
| return SC_FALSE; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| void sc_transaction_merge(sc_transaction * txn) {} | ||||||||||||||
|
|
||||||||||||||
| void sc_transaction_apply(sc_transaction * txn) {} | ||||||||||||||
|
|
||||||||||||||
| void sc_transaction_clear(sc_transaction * txn) {} | ||||||||||||||
|
|
||||||||||||||
| sc_bool sc_transaction_element_new(sc_transaction * txn, sc_element * element) {} | ||||||||||||||
|
|
||||||||||||||
| sc_bool sc_transaction_element_change( | ||||||||||||||
| sc_element * element, | ||||||||||||||
| sc_transaction * txn, | ||||||||||||||
| SC_ELEMENT_MODIFIED_FLAGS modified_flags, | ||||||||||||||
| sc_element const * new_data) | ||||||||||||||
| { | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| sc_bool sc_transaction_element_remove(sc_transaction * txn, sc_addr addr) {} | ||||||||||||||
|
|
||||||||||||||
| sc_bool sc_transaction_element_content_set(sc_transaction * txn, sc_addr addr, sc_stream * content) {} | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #ifndef SC_TRANSACTION_H | ||
| #define SC_TRANSACTION_H | ||
|
|
||
| #include <sc-store/sc-transaction/sc_element_version.h> | ||
| #include <sc-store/sc-transaction/sc_transaction_buffer.h> | ||
|
|
||
| #include <sc-core/sc_stream.h> | ||
| #include <sc-core/sc-container/sc_list.h> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider including |
||
|
|
||
| typedef struct sc_transaction | ||
| { | ||
| sc_uint64 transaction_id; | ||
| sc_bool is_committed; | ||
| sc_list * elements; | ||
| sc_transaction_buffer * transaction_buffer; | ||
| } sc_transaction; | ||
|
|
||
| sc_transaction * sc_transaction_new(sc_uint64 const * txn_id); | ||
| // create a new transaction | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use another style for code strings
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly should be adjusted to match the required code style? |
||
| void sc_transaction_destroy(sc_transaction * txn); | ||
| // destroy the given transaction | ||
|
|
||
| sc_bool sc_transaction_element_new(sc_transaction * txn, sc_element * element); | ||
| sc_bool sc_transaction_element_change( | ||
| sc_element * element, | ||
| sc_transaction * txn, | ||
| SC_ELEMENT_MODIFIED_FLAGS modified_flags, | ||
| sc_element const * new_data); | ||
| sc_bool sc_transaction_element_remove(sc_transaction * txn, sc_addr addr); | ||
| sc_bool sc_transaction_element_content_set(sc_transaction * txn, sc_addr addr, sc_stream * content); | ||
|
|
||
| void sc_transaction_commit(sc_transaction * txn); | ||
| // apply all operations of the transaction on sc-memory | ||
| void sc_transaction_rollback(sc_transaction * txn); | ||
| // rollback the transaction operations | ||
|
|
||
| sc_bool sc_transaction_validate(sc_transaction * txn); | ||
| // check if the transaction can be applied based on element versions and free segments | ||
| void sc_transaction_merge(sc_transaction * txn); | ||
| // check versions of all elements in the transaction and try to merge them | ||
| void sc_transaction_apply(sc_transaction * txn); | ||
| // apply all operations (merged versions, allocated spaces) to sc-memory | ||
| void sc_transaction_clear(sc_transaction * txn); | ||
| // deletes all transaction items and clears them without performing a commit | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,175 @@ | ||||||||
| #include "sc_transaction_buffer.h" | ||||||||
|
|
||||||||
| #include <sc-store/sc-transaction/sc_element_version.h> | ||||||||
| #include <sc-core/sc-base/sc_allocator.h> | ||||||||
| #include <sc-core/sc-container/sc_list.h> | ||||||||
| #include <sc-core/sc_stream.h> | ||||||||
|
|
||||||||
| typedef struct sc_modified_element { | ||||||||
| sc_addr addr; | ||||||||
| sc_element_version * version; | ||||||||
| sc_stream * content; | ||||||||
| SC_ELEMENT_MODIFIED_FLAGS flags; | ||||||||
| } sc_modified_element; | ||||||||
|
|
||||||||
| sc_bool sc_transaction_buffer_initialize(sc_transaction_buffer * buffer) | ||||||||
| { | ||||||||
| if (buffer == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| buffer->new_elements = sc_mem_new(sc_list, 1); | ||||||||
| if (buffer->new_elements == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| sc_list_init(&buffer->new_elements); | ||||||||
|
|
||||||||
| buffer->modified_elements = sc_mem_new(sc_list, 1); | ||||||||
| if (buffer->modified_elements == null_ptr) | ||||||||
| { | ||||||||
| sc_mem_free(buffer->new_elements); | ||||||||
| return SC_FALSE; | ||||||||
| } | ||||||||
| sc_list_init(&buffer->modified_elements); | ||||||||
|
|
||||||||
| buffer->deleted_elements = sc_mem_new(sc_list, 1); | ||||||||
| if (buffer->deleted_elements == null_ptr) | ||||||||
| { | ||||||||
| sc_mem_free(buffer->new_elements); | ||||||||
| sc_mem_free(buffer->modified_elements); | ||||||||
| return SC_FALSE; | ||||||||
| } | ||||||||
| sc_list_init(&buffer->deleted_elements); | ||||||||
|
|
||||||||
| return SC_TRUE; | ||||||||
| } | ||||||||
|
|
||||||||
| sc_bool sc_transaction_buffer_created_add(sc_transaction_buffer * buffer, sc_addr addr) | ||||||||
| { | ||||||||
| if (buffer == null_ptr || buffer->new_elements == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| if (SC_ADDR_IS_EMPTY(addr)) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| if (transaction_buffer_contains_created(buffer, addr)) | ||||||||
| return SC_TRUE; | ||||||||
|
|
||||||||
| sc_addr * addr_copy = sc_mem_new(sc_addr, 1); | ||||||||
| if (addr_copy == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| *addr_copy = addr; | ||||||||
|
|
||||||||
| if (sc_list_push_back(buffer->new_elements, addr_copy) == null_ptr) | ||||||||
| { | ||||||||
| sc_mem_free(addr_copy); | ||||||||
| return SC_FALSE; | ||||||||
| } | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is preferable to store in such lists not a pointer to an sc-address, but rather the hash of the sc-address, cast to void *. To obtain the sc-address hash from the sc-address, use the SC_ADDR_LOCAL_TO_INT macro. This approach is more efficient and memory-friendly compared to using pointers to objects.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to introduce this approach everywhere |
||||||||
|
|
||||||||
| return SC_TRUE; | ||||||||
| } | ||||||||
|
|
||||||||
| sc_bool sc_transaction_buffer_modified_add( | ||||||||
| sc_transaction_buffer * buffer, | ||||||||
| sc_addr addr, | ||||||||
| sc_element * element, | ||||||||
| sc_stream * content, | ||||||||
| SC_ELEMENT_MODIFIED_FLAGS flags) | ||||||||
| { | ||||||||
| if (buffer == null_ptr || buffer->modified_elements == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| if (SC_ADDR_IS_EMPTY(addr)) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| sc_element_version * new_version = sc_element_create_new_version(element, /* version_id */ 0, flags); // Add generation for id | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See |
||||||||
| if (new_version == NULL) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| sc_iterator * it = sc_list_iterator(buffer->modified_elements); | ||||||||
| while (sc_iterator_next(it)) | ||||||||
| { | ||||||||
| sc_modified_element * mod = (sc_modified_element *) sc_iterator_get(it); | ||||||||
| if (SC_ADDR_IS_EQUAL(mod->addr, addr)) | ||||||||
| { | ||||||||
| mod->version = new_version; | ||||||||
| mod->content = content; | ||||||||
| mod->flags = flags; | ||||||||
| sc_iterator_destroy(it); | ||||||||
| return SC_TRUE; | ||||||||
| } | ||||||||
| } | ||||||||
| sc_iterator_destroy(it); | ||||||||
|
|
||||||||
| sc_modified_element * new_mod = sc_mem_new(sc_modified_element, 1); | ||||||||
| if (new_mod == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| new_mod->addr = addr; | ||||||||
| new_mod->version = new_version; | ||||||||
| new_mod->content = content; | ||||||||
| new_mod->flags = flags; | ||||||||
|
|
||||||||
| if (sc_list_push_back(buffer->modified_elements, new_mod) == null_ptr) | ||||||||
| { | ||||||||
| sc_mem_free(new_version); | ||||||||
| sc_mem_free(new_mod); | ||||||||
| return SC_FALSE; | ||||||||
| } | ||||||||
|
|
||||||||
| return SC_TRUE; | ||||||||
| } | ||||||||
|
|
||||||||
| sc_bool sc_transaction_buffer_removed_add(sc_transaction_buffer * buffer, sc_addr addr) | ||||||||
| { | ||||||||
| if (buffer == null_ptr || buffer->deleted_elements == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| if (SC_ADDR_IS_EMPTY(addr)) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| sc_iterator * it = sc_list_iterator(buffer->deleted_elements); | ||||||||
| while (sc_iterator_next(it)) | ||||||||
| { | ||||||||
| sc_addr * stored_addr = (sc_addr *) sc_iterator_get(it); | ||||||||
| if (SC_ADDR_IS_EQUAL(*stored_addr, addr)) | ||||||||
| { | ||||||||
| sc_iterator_destroy(it); | ||||||||
| return SC_TRUE; | ||||||||
| } | ||||||||
| } | ||||||||
| sc_iterator_destroy(it); | ||||||||
|
|
||||||||
| sc_addr * addr_copy = sc_mem_new(sc_addr, 1); | ||||||||
| if (addr_copy == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| *addr_copy = addr; | ||||||||
| if (sc_list_push_back(buffer->deleted_elements, addr_copy) == null_ptr) | ||||||||
| { | ||||||||
| sc_mem_free(addr_copy); | ||||||||
| return SC_FALSE; | ||||||||
| } | ||||||||
|
|
||||||||
| return SC_TRUE; | ||||||||
| } | ||||||||
|
|
||||||||
| sc_bool transaction_buffer_contains_created(sc_transaction_buffer const * buffer, sc_addr addr) | ||||||||
| { | ||||||||
| if (buffer == null_ptr || buffer->new_elements == null_ptr) | ||||||||
| return SC_FALSE; | ||||||||
|
|
||||||||
| sc_iterator * it = sc_list_iterator(buffer->new_elements); | ||||||||
| while (sc_iterator_next(it)) | ||||||||
| { | ||||||||
| sc_addr * stored_addr = (sc_addr *) sc_iterator_get(it); | ||||||||
| if (SC_ADDR_IS_EQUAL(*stored_addr, addr)) | ||||||||
| { | ||||||||
| sc_iterator_destroy(it); | ||||||||
| return SC_TRUE; | ||||||||
| } | ||||||||
| } | ||||||||
| sc_iterator_destroy(it); | ||||||||
|
|
||||||||
| return SC_FALSE; | ||||||||
| } | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Quality: .gitignore ignores all .cmake and .tcl files
The new .gitignore rules add blanket
*.cmakeand*.tclpatterns. This will silently ignore legitimately tracked CMake modules/config files (e.g. Find*.cmake, project config templates) across the repo, causing future such files to be missed by git add. Scope these ignores to build directories rather than matching every .cmake/.tcl in the tree.Was this helpful? React with 👍 / 👎