5 * $TOG: Threads.hh /main/5 1997/09/03 17:27:34 mgreess $
7 * RESTRICTED CONFIDENTIAL INFORMATION:
9 * The information in this document is subject to special
10 * restrictions in a confidential disclosure agreement bertween
11 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
13 * Sun's specific written approval. This documment and all copies
14 * and derivative works thereof must be returned or destroyed at
17 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
26 #include <DtMail/DtLanguages.hh>
28 // This mutex must be used before calling any Dt* functions. They
29 // are extremely MT-UNSAFE and must be protected.
31 extern void * _DtMutex;
33 // This function will create an initialized mutex.
35 void * MutexInit(void);
36 void MutexDestroy(void * mutex);
38 // This class locks the specified mutex when constructed, and
39 // releases the lock on destruction. It is useful for mutexing
40 // a region of code automatically by including it in the scope
41 // of a set of braces.
43 class MutexLock : public DtCPlusPlusAllocator {
45 MutexLock(void * mutex);
49 void unlock_and_destroy(void);
55 // The SafeScalar class is designed to allow safe access to scalar values
56 // from within an MT app. It should only be used with the common 32 bit
59 class SafeScalarImpl : public DtCPlusPlusAllocator {
62 ~SafeScalarImpl(void);
64 long operator = (const long);
65 long operator += (const long);
66 long operator -= (const long);
67 long operator *= (const long);
68 long operator /= (const long);
70 int operator == (const long);
71 int operator <= (const long);
72 int operator < (const long);
73 int operator >= (const long);
74 int operator > (const long);
75 int operator != (const long);
84 template <class Scalar>
85 class SafeScalar : public DtCPlusPlusAllocator {
87 SafeScalar(void) : _scalar() { }
90 Scalar operator= (const Scalar val) { return((Scalar)(long)(_scalar = (long)val)); }
91 Scalar operator += (const Scalar val) { return((Scalar)(long)(_scalar += (long)val)); }
92 Scalar operator -= (const Scalar val) { return((Scalar)(long)(_scalar -= (long)val)); }
93 Scalar operator *= (const Scalar val) { return((Scalar)(long)(_scalar *= (long)val)); }
94 Scalar operator /= (const Scalar val) { return((Scalar)(long)(_scalar /= (long)val)); }
96 int operator == (const Scalar val) { return(_scalar == (long)val); }
97 int operator <= (const Scalar val) { return(_scalar <= (long)val); }
98 int operator < (const Scalar val) { return(_scalar < (long)val); }
99 int operator >= (const Scalar val) { return(_scalar >= (long)val); }
100 int operator > (const Scalar val) { return(_scalar > (long)val); }
101 int operator != (const Scalar val) { return(_scalar != (long)val); }
103 operator Scalar (void) { return((Scalar)(long)_scalar); }
106 SafeScalarImpl _scalar;
109 // The condition class is used to block an appliction until the
110 // condition has changed. This is typically used while creating or
111 // destroying a class.
113 class Condition : public DtCPlusPlusAllocator {
123 int operator += (int);
130 void waitFalse(void);
132 void waitGT(int); // wait >
133 void waitLT(int); // wait <
134 void waitProcStatus(void);
135 #endif /* DEAD_WOOD */
143 typedef unsigned int Thread;
145 typedef void * (*ThreadEntryPoint)(void *);
147 Thread ThreadCreate(ThreadEntryPoint, void * client_data);
148 Thread ThreadSelf(void);
149 void ThreadPrio(Thread, const int prio);
150 void ThreadKill(Thread, const int signal);
151 void ThreadExit(const int status);
152 void ThreadJoin(Thread);
153 time_t ThreadSleep(time_t seconds);