threading.h revision 63f12ff6ff6ac8de6bba5201b43fbb258ea54f7b
1/*
2* Tapetest
3* Copyright (c) International Business Machines Corp., 2001
4*
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19*
20*  Please send e-mail to yardleyb@us.ibm.com if you have
21*  questions or comments.
22*
23*  Project Website:  TBD
24*
25* $Id: threading.h,v 1.3 2003/09/17 17:15:28 robbiew Exp $
26* $Log: threading.h,v $
27* Revision 1.3  2003/09/17 17:15:28  robbiew
28* Update to 1.1.12
29*
30* Revision 1.5  2002/03/30 01:32:14  yardleyb
31* Major Changes:
32*
33* Added Dumping routines for
34* data miscompares,
35*
36* Updated performance output
37* based on command line.  Gave
38* one decimal in MB/s output.
39*
40* Rewrote -pL IO routine to show
41* correct stats.  Now show pass count
42* when using -C.
43*
44* Minor Changes:
45*
46* Code cleanup to remove the plethera
47* if #ifdef for windows/unix functional
48* differences.
49*
50* Revision 1.4  2002/02/28 04:25:45  yardleyb
51* reworked threading code
52* made locking code a macro.
53*
54* Revision 1.3  2002/02/19 02:46:37  yardleyb
55* Added changes to compile for AIX.
56* Update getvsiz so it returns a -1
57* if the ioctl fails and we handle
58* that fact correctly.  Added check
59* to force vsiz to always be greater
60* then stop_lba.
61*
62* Revision 1.2  2002/02/04 20:35:38  yardleyb
63* Changed max. number of threads to 64k.
64* Check for max threads in parsing.
65* Fixed windows getopt to return correctly
66* when a bad option is given.
67* Update time output to be in the format:
68*   YEAR/MONTH/DAY-HOUR:MIN:SEC
69* instead of epoch time.
70*
71* Revision 1.1  2001/12/04 18:51:06  yardleyb
72* Checkin of new source files and removal
73* of outdated source
74*
75*/
76
77#ifndef THREADING_H
78#define THREADING_H 1
79
80#ifdef WINDOWS
81#include <windows.h>
82#else
83#include <pthread.h>
84#include <sys/types.h>
85#include <unistd.h>
86#endif
87
88#include "defs.h"
89#include "globals.h"
90#include "main.h"
91#include "threading.h"
92
93#define MAX_THREADS 65536		/* max number of threads, reader/writer, per test */
94
95#ifdef WINDOWS
96#define LOCK(Mutex) WaitForSingleObject((void *) Mutex, INFINITE)
97#define UNLOCK(Mutex) ReleaseMutex((void *) Mutex)
98#define TEXIT(errno) ExitThread(errno); return(errno)
99#else
100#define LOCK(Mutex) \
101		pthread_cleanup_push((void *) pthread_mutex_unlock, (void *) &Mutex); \
102		pthread_mutex_lock(&Mutex)
103#define UNLOCK(Mutex) \
104		pthread_mutex_unlock(&Mutex); \
105		pthread_cleanup_pop(0)
106#define TEXIT(errno) pthread_exit(&errno)
107#endif
108
109typedef struct thread_struct {
110#ifdef WINDOWS
111	HANDLE hThread;				/* handle to thread */
112#else
113	pthread_t hThread;			/* thread */
114	BOOL bCanBeJoined;
115#endif
116	struct thread_struct *next;	/* pointer to next thread */
117} thread_struct_t;
118
119void clean_up(void);
120void CreateChild(void *, child_args_t *);
121
122#endif /* THREADING_H */
123