update dev300-m58
[ooovba.git] / sal / inc / osl / thread.h
blob17aa8eb352778910ceb55f18712b27da431d5d36
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: thread.h,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _OSL_THREAD_H_
32 #define _OSL_THREAD_H_
34 #include <osl/time.h>
36 #ifndef _RTL_TEXTENC_H_
37 # include <rtl/textenc.h>
38 #endif
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 /**
45 Opaque data type for threads. As with all other osl-handles
46 you can initialize and/or test it to/for 0.
48 typedef void* oslThread;
50 /** the function-ptr. representing the threads worker-function.
52 typedef void (SAL_CALL *oslWorkerFunction)(void*);
54 /** levels of thread-priority
55 Note that oslThreadPriorityUnknown might be returned
56 by getPriorityOfThread() (e.g. when it is terminated),
57 but mustn't be used with setPriority()!
59 typedef enum
61 osl_Thread_PriorityHighest,
62 osl_Thread_PriorityAboveNormal,
63 osl_Thread_PriorityNormal,
64 osl_Thread_PriorityBelowNormal,
65 osl_Thread_PriorityLowest,
66 osl_Thread_PriorityUnknown, /* don't use to set */
67 osl_Thread_Priority_FORCE_EQUAL_SIZE = SAL_MAX_ENUM
68 } oslThreadPriority;
71 typedef sal_uInt32 oslThreadIdentifier;
73 typedef sal_uInt32 oslThreadKey;
75 /** Create the thread, using the function-ptr pWorker as
76 its main (worker) function. This functions receives in
77 its void* parameter the value supplied by pThreadData.
78 Once the OS-structures are initialized,the thread starts
79 running.
80 @return 0 if creation failed, otherwise a handle to the thread
82 oslThread SAL_CALL osl_createThread(oslWorkerFunction pWorker, void* pThreadData);
84 /** Create the thread, using the function-ptr pWorker as
85 its main (worker) function. This functions receives in
86 its void* parameter the value supplied by pThreadData.
87 The thread will be created, but it won't start running.
88 To wake-up the thread, use resume().
89 @return 0 if creation failed, otherwise a handle to the thread
91 oslThread SAL_CALL osl_createSuspendedThread(oslWorkerFunction pWorker, void* pThreadData);
93 /** Get the identifier for the specified thread or if parameter
94 Thread is NULL of the current active thread.
95 @return identifier of the thread
97 oslThreadIdentifier SAL_CALL osl_getThreadIdentifier(oslThread Thread);
99 /** Release the thread handle.
100 If Thread is NULL, the function won't do anything.
101 Note that we do not interfere with the actual running of
102 the thread, we just free up the memory needed by the handle.
104 void SAL_CALL osl_destroyThread(oslThread Thread);
106 /** Wake-up a thread that was suspended with suspend() or
107 createSuspended(). The oslThread must be valid!
109 void SAL_CALL osl_resumeThread(oslThread Thread);
111 /** Suspend the execution of the thread. If you want the thread
112 to continue, call resume(). The oslThread must be valid!
114 void SAL_CALL osl_suspendThread(oslThread Thread);
116 /** Changes the threads priority.
117 The oslThread must be valid!
119 void SAL_CALL osl_setThreadPriority(oslThread Thread, oslThreadPriority Priority);
121 /** Retrieves the threads priority.
122 Returns oslThreadPriorityUnknown for invalid Thread-argument or
123 terminated thread. (I.e.: The oslThread might be invalid.)
125 oslThreadPriority SAL_CALL osl_getThreadPriority(const oslThread Thread);
127 /** Returns True if the thread was created and has not terminated yet.
128 Note that according to this definition a "running" thread might be
129 suspended! Also returns False is Thread is NULL.
131 sal_Bool SAL_CALL osl_isThreadRunning(const oslThread Thread);
133 /** Blocks the calling thread until Thread has terminated.
134 Returns immediately if Thread is NULL.
136 void SAL_CALL osl_joinWithThread(oslThread Thread);
138 /** Blocks the calling thread at least for the given number
139 of time.
141 void SAL_CALL osl_waitThread(const TimeValue* pDelay);
143 /** The requested thread will get terminate the next time
144 scheduleThread() is called.
146 void SAL_CALL osl_terminateThread(oslThread Thread);
148 /** Offers the rest of the threads time-slice to the OS.
149 scheduleThread() should be called in the working loop
150 of the thread, so any other thread could also get the
151 processor. Returns False if the thread should terminate, so
152 the thread could free any allocated resources.
154 sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread);
156 /** Offers the rest of the threads time-slice to the OS.
157 Under POSIX you _need_ to yield(), otherwise, since the
158 threads are not preempted during execution, NO other thread
159 (even with higher priority) gets the processor. Control is
160 only given to another thread if the current thread blocks
161 or uses yield().
163 void SAL_CALL osl_yieldThread(void);
165 /* Callback when data stored in a thread key is no longer needed */
167 typedef void (SAL_CALL *oslThreadKeyCallbackFunction)(void *);
169 /** Create a key to an associated thread local storage pointer. */
170 oslThreadKey SAL_CALL osl_createThreadKey(oslThreadKeyCallbackFunction pCallback);
172 /** Destroy a key to an associated thread local storage pointer. */
173 void SAL_CALL osl_destroyThreadKey(oslThreadKey Key);
175 /** Get to key associated thread specific data. */
176 void* SAL_CALL osl_getThreadKeyData(oslThreadKey Key);
178 /** Set to key associated thread specific data. */
179 sal_Bool SAL_CALL osl_setThreadKeyData(oslThreadKey Key, void *pData);
181 /** Get the current thread local text encoding. */
182 rtl_TextEncoding SAL_CALL osl_getThreadTextEncoding(void);
184 /** Set the thread local text encoding.
185 @return the old text encoding.
187 rtl_TextEncoding SAL_CALL osl_setThreadTextEncoding(rtl_TextEncoding Encoding);
189 #ifdef __cplusplus
191 #endif
193 #endif /* _OSL_THREAD_H_ */