diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2020-12-05 21:00:49 +0100 |
|---|---|---|
| committer | DanielGavin <danielgavin5@hotmail.com> | 2020-12-05 21:00:49 +0100 |
| commit | 79e4c393e9b23574aa1d59ce2ccafbc60643a49a (patch) | |
| tree | e118e76a38b6c52fb56ffbd1fd60f98ef8c5d85c /src/server/documents.odin | |
| parent | 498e8a3895cd5b1db756b7f61eb48d1fd4211460 (diff) | |
requests are now made into tasks
Diffstat (limited to 'src/server/documents.odin')
| -rw-r--r-- | src/server/documents.odin | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/server/documents.odin b/src/server/documents.odin index 5a0261c..dedc74a 100644 --- a/src/server/documents.odin +++ b/src/server/documents.odin @@ -10,6 +10,8 @@ import "core:odin/tokenizer" import "core:path" import "core:mem" +import "intrinsics" + import "shared:common" ParserError :: struct { @@ -36,6 +38,7 @@ Document :: struct { imports: [] Package, package_name: string, allocator: ^common.Scratch_Allocator, //because does not support freeing I use arena allocators for each document + operating_on: int, //atomic }; DocumentStorage :: struct { @@ -75,7 +78,23 @@ document_get :: proc(uri_string: string) -> ^Document { return nil; } - return &document_storage.documents[uri.path]; + document := &document_storage.documents[uri.path]; + + if document == nil { + return nil; + } + + intrinsics.atomic_add(&document.operating_on, 1); + + return document; +} + +document_release :: proc(document: ^Document) { + + if document != nil { + intrinsics.atomic_sub(&document.operating_on, 1); + } + } /* @@ -126,7 +145,7 @@ document_open :: proc(uri_string: string, text: string, config: ^common.Config, return err; } - document_storage.documents[uri.path] = document; + document_storage.documents[strings.clone(uri.path)] = document; } |