8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-27 17:23:03 +01:00
firebird-mirror/src/jrd/thd.h

258 lines
6.7 KiB
C
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD access method
* MODULE: thd.h
* DESCRIPTION: Thread support definitions
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
2002-10-29 03:45:09 +01:00
*
* 2002.10.28 Sean Leyne - Completed removal of obsolete "DGUX" port
*
2002-10-30 07:40:58 +01:00
* 2002.10.29 Sean Leyne - Removed obsolete "Netware" port
*
2001-05-23 15:26:42 +02:00
*/
/*
2004-05-24 19:31:47 +02:00
$Id: thd.h,v 1.29 2004-05-24 17:28:33 brodsom Exp $
2001-05-23 15:26:42 +02:00
*/
#ifndef JRD_THD_H
#define JRD_THD_H
2001-05-23 15:26:42 +02:00
#ifdef SOLARIS
#ifdef SOLARIS_MT
#include <thread.h>
#define THD_MUTEX_STRUCT mutex_t
#define THD_COND_STRUCT cond_t
#define THD_RWLOCK_STRUCT rwlock_t
#endif
#endif
2001-05-23 15:26:42 +02:00
#ifdef VMS
//
//#define POSIX_THREADS
//
2001-05-23 15:26:42 +02:00
#include "../jrd/isc.h"
#define THD_MUTEX_STRUCT MTX_T
#endif
#ifdef WIN_NT
#define THD_MUTEX_STRUCT struct IB_RTL_CRITICAL_SECTION
/* The following code fragment has been extracted from <winnt.h>.
Microsoft being what it is, one is forced to include just about the
entire world even if you want only one little declaration. Since
including the whole world tends to break things (Microsoft also
doesn't believe in benign naming conversions) we must copy code. */
2004-05-09 07:48:33 +02:00
struct IB_RTL_CRITICAL_SECTION
2001-05-23 15:26:42 +02:00
{
void* DebugInfo;
ULONG LockCount;
ULONG RecursionCount;
void* OwningThread;
void* LockSemaphore;
ULONG Reserved;
};
#endif
#ifdef USE_POSIX_THREADS
2001-05-23 15:26:42 +02:00
#include <pthread.h>
#define THD_MUTEX_STRUCT pthread_mutex_t
#define THD_COND_STRUCT pthread_cond_t
#ifndef PTHREAD_PROCESS_SHARED
#define PTHREAD_PROCESS_SHARED
2001-05-23 15:26:42 +02:00
#endif
#ifndef PTHREAD_CREATE_DETACHED
#define PTHREAD_CREATE_DETACHED
2001-05-23 15:26:42 +02:00
#endif
#ifdef HAVE_PTHREAD_KEYCREATE
#define pthread_key_create pthread_keycreate
#endif
2001-05-23 15:26:42 +02:00
#endif
#ifndef THD_MUTEX_STRUCT
#define THD_MUTEX_STRUCT SCHAR
#endif
#ifndef THD_COND_STRUCT
#define THD_COND_STRUCT SCHAR
#endif
/* Thread priorities (may be ignored) */
2004-05-03 23:43:56 +02:00
const int THREAD_high = 1;
const int THREAD_medium_high = 2;
const int THREAD_medium = 3;
const int THREAD_medium_low = 4;
const int THREAD_low = 5;
const int THREAD_critical = 6;
2001-05-23 15:26:42 +02:00
/* Thread option flags */
2004-05-03 23:43:56 +02:00
const int THREAD_ast = 1; /* Thread can/should run at ast level */
const int THREAD_blast = 2; /* Blow away thread during exit handler */
const int THREAD_wait = 4; /* Somebody will wait for thread exit */
2001-05-23 15:26:42 +02:00
/* Thread quanta */
2004-05-03 23:43:56 +02:00
const int QUANTUM = 100; /* Default quantum */
const int SWEEP_QUANTUM = 10; /* Make sweeps less disruptive */
2001-05-23 15:26:42 +02:00
/* Thread specific data */
2004-05-24 19:31:47 +02:00
struct thdd {
2001-05-23 15:26:42 +02:00
void *thdd_prior_context;
ULONG thdd_type; /* what kind of structure this is */
2004-05-24 19:31:47 +02:00
};
typedef thdd *THDD;
2001-05-23 15:26:42 +02:00
/* Thread structure types */
2004-05-03 23:43:56 +02:00
const USHORT THDD_TYPE_TGBL = 1; /* used by backup/restore */
const USHORT THDD_TYPE_TSQL = 2; /* used by DSQL */
const USHORT THDD_TYPE_TDBB = 3; /* used in engine */
const USHORT THDD_TYPE_TRDB = 4; /* used in remote interface */
const USHORT THDD_TYPE_TDBA = 5; /* used in DBA utility */
const USHORT THDD_TYPE_TIDB = 6; /* used by interprocess server */
const USHORT THDD_TYPE_TALICE = 7; /* used by gfix */
const USHORT THDD_TYPE_TSEC = 8; /* used by gsec */
2001-05-23 15:26:42 +02:00
/* General purpose in use object structure */
2004-05-24 19:31:47 +02:00
struct iuo {
2001-05-23 15:26:42 +02:00
struct iuo *iuo_next;
void *iuo_object[10];
USHORT iuo_in_use_count;
2004-05-24 19:31:47 +02:00
};
typedef iuo *IUO;
2001-05-23 15:26:42 +02:00
/* Mutex structure */
2004-05-24 19:31:47 +02:00
struct mutx_t {
2001-05-23 15:26:42 +02:00
THD_MUTEX_STRUCT mutx_mutex;
2004-05-24 19:31:47 +02:00
};
typedef mutx_t MUTX_T;
typedef mutx_t* MUTX;
2001-05-23 15:26:42 +02:00
/* Recursive mutex structure */
2004-05-24 19:31:47 +02:00
struct rec_mutx_t {
2001-05-23 15:26:42 +02:00
MUTX_T rec_mutx_mtx[1];
2004-04-20 07:57:31 +02:00
FB_THREAD_ID rec_mutx_id;
2001-05-23 15:26:42 +02:00
SLONG rec_mutx_count;
2004-05-24 19:31:47 +02:00
};
typedef rec_mutx_t REC_MUTX_T;
typedef rec_mutx_t *REC_MUTX;
2001-05-23 15:26:42 +02:00
/* Combined mutex and condition variable structure */
2002-09-25 08:22:43 +02:00
#ifndef SOLARIS
2004-05-24 19:31:47 +02:00
struct cond_t {
2001-05-23 15:26:42 +02:00
THD_MUTEX_STRUCT cond_mutex;
THD_COND_STRUCT cond_cond;
2004-05-24 19:31:47 +02:00
};
typedef cond_t COND_T;
typedef cond_t *COND;
2001-05-23 15:26:42 +02:00
2002-09-25 08:22:43 +02:00
#endif
2001-05-23 15:26:42 +02:00
/* Read/write lock structure */
2004-05-24 19:31:47 +02:00
struct wlck_t {
2001-05-23 15:26:42 +02:00
#ifdef THD_RWLOCK_STRUCT
THD_RWLOCK_STRUCT wlck_wlock;
#else
COND_T wlck_cond;
int wlck_count;
int wlck_waiters;
#endif
2004-05-24 19:31:47 +02:00
};
typedef wlck_t WLCK_T;
typedef wlck_t *WLCK;
2001-05-23 15:26:42 +02:00
2004-05-03 23:43:56 +02:00
const int WLCK_read = 1;
const int WLCK_write = 2;
2001-05-23 15:26:42 +02:00
/* Threading allocation size */
#define THREAD_STRUCT_SIZE(type,n) (n * sizeof (type) + ALIGNMENT)
#define THREAD_STRUCT_ALIGN(blk) FB_ALIGN((U_IPTR) blk, ALIGNMENT)
#ifdef V4_THREADING
#define V4_INIT THD_init()
#define V4_GLOBAL_MUTEX_LOCK THD_mutex_lock_global()
#define V4_GLOBAL_MUTEX_UNLOCK THD_mutex_unlock_global()
#define V4_MUTEX_INIT(mutx) THD_mutex_init (mutx)
#define V4_MUTEX_LOCK(mutx) THD_mutex_lock (mutx)
#define V4_MUTEX_UNLOCK(mutx) THD_mutex_unlock (mutx)
#define V4_MUTEX_DESTROY(mutx) THD_mutex_destroy (mutx)
#define V4_RW_LOCK_INIT_N(wlck,n) THD_wlck_init_n (wlck, n)
#define V4_RW_LOCK_INIT(wlck) THD_wlck_init (wlck)
#define V4_RW_LOCK_LOCK(wlck,type) THD_wlck_lock (wlck, type)
#define V4_RW_LOCK_UNLOCK(wlck) THD_wlck_unlock (wlck)
#define V4_RW_LOCK_DESTROY(wlck) THD_wlck_destroy (wlck)
#define V4_RW_LOCK_DESTROY_N(wlck,n) THD_wlck_destroy_n (wlck, n)
// BRS. 03/23/2003
// Those empty defines was substituted with #ifdef V4_THREADING
//#else
//#define V4_INIT
//#define V4_GLOBAL_MUTEX_LOCK
//#define V4_GLOBAL_MUTEX_UNLOCK
//#define V4_MUTEX_INIT(mutx)
//#define V4_MUTEX_LOCK(mutx)
//#define V4_MUTEX_UNLOCK(mutx)
//#define V4_MUTEX_DESTROY(mutx)
//#define V4_RW_LOCK_INIT_N(wlck,n)
//#define V4_RW_LOCK_INIT(wlck)
//#define V4_RW_LOCK_LOCK(wlck,type)
//#define V4_RW_LOCK_UNLOCK(wlck)
//#define V4_RW_LOCK_DESTROY_N(wlck,n)
//#define V4_RW_LOCK_DESTROY(wlck)
2001-05-23 15:26:42 +02:00
#endif
#ifdef ANY_THREADING
#define THD_INIT THD_init()
#define THD_GLOBAL_MUTEX_LOCK THD_mutex_lock_global()
#define THD_GLOBAL_MUTEX_UNLOCK THD_mutex_unlock_global()
#define THD_MUTEX_INIT_N(mutx,n) THD_mutex_init_n (mutx, n)
#define THD_MUTEX_DESTROY_N(mutx,n) THD_mutex_destroy_n (mutx, n)
#define THD_MUTEX_INIT(mutx) THD_mutex_init (mutx)
#define THD_MUTEX_LOCK(mutx) THD_mutex_lock (mutx)
#define THD_MUTEX_UNLOCK(mutx) THD_mutex_unlock (mutx)
#define THD_MUTEX_DESTROY(mutx) THD_mutex_destroy (mutx)
#else
#define THD_INIT
#define THD_GLOBAL_MUTEX_LOCK
#define THD_GLOBAL_MUTEX_UNLOCK
#define THD_MUTEX_INIT_N(mutx,n)
#define THD_MUTEX_DESTROY_N(mutx,n)
#define THD_MUTEX_INIT(mutx)
#define THD_MUTEX_LOCK(mutx)
#define THD_MUTEX_UNLOCK(mutx)
#define THD_MUTEX_DESTROY(mutx)
#endif
#endif /* JRD_THD_H */