From 34fe6a5a90a381437a499ac699e89bc82ef0f3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Thu, 10 Feb 2000 11:12:36 -0800 Subject: [PATCH] threading should now work, your mileage may vary.. Rev: src/modules/Oracle/oracle.c:1.19 --- src/modules/Oracle/oracle.c | 143 ++++++++++++++++++++++++++++++++++-- 1 file changed, 136 insertions(+), 7 deletions(-) diff --git a/src/modules/Oracle/oracle.c b/src/modules/Oracle/oracle.c index 751be1582b..d07575ca32 100644 --- a/src/modules/Oracle/oracle.c +++ b/src/modules/Oracle/oracle.c @@ -1,5 +1,5 @@ /* - * $Id: oracle.c,v 1.18 1999/11/05 23:43:28 marcus Exp $ + * $Id: oracle.c,v 1.19 2000/02/10 19:12:36 hubbe Exp $ * * Pike interface to Oracle databases. * @@ -36,17 +36,31 @@ #endif -RCSID("$Id: oracle.c,v 1.18 1999/11/05 23:43:28 marcus Exp $"); +RCSID("$Id: oracle.c,v 1.19 2000/02/10 19:12:36 hubbe Exp $"); #ifdef HAVE_ORACLE #define BLOB_FETCH_CHUNK 16384 +#define ORACLE_USE_THREADS +#define SERIALIZE_CONNECT + +/* #define SERIALIZE_ALL */ + + +#ifndef ORACLE_USE_THREADS + #undef THREADS_ALLOW #define THREADS_ALLOW() #undef THREADS_DISALLOW #define THREADS_DISALLOW() +#endif + +#if defined(SERIALIZE_ALL) || defined(SERIALIZE_CONNECT) +DEFINE_MUTEX(oracle_serialization_mutex); +#endif + struct program *oracle_program = NULL, *oracle_result_program = NULL; struct dbcurs { @@ -107,10 +121,24 @@ static void f_result_create(INT32 args) INT32 i; get_all_args("Oracle.oracle_result->create", args, "%o", &p); - - if(!(dbcon = (struct dbcon *)get_storage(p, oracle_program)) || - !(curs = dbcon->share_cda)) - error("Bad argument 1 to Oracle.oracle_result->create()\n"); + + if(p && !p->prog) + error("Bad argument 1 to Oracle.oracle_result->create(), destructd object!\n"); + + if(!(dbcon = (struct dbcon *)get_storage(p, oracle_program))) + { +#if 0 + describe(p); + dump_program_desc(p->prog); + + describe(oracle_program); + dump_program_desc(oracle_program); +#endif + error("Bad argument 1 to Oracle.oracle_result->create(), not an oracle object\n"); + } + + if(!(curs = dbcon->share_cda)) + error("Unititialized object as argument 1 to Oracle.oracle_result->create()\n"); r->curs = curs; dbcon->share_cda = NULL; @@ -133,6 +161,10 @@ static void f_num_fields(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + for(i=11; ; i+=10) if((rc = odescr(r->cda, i, &siz, NULL, NULL, NULL, NULL, NULL, NULL, NULL))) @@ -144,6 +176,10 @@ static void f_num_fields(INT32 args) NULL, NULL, NULL))) break; +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(r->cda->rc != 1007) @@ -175,9 +211,17 @@ static void f_fetch_fields(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + rc = odescr(r->cda, i+1, &siz, &typ, nambuf, &cbufl, &dispsz, NULL, &scale, NULL); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc || cbufl < nambufsz) break; @@ -266,9 +310,17 @@ static void f_fetch_row(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + rc = odescr(r->cda, i+1, &siz, &typ, NULL, NULL, &dsiz, NULL, NULL, NULL); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) { @@ -289,6 +341,10 @@ static void f_fetch_row(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + s->rcode = 0; s->indp = -1; @@ -297,6 +353,10 @@ static void f_fetch_row(INT32 args) typ : SQLT_STR), -1, &s->indp, NULL, -1, -1, &s->rsiz, &s->rcode); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) { @@ -321,8 +381,16 @@ static void f_fetch_row(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + rc = ofetch(r->cda); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) { @@ -398,8 +466,16 @@ static struct dbcurs *make_cda(struct dbcon *dbcon) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + rc=oopen(&curs->cda, &dbcon->lda, NULL, -1, -1, NULL, -1); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) { @@ -433,11 +509,19 @@ static void f_create(INT32 args) THREADS_ALLOW(); +#if defined(SERIALIZE_ALL) || defined(SERIALIZE_CONNECT) + mt_lock( & oracle_serialization_mutex ); +#endif + rc = olog(&dbcon->lda, (ub1*)dbcon->hda, uid->str, uid->len, (passwd? passwd->str:NULL), (passwd? passwd->len:-1), (host? host->str:NULL), (host? host->len:-1), OCI_LM_DEF); +#if defined(SERIALIZE_ALL) || defined(SERIALIZE_CONNECT) + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) @@ -471,9 +555,17 @@ static void f_big_query(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + ocan(&curs->cda); rc = oparse(&curs->cda, query->str, query->len, 1, 2); + +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif THREADS_DISALLOW(); @@ -544,8 +636,16 @@ static void f_big_query(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + rc = oexec(&curs->cda); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) { @@ -577,9 +677,17 @@ static void f_big_query(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + rc = odescr(&curs->cda, cols+1, &siz, &typ, cbuf, &cbufl, &dispsz, &prec, &scale, &nullok); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) { @@ -637,6 +745,10 @@ static void f_list_tables(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + ocan(&curs->cda); if(wild) { @@ -647,6 +759,10 @@ static void f_list_tables(INT32 args) -1, NULL, NULL, -1, 0); } else rc = oparse(&curs->cda, "select tname from tab", -1, 1, 2); + +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif THREADS_DISALLOW(); @@ -658,8 +774,16 @@ static void f_list_tables(INT32 args) THREADS_ALLOW(); +#ifdef SERIALIZE_ALL + mt_lock( & oracle_serialization_mutex ); +#endif + rc = oexec(&curs->cda); +#ifdef SERIALIZE_ALL + mt_unlock( & oracle_serialization_mutex ); +#endif + THREADS_DISALLOW(); if(rc) { @@ -699,7 +823,12 @@ void pike_module_init(void) putenv("ORACLE_SID="ORACLE_SID); #endif - /* opinit(OCI_EV_TSF); */ +#ifdef ORACLE_USE_THREADS + opinit(OCI_EV_TSF); +#endif + + if(oracle_program) + fatal("Oracle module initiated twice!\n"); start_new_program(); ADD_STORAGE(struct dbcon); -- GitLab