os0thread.h 4.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/******************************************************
The interface to the operating system
process and thread control primitives

(c) 1995 Innobase Oy

Created 9/8/1995 Heikki Tuuri
*******************************************************/

#ifndef os0thread_h
#define os0thread_h

#include "univ.i"

15 16 17 18
/* Maximum number of threads which can be created in the program;
this is also the size of the wait slot array for MySQL threads which
can wait inside InnoDB */
#define	OS_THREAD_MAX_N		10000
19 20 21 22 23 24 25 26 27 28 29 30

/* Possible fixed priorities for threads */
#define OS_THREAD_PRIORITY_NONE		100
#define OS_THREAD_PRIORITY_BACKGROUND	1
#define OS_THREAD_PRIORITY_NORMAL	2
#define OS_THREAD_PRIORITY_ABOVE_NORMAL	3

#ifdef __WIN__
typedef void*			os_thread_t;
#else
typedef pthread_t               os_thread_t;
#endif
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
31 32

#define os_thread_id_t          os_thread_t
33

34 35 36
/* Define a function pointer type to use in a typecast */
typedef void* (*os_posix_f_t) (void*);

heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
37 38 39 40 41 42 43 44 45 46 47 48
/*******************************************************************
Compares two threads or thread ids for equality */

ibool
os_thread_eq(
/*=========*/
				/* out: TRUE if equal */
	os_thread_t	a,	/* in: OS thread or thread id */
	os_thread_t	b);	/* in: OS thread or thread id */
/********************************************************************
Converts an OS thread or thread id to a ulint. It is NOT guaranteed that
the ulint is unique for the thread though! */
49

heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
50 51 52 53 54
ulint
os_thread_pf(
/*=========*/
				/* out: unsigned long int */
	os_thread_t	a);	/* in: thread or thread id */
55 56 57 58 59 60 61 62 63
/********************************************************************
Creates a new thread of execution. The execution starts from
the function given. The start function takes a void* parameter
and returns a ulint. */

os_thread_t
os_thread_create(
/*=============*/
						/* out: handle to the thread */
64 65 66
#ifndef __WIN__
		 os_posix_f_t            start_f,
#else
67 68
	ulint (*start_f)(void*),		/* in: pointer to function
						from which to start */
69
#endif
70 71 72
	void*			arg,		/* in: argument to start
						function */
	os_thread_id_t*		thread_id);	/* out: id of created
73 74 75
						thread; currently this is
						identical to the handle to
						the thread */
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
/*********************************************************************
A thread calling this function ends its execution. */

void
os_thread_exit(
/*===========*/
	ulint	code);	/* in: exit code */
/*********************************************************************
Returns the thread identifier of current thread. */

os_thread_id_t
os_thread_get_curr_id(void);
/*========================*/
/*********************************************************************
Returns handle to the current thread. */

os_thread_t
os_thread_get_curr(void);
/*====================*/
/*********************************************************************
Waits for a thread to terminate. */

void
os_thread_wait(
/*===========*/
	os_thread_t	thread);	/* in: thread to wait */
/*********************************************************************
Advises the os to give up remainder of the thread's time slice. */

void
os_thread_yield(void);
/*=================*/
/*********************************************************************
The thread sleeps at least the time given in microseconds. */

void
os_thread_sleep(
/*============*/
	ulint	tm);	/* in: time in microseconds */
/**********************************************************************
Gets a thread priority. */

ulint
os_thread_get_priority(
/*===================*/
				/* out: priority */
	os_thread_t	handle);/* in: OS handle to the thread */
/**********************************************************************
Sets a thread priority. */

void
os_thread_set_priority(
/*===================*/
	os_thread_t	handle,	/* in: OS handle to the thread */
	ulint		pri);	/* in: priority: one of OS_PRIORITY_... */
/**********************************************************************
Gets the last operating system error code for the calling thread. */

ulint
os_thread_get_last_error(void);
/*==========================*/


#ifndef UNIV_NONINL
#include "os0thread.ic"
#endif

#endif