00001 /****************************************************** 00002 Sessions 00003 00004 (c) 1996 Innobase Oy 00005 00006 Created 6/25/1996 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #include "usr0sess.h" 00010 00011 #ifdef UNIV_NONINL 00012 #include "usr0sess.ic" 00013 #endif 00014 00015 #include "trx0trx.h" 00016 00017 /************************************************************************* 00018 Closes a session, freeing the memory occupied by it. */ 00019 static 00020 void 00021 sess_close( 00022 /*=======*/ 00023 sess_t* sess); /* in, own: session object */ 00024 00025 /************************************************************************* 00026 Opens a session. */ 00027 00028 sess_t* 00029 sess_open(void) 00030 /*===========*/ 00031 /* out, own: session object */ 00032 { 00033 sess_t* sess; 00034 00035 #ifdef UNIV_SYNC_DEBUG 00036 ut_ad(mutex_own(&kernel_mutex)); 00037 #endif /* UNIV_SYNC_DEBUG */ 00038 sess = mem_alloc(sizeof(sess_t)); 00039 00040 sess->state = SESS_ACTIVE; 00041 00042 sess->trx = trx_create(sess); 00043 00044 UT_LIST_INIT(sess->graphs); 00045 00046 return(sess); 00047 } 00048 00049 /************************************************************************* 00050 Closes a session, freeing the memory occupied by it. */ 00051 static 00052 void 00053 sess_close( 00054 /*=======*/ 00055 sess_t* sess) /* in, own: session object */ 00056 { 00057 #ifdef UNIV_SYNC_DEBUG 00058 ut_ad(mutex_own(&kernel_mutex)); 00059 #endif /* UNIV_SYNC_DEBUG */ 00060 ut_ad(sess->trx == NULL); 00061 00062 mem_free(sess); 00063 } 00064 00065 /************************************************************************* 00066 Closes a session, freeing the memory occupied by it, if it is in a state 00067 where it should be closed. */ 00068 00069 ibool 00070 sess_try_close( 00071 /*===========*/ 00072 /* out: TRUE if closed */ 00073 sess_t* sess) /* in, own: session object */ 00074 { 00075 #ifdef UNIV_SYNC_DEBUG 00076 ut_ad(mutex_own(&kernel_mutex)); 00077 #endif /* UNIV_SYNC_DEBUG */ 00078 if (UT_LIST_GET_LEN(sess->graphs) == 0) { 00079 sess_close(sess); 00080 00081 return(TRUE); 00082 } 00083 00084 return(FALSE); 00085 }
1.4.7

