From fa92e78f8c56c40f51abab765f5212b87c472fc7 Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Tue, 23 Jan 2024 14:21:43 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20mutex=5F?= =?UTF-8?q?GetVersionModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pkg/network/grpc/grpc_client/grpc_client_table.go_ | 6 ++++++ .../pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ index e12a72d..0b376ab 100644 --- a/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ +++ b/bin/templates/pkg/network/grpc/grpc_client/grpc_client_table.go_ @@ -8,6 +8,7 @@ import ( "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "log" + "sync" "time" ) @@ -21,9 +22,14 @@ const TableName string = "lawsuit_status_types" type Crud_GRPC struct { } +// mutex_GetVersionModel - защита от многопоточности GetVersionModel() +var mutex_GetVersionModel = sync.Mutex{} + // GetVersionModel - возвращает хэш версии структуры модели func (crud Crud_GRPC) GetVersionModel() uint32 { if VersionModel == 0 { + mutex_GetVersionModel.Lock() + defer mutex_GetVersionModel.Unlock() VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() } return VersionModel diff --git a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ index 0ad505d..a97f041 100644 --- a/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ +++ b/bin/templates/pkg/network/nrpc/nrpc_client/nrpc_client_table.go_ @@ -7,6 +7,7 @@ import ( "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/nrpc/grpc_client/constants" "gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/object_model/entities/lawsuit_status_types" "log" + "sync" ) // VersionModel - хранит версию структуры модели @@ -19,9 +20,14 @@ const TableName string = "lawsuit_status_types" type Crud_NRPC struct { } +// mutex_GetVersionModel - защита от многопоточности GetVersionModel() +var mutex_GetVersionModel = sync.Mutex{} + // GetVersionModel - возвращает хэш версии структуры модели func (crud Crud_NRPC) GetVersionModel() uint32 { if VersionModel == 0 { + mutex_GetVersionModel.Lock() + defer mutex_GetVersionModel.Unlock() VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion() } return VersionModel