From d347c96da646a617561dd5b90634a7b19628ad16 Mon Sep 17 00:00:00 2001 From: coshcage <58808125+coshcage@users.noreply.github.com> Date: Wed, 31 Jan 2024 04:57:59 +0000 Subject: [PATCH] Add files via upload --- src/sicore.c | 36 ++++++++++++++++++++++++++++++++++-- src/silock.c | 10 +++++++++- src/sitable.c | 22 ++++++++++++++++++++-- src/sitrans.c | 22 +++++++++++++++++++++- src/svimrdb.h | 18 +++++++++++------- 5 files changed, 95 insertions(+), 13 deletions(-) diff --git a/src/sicore.c b/src/sicore.c index a0216b3..1232279 100644 --- a/src/sicore.c +++ b/src/sicore.c @@ -2,7 +2,7 @@ * Name: svimrdb.h * Description: SI core functions. * Author: cosh.cage#hotmail.com - * File ID: 0628231947B1101231110L00741 + * File ID: 0628231947B0130242056L00773 * License: GPLv2. */ #include /* Using macro BUFSIZ. */ @@ -11,7 +11,7 @@ #include /* Using function roundf, round. */ #include "svimrdb.h" -/* size_t integer copmaration function. */ +/* size_t integer comparation function. */ extern int _grpCBFCompareInteger(const void * px, const void * py); static int _sicbfcmp(const void * px, const void * py); static int _sicbftvsMergeView(void * pitem, size_t param); @@ -20,6 +20,7 @@ static int _sicbftvsMergeView(void * pitem, size_t param); * This variable is used to store the view column number. */ static size_t _sizCUTTarget; +pthread_mutex_t mtxSCT = PTHREAD_MUTEX_INITIALIZER; /* Attention: This Is An Internal Function. No Interface for Library Users. * Function name: _sicbfcmp @@ -35,6 +36,7 @@ static int _sicbfcmp(const void * px, const void * py) size_t i; P_CELL pcx, pcy; + pthread_mutex_lock(&mtxSCT); for (i = 0; i < _sizCUTTarget; ++i) { @@ -72,13 +74,25 @@ static int _sicbfcmp(const void * px, const void * py) if (0 == r) continue; else + { + pthread_mutex_unlock(&mtxSCT); return r; + } } else if (NULL == pcx && NULL != pcy) + { + pthread_mutex_unlock(&mtxSCT); return -1; + } else if (NULL != pcx && NULL == pcy) + { + pthread_mutex_unlock(&mtxSCT); return 1; + } } + + pthread_mutex_unlock(&mtxSCT); + return r; } @@ -92,12 +106,14 @@ static int _sicbfcmp(const void * px, const void * py) */ static int _sicbftvsMergeView(void * pitem, size_t param) { + pthread_mutex_lock(&mtxSCT); memcpy ( ((P_MATRIX)(0[(size_t *)param]))->arrz.pdata + 1[(size_t *)param]++ * _sizCUTTarget * sizeof(P_CELL), *(P_CELL *)(P2P_BSTNODE(pitem)->knot.pdata), _sizCUTTarget * sizeof(P_CELL) ); + pthread_mutex_unlock(&mtxSCT); return CBF_CONTINUE; } @@ -122,8 +138,12 @@ P_MATRIX siCreateUniqueView(P_MATRIX pmtx) setInitT(&set); + pthread_mutex_lock(&mtxSCT); + _sizCUTTarget = pmtx->col; + pthread_mutex_unlock(&mtxSCT); + for (j = i = 0; i < pmtx->ln; ++i) { P_CELL * ptuple = strGetValueMatrix(NULL, pmtx, i, 0, sizeof(P_CELL)); @@ -217,8 +237,12 @@ P_MATRIX siCreateUnionView(P_MATRIX pmtxa, P_MATRIX pmtxb) setInitT(&set); + pthread_mutex_lock(&mtxSCT); + _sizCUTTarget = pma->col; + pthread_mutex_unlock(&mtxSCT); + for (j = i = 0; i < pma->ln; ++i) { P_CELL * ptuple = strGetValueMatrix(NULL, pma, i, 0, sizeof(P_CELL)); @@ -284,8 +308,12 @@ P_MATRIX siCreateIntersectionView(P_MATRIX pmtxa, P_MATRIX pmtxb) setInitT(&seta); setInitT(&setb); + pthread_mutex_lock(&mtxSCT); + _sizCUTTarget = pma->col; + pthread_mutex_unlock(&mtxSCT); + for (i = 0; i < pma->ln; ++i) { ptuple = strGetValueMatrix(NULL, pma, i, 0, sizeof(P_CELL)); @@ -360,8 +388,12 @@ P_MATRIX siCreateDifferenceView(P_MATRIX pmtxa, P_MATRIX pmtxb) setInitT(&seta); setInitT(&setb); + pthread_mutex_lock(&mtxSCT); + _sizCUTTarget = pma->col; + pthread_mutex_unlock(&mtxSCT); + for (i = 0; i < pma->ln; ++i) { ptuple = strGetValueMatrix(NULL, pma, i, 0, sizeof(P_CELL)); diff --git a/src/silock.c b/src/silock.c index 9c580ee..bdc9d66 100644 --- a/src/silock.c +++ b/src/silock.c @@ -2,7 +2,7 @@ * Name: silock.c * Description: Lock functions. * Author: cosh.cage#hotmail.com - * File ID: 0704231516F0708231202L00145 + * File ID: 0704231516F0130242056L00153 * License: GPLv2. */ @@ -22,6 +22,7 @@ static BOOL const bCompatibleMatrix[][6] = }; extern P_SET_T psetTrans; /* Transactions. */ +extern pthread_mutex_t mtxPST; /* Attention: This Is An Internal Function. No Interface for Library Users. * Function name: _sicbfcmpLock @@ -114,13 +115,20 @@ BOOL siTrylock(P_TRANS ptrans, void * pobj, LockType lt) a[2] = (size_t)ptrans; a[3] = FALSE; + pthread_mutex_lock(&mtxPST); + if (NULL != psetTrans) { setTraverseT(psetTrans, _sicbftvsTrans, (size_t)a, ETM_LEVELORDER); if (FALSE != a[3]) + { + pthread_mutex_unlock(&mtxPST); return FALSE; + } } + pthread_mutex_unlock(&mtxPST); + setInsertT(&ptrans->setlock, &l, sizeof(LOCK), _sicbfcmpLock); return TRUE; } diff --git a/src/sitable.c b/src/sitable.c index 2e4d3b3..2200247 100644 --- a/src/sitable.c +++ b/src/sitable.c @@ -2,7 +2,7 @@ * Name: sitable.c * Description: SI functions for tables. * Author: cosh.cage#hotmail.com - * File ID: 0628231947C1101231110L00978 + * File ID: 0628231947C0130242056L00996 * License: GPLv2. */ #define _CRT_SECURE_NO_WARNINGS @@ -16,6 +16,9 @@ static size_t sizSVTarget = 0; /* Variable for sorting column of a table. */ static BOOL bAscend = TRUE; /* Ascend or descend for TRUE or FALSE respectively. */ +pthread_mutex_t mtxSST = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t mtxBAD = PTHREAD_MUTEX_INITIALIZER; + /* Attention: This Is An Internal Function. No Interface for Library Users. * Function name: _sicbfcmpSV * Description: This function is used to compare cells of a view. @@ -29,8 +32,14 @@ static int _sicbfcmpSV(const void * px, const void * py) { int r = 0; P_CELL pcx, pcy; + + pthread_mutex_lock(&mtxSST); + pcx = *((P_CELL *)px + sizSVTarget); pcy = *((P_CELL *)py + sizSVTarget); + + pthread_mutex_unlock(&mtxSST); + if (NULL != pcx && NULL != pcy) { switch (pcx->ct) @@ -85,8 +94,17 @@ void siSortView(P_MATRIX pmtx, size_t col, BOOL ascd) { if (col >= pmtx->col) return; + + pthread_mutex_lock(&mtxSST); + pthread_mutex_lock(&mtxBAD); + sizSVTarget = col; bAscend = ascd; + + pthread_mutex_unlock(&mtxBAD); + pthread_mutex_unlock(&mtxSST); + + qsort(pmtx->arrz.pdata, pmtx->ln, sizeof(P_CELL) * pmtx->col, _sicbfcmpSV); } @@ -450,7 +468,7 @@ BOOL siInsertIntoTable(P_TRANS ptrans, P_TABLE ptbl, ...) switch (pt->ct) { case CT_CHAR: - cd.c = va_arg(arg, char); + cd.c = (char)va_arg(arg, char); pc = siCreateCell(&cd.c, pt->ct); if (NULL != pt->phsh) { diff --git a/src/sitrans.c b/src/sitrans.c index edf5834..de0f14f 100644 --- a/src/sitrans.c +++ b/src/sitrans.c @@ -2,7 +2,7 @@ * Name: sitrans.c * Description: Transaction control. * Author: cosh.cage#hotmail.com - * File ID: 0702231427D0809230919L00340 + * File ID: 0702231427D0130242055L00360 * License: GPLv2. */ @@ -13,6 +13,7 @@ /* A set of transactions. */ P_SET_T psetTrans = NULL; +pthread_mutex_t mtxPST = PTHREAD_MUTEX_INITIALIZER; /* Compare function declaration. */ extern int _grpCBFCompareInteger(const void * px, const void * py); @@ -31,9 +32,15 @@ P_TRANS siBeginTransaction() return NULL; queInitDL(&pt->qoprlst); setInitT(&pt->setlock); + + pthread_mutex_lock(&mtxPST); + if (NULL == psetTrans) psetTrans = setCreateT(); setInsertT(psetTrans, &pt, sizeof(P_TRANS), _grpCBFCompareInteger); + + pthread_mutex_unlock(&mtxPST); + return pt; } @@ -85,7 +92,11 @@ void siCommitTransaction(P_TRANS ptrans) break; } } + pthread_mutex_lock(&mtxPST); + setRemoveT(psetTrans, &ptrans, sizeof(P_TRANS), _grpCBFCompareInteger); + + pthread_mutex_unlock(&mtxPST); setFreeT(&ptrans->setlock); free(ptrans); } @@ -320,7 +331,12 @@ void siRollbackTransaction(P_ARRAY_Z * pparr, P_TRANS ptrans) if (NULL != pparr && 0 != m) strResizeArrayZ(*pparr, m, sizeof(TBLREF)); + pthread_mutex_lock(&mtxPST); + setRemoveT(psetTrans, &ptrans, sizeof(P_TRANS), _grpCBFCompareInteger); + + pthread_mutex_unlock(&mtxPST); + setFreeT(&ptrans->setlock); free(ptrans); } @@ -334,6 +350,10 @@ void siRollbackTransaction(P_ARRAY_Z * pparr, P_TRANS ptrans) */ void siReleaseAllTransaction() { + pthread_mutex_lock(&mtxPST); + setDeleteT(psetTrans); psetTrans = NULL; + + pthread_mutex_unlock(&mtxPST); } diff --git a/src/svimrdb.h b/src/svimrdb.h index 02dac83..931cab0 100644 --- a/src/svimrdb.h +++ b/src/svimrdb.h @@ -2,19 +2,20 @@ * Name: svimrdb.h * Description: StoneValley in-memory relational database (aka SI). * Author: cosh.cage#hotmail.com - * File ID: 0628231947A00809230919L00190 + * File ID: 0628231947A0130242055L00197 * License: GPLv2. */ #ifndef _SVIMRDB_H_ #define _SVIMRDB_H_ /* Include StoneValley headers. */ -#include "StoneValley/src/svstring.h" -#include "StoneValley/src/svtree.h" -#include "StoneValley/src/svset.h" -#include "StoneValley/src/svqueue.h" -#include "StoneValley/src/svhash.h" +#include "svstring.h" +#include "svtree.h" +#include "svset.h" +#include "svqueue.h" +#include "svhash.h" #include /* Using function wcslen, wcscmp, wprintf, wcscmp. */ +#include /* Cell type. */ typedef enum en_CellType @@ -187,6 +188,9 @@ BOOL siTrylock(P_TRANS ptrans, void * pobj, LockType lt); void siUnlock(P_TRANS ptrans, void * pobj, LockType lt); #define BKSNUM 1021 /* 1021 is a prime. */ -#define strdup _strdup /* POSIX compliant for visual C compiler. */ +// #define strdup _strdup /* POSIX compliant for visual C compiler. */ + +//#define pthread_mutex_lock(abc) +//#define pthread_mutex_unlock(def) #endif