/usr/include/d/gtkd-3/glib/Thread.d is in libgtkd-3-dev 3.7.5-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | /*
* This file is part of gtkD.
*
* gtkD is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version, with
* some exceptions, please read the COPYING file.
*
* gtkD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with gtkD; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*/
// generated automatically - do not change
// find conversion definition on APILookup.txt
// implement new conversion functionalities on the wrap.utils pakage
module glib.Thread;
private import glib.ConstructionException;
private import glib.ErrorG;
private import glib.GException;
private import glib.Str;
private import glib.c.functions;
public import glib.c.types;
public import gtkc.glibtypes;
private import gtkd.Loader;
/**
* The #GThread struct represents a running thread. This struct
* is returned by g_thread_new() or g_thread_try_new(). You can
* obtain the #GThread struct representing the current thread by
* calling g_thread_self().
*
* GThread is refcounted, see g_thread_ref() and g_thread_unref().
* The thread represented by it holds a reference while it is running,
* and g_thread_join() consumes the reference that it is given, so
* it is normally not necessary to manage GThread references
* explicitly.
*
* The structure is opaque -- none of its fields may be directly
* accessed.
*/
public class Thread
{
/** the main Gtk struct */
protected GThread* gThread;
protected bool ownedRef;
/** Get the main Gtk struct */
public GThread* getThreadStruct(bool transferOwnership = false)
{
if (transferOwnership)
ownedRef = false;
return gThread;
}
/** the main Gtk struct as a void* */
protected void* getStruct()
{
return cast(void*)gThread;
}
/**
* Sets our main struct and passes it to the parent class.
*/
public this (GThread* gThread, bool ownedRef = false)
{
this.gThread = gThread;
this.ownedRef = ownedRef;
}
~this ()
{
if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
g_thread_unref(gThread);
}
/**
* This function is the same as g_thread_new() except that
* it allows for the possibility of failure.
*
* If a thread can not be created (due to resource limits),
* @error is set and %NULL is returned.
*
* Params:
* name = an (optional) name for the new thread
* func = a function to execute in the new thread
* data = an argument to supply to the new thread
*
* Returns: the new #GThread, or %NULL if an error occurred
*
* Since: 2.32
*
* Throws: GException on failure.
* Throws: ConstructionException GTK+ fails to create the object.
*/
public this(string name, GThreadFunc func, void* data)
{
GError* err = null;
auto p = g_thread_try_new(Str.toStringz(name), func, data, &err);
if (err !is null)
{
throw new GException( new ErrorG(err) );
}
if(p is null)
{
throw new ConstructionException("null returned by try_new");
}
this(cast(GThread*) p);
}
/**
* Waits until @thread finishes, i.e. the function @func, as
* given to g_thread_new(), returns or g_thread_exit() is called.
* If @thread has already terminated, then g_thread_join()
* returns immediately.
*
* Any thread can wait for any other thread by calling g_thread_join(),
* not just its 'creator'. Calling g_thread_join() from multiple threads
* for the same @thread leads to undefined behaviour.
*
* The value returned by @func or given to g_thread_exit() is
* returned by this function.
*
* g_thread_join() consumes the reference to the passed-in @thread.
* This will usually cause the #GThread struct and associated resources
* to be freed. Use g_thread_ref() to obtain an extra reference if you
* want to keep the GThread alive beyond the g_thread_join() call.
*
* Returns: the return value of the thread
*/
public void* join()
{
return g_thread_join(gThread);
}
/**
* Increase the reference count on @thread.
*
* Returns: a new reference to @thread
*
* Since: 2.32
*/
public Thread doref()
{
auto p = g_thread_ref(gThread);
if(p is null)
{
return null;
}
return new Thread(cast(GThread*) p, true);
}
/**
* Decrease the reference count on @thread, possibly freeing all
* resources associated with it.
*
* Note that each thread holds a reference to its #GThread while
* it is running, so it is safe to drop your own reference to it
* if you don't need it anymore.
*
* Since: 2.32
*/
public void unref()
{
g_thread_unref(gThread);
}
/** */
public static GQuark errorQuark()
{
return g_thread_error_quark();
}
/**
* Terminates the current thread.
*
* If another thread is waiting for us using g_thread_join() then the
* waiting thread will be woken up and get @retval as the return value
* of g_thread_join().
*
* Calling g_thread_exit() with a parameter @retval is equivalent to
* returning @retval from the function @func, as given to g_thread_new().
*
* You must only call g_thread_exit() from a thread that you created
* yourself with g_thread_new() or related APIs. You must not call
* this function from a thread created with another threading library
* or or from within a #GThreadPool.
*
* Params:
* retval = the return value of this thread
*/
public static void exit(void* retval)
{
g_thread_exit(retval);
}
/**
* This function returns the #GThread corresponding to the
* current thread. Note that this function does not increase
* the reference count of the returned struct.
*
* This function will return a #GThread even for threads that
* were not created by GLib (i.e. those created by other threading
* APIs). This may be useful for thread identification purposes
* (i.e. comparisons) but you must not use GLib functions (such
* as g_thread_join()) on these threads.
*
* Returns: the #GThread representing the current thread
*/
public static Thread self()
{
auto p = g_thread_self();
if(p is null)
{
return null;
}
return new Thread(cast(GThread*) p, true);
}
/**
* Causes the calling thread to voluntarily relinquish the CPU, so
* that other threads can run.
*
* This function is often used as a method to make busy wait less evil.
*/
public static void yield()
{
g_thread_yield();
}
/**
* Sets the indicated @lock_bit in @address. If the bit is already
* set, this call will block until g_bit_unlock() unsets the
* corresponding bit.
*
* Attempting to lock on two different bits within the same integer is
* not supported and will very probably cause deadlocks.
*
* The value of the bit that is set is (1u << @bit). If @bit is not
* between 0 and 31 then the result is undefined.
*
* This function accesses @address atomically. All other accesses to
* @address must be atomic in order for this function to work
* reliably.
*
* Params:
* address = a pointer to an integer
* lockBit = a bit value between 0 and 31
*
* Since: 2.24
*/
public static void bitLock(int* address, int lockBit)
{
g_bit_lock(address, lockBit);
}
/**
* Sets the indicated @lock_bit in @address, returning %TRUE if
* successful. If the bit is already set, returns %FALSE immediately.
*
* Attempting to lock on two different bits within the same integer is
* not supported.
*
* The value of the bit that is set is (1u << @bit). If @bit is not
* between 0 and 31 then the result is undefined.
*
* This function accesses @address atomically. All other accesses to
* @address must be atomic in order for this function to work
* reliably.
*
* Params:
* address = a pointer to an integer
* lockBit = a bit value between 0 and 31
*
* Returns: %TRUE if the lock was acquired
*
* Since: 2.24
*/
public static bool bitTrylock(int* address, int lockBit)
{
return g_bit_trylock(address, lockBit) != 0;
}
/**
* Clears the indicated @lock_bit in @address. If another thread is
* currently blocked in g_bit_lock() on this same bit then it will be
* woken up.
*
* This function accesses @address atomically. All other accesses to
* @address must be atomic in order for this function to work
* reliably.
*
* Params:
* address = a pointer to an integer
* lockBit = a bit value between 0 and 31
*
* Since: 2.24
*/
public static void bitUnlock(int* address, int lockBit)
{
g_bit_unlock(address, lockBit);
}
/**
* Determine the approximate number of threads that the system will
* schedule simultaneously for this process. This is intended to be
* used as a parameter to g_thread_pool_new() for CPU bound tasks and
* similar cases.
*
* Returns: Number of schedulable threads, always greater than 0
*
* Since: 2.36
*/
public static uint getNumProcessors()
{
return g_get_num_processors();
}
/**
* This is equivalent to g_bit_lock, but working on pointers (or other
* pointer-sized values).
*
* For portability reasons, you may only lock on the bottom 32 bits of
* the pointer.
*
* Params:
* address = a pointer to a #gpointer-sized value
* lockBit = a bit value between 0 and 31
*
* Since: 2.30
*/
public static void pointerBitLock(void* address, int lockBit)
{
g_pointer_bit_lock(address, lockBit);
}
/**
* This is equivalent to g_bit_trylock, but working on pointers (or
* other pointer-sized values).
*
* For portability reasons, you may only lock on the bottom 32 bits of
* the pointer.
*
* Params:
* address = a pointer to a #gpointer-sized value
* lockBit = a bit value between 0 and 31
*
* Returns: %TRUE if the lock was acquired
*
* Since: 2.30
*/
public static bool pointerBitTrylock(void* address, int lockBit)
{
return g_pointer_bit_trylock(address, lockBit) != 0;
}
/**
* This is equivalent to g_bit_unlock, but working on pointers (or other
* pointer-sized values).
*
* For portability reasons, you may only lock on the bottom 32 bits of
* the pointer.
*
* Params:
* address = a pointer to a #gpointer-sized value
* lockBit = a bit value between 0 and 31
*
* Since: 2.30
*/
public static void pointerBitUnlock(void* address, int lockBit)
{
g_pointer_bit_unlock(address, lockBit);
}
}
|