Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Data Structures

Critical section

The thread between the parts that require mutual exclusion (lock table, page buffer, and access / modification of the operation) was designated as a critical section.

The critical section has been defined as follows.

CSECT_ER_LOG_FILELatch for error msg log file
CSECT_ER_MSG_CACHELatch for error msg cache
CSECT_WFGLatch for wait-for-graph
CSECT_LOGLatch for log manager
CSECT_LOCATOR_SR_CLASSNAME_TABLELatch for temp classname to classOID entries
CSECT_FILE_NEWFILELatch related to new file table
CSECT_QPROC_QUERY_TABLELatch for query manager table
CSECT_QPROC_QFILE_PGCNTLatch for query file page count
CSECT_QPROC_XASL_CACHELatch for XASL cache (mht: memory hash table)
CSECT_QPROC_LIST_CACHELatch for query result(list file) cache (mht)
CSECT_BOOT_SR_DBPARMLatch for accessing System Database parameters. Used during vol creation
CSECT_DISK_REFRESH_GOODVOLLatch for refreshing good volume cache
CSECT_CNV_FMT_LEXERLatch for value/string format translation lexer
CSECT_HEAP_CHNGUESSLatch for schema change
CSECT_SPAGE_SAVESPACELatch for slotted page saving space
CSECT_TRAN_TABLELatch for transaction table
CSECT_LOG_FLUSHfor 2 flushing (by LFT, by normal thread)
CSECT_HA_SERVER_STATELatch for HA server mode change

The critical section with the following data structures and operations has been implemented.

typedef struct css_critical_section
  const char *name;
  MUTEX_T lock;                           /* read/write monitor lock */
  int rwlock;                             /* >0 = # readers, <0 = writer, 0 = none */
  unsigned int waiting_writers;           /* # of waiting writers */
  COND_T readers_ok;                      /* start waiting readers */
  THREAD_ENTRY *waiting_writers_queue;    /* queue of waiting writers */
  THREAD_ENTRY *waiting_promoters_queue;  /* queue of waiting promoters */
  THREAD_T owner;                         /* CS owner writer */
  int tran_index;                         /* transaction id acquiring CS */
  unsigned int total_enter;
  unsigned int total_nwaits;              /* total # of waiters */
  struct timeval max_wait;
  struct timeval total_wait;
int csect_initialize (void)
Initializes all the critical section lock structures. Initializes a mutex with the condition variable.
Called when server starts.
int csect_finalize (void)
Frees all the critical section lock structures. mutex and condition variable are destroyed.
int csect_enter (THREAD_ENTRY * thread_p, int cs_index, int wait_secs)
Locks out other threads from concurrent execution through a critical section of a code.
cs_index (in): the identifier of the section to lock.
wait_secs (in): timeout in seconds.
If the thread is already an owner of the resource then it could reenter this section as a writer. rwlock needs to be decremented.
Otherwise, if wait_secs = INF_WAIT, the thread will wait until others send a signal to wake it up.
If wait_secs = NOT_WAIT, TIMEOUT error is returned immediately without waiting.
If wait_secs > 0, the thread will wait until the time is out.
Related functions:
Int csect_enter_critical_section (THREAD_ENTRY * thread_p, CSS_CRITICAL_SECTION * cs_ptr, int wait_secs);
Int csect_enter_critical_section_as_reader (THREAD_ENTRY * thread_p, CSS_CRITICAL_SECTION * cs_ptr, int wait_secs);
Note: writer’s priority is higher than reader’s.
int csect_exit (int cs_index)
Unlocks the critical section, which may restart another thread that is suspended and is waiting for the critical section.
cs_index: identifier of the section to unlock
Wake up one of the following groups by priority: promoter, writer, readers.
int csect_demote (THREAD_ENTRY * thread_p, int cs_index, int wait_secs);
Acquires a read lock when it has a write lock. If the thread is not an owner, it acts like a normal reader request.
int csect_promote (THREAD_ENTRY * thread_p, int cs_index, int wait_secs);
Acquires a write lock when it has a read lock. If thread is not an owner, then it waits as a writer.
comments powered by Disqus
Page info
viewed 6688 times
translations en
posted 6 years ago by
updated 6 years ago by
View revisions
Share this article