Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
coshcage authored Jan 31, 2024
1 parent a906580 commit d347c96
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 13 deletions.
36 changes: 34 additions & 2 deletions src/sicore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h> /* Using macro BUFSIZ. */
Expand All @@ -11,7 +11,7 @@
#include <math.h> /* 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);
Expand All @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 9 additions & 1 deletion src/silock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Name: silock.c
* Description: Lock functions.
* Author: cosh.cage#hotmail.com
* File ID: 0704231516F0708231202L00145
* File ID: 0704231516F0130242056L00153
* License: GPLv2.
*/

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 20 additions & 2 deletions src/sitable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
{
Expand Down
22 changes: 21 additions & 1 deletion src/sitrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Name: sitrans.c
* Description: Transaction control.
* Author: cosh.cage#hotmail.com
* File ID: 0702231427D0809230919L00340
* File ID: 0702231427D0130242055L00360
* License: GPLv2.
*/

Expand All @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
18 changes: 11 additions & 7 deletions src/svimrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <wchar.h> /* Using function wcslen, wcscmp, wprintf, wcscmp. */
#include <pthread.h>

/* Cell type. */
typedef enum en_CellType
Expand Down Expand Up @@ -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

0 comments on commit d347c96

Please sign in to comment.