Open Broadcaster Software
Free, open source software for live streaming and recording
threading.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 Hugh Bailey <obs.jim@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #pragma once
18 
19 /*
20  * Allows posix thread usage on windows as well as other operating systems.
21  * Use this header if you want to make your code more platform independent.
22  *
23  * Also provides a custom platform-independent "event" handler via
24  * pthread conditional waits.
25  */
26 
27 #include "c99defs.h"
28 
29 #ifdef _MSC_VER
30 #include "../../deps/w32-pthreads/pthread.h"
31 #else
32 #include <errno.h>
33 #include <pthread.h>
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _WIN32
41 #include "threading-windows.h"
42 #else
43 #include "threading-posix.h"
44 #endif
45 
46 /* this may seem strange, but you can't use it unless it's an initializer */
47 static inline void pthread_mutex_init_value(pthread_mutex_t *mutex)
48 {
49  pthread_mutex_t init_val = PTHREAD_MUTEX_INITIALIZER;
50  if (!mutex)
51  return;
52 
53  *mutex = init_val;
54 }
55 
59 };
60 
61 struct os_event_data;
62 struct os_sem_data;
63 typedef struct os_event_data os_event_t;
64 typedef struct os_sem_data os_sem_t;
65 
66 EXPORT int os_event_init(os_event_t **event, enum os_event_type type);
68 EXPORT int os_event_wait(os_event_t *event);
69 EXPORT int os_event_timedwait(os_event_t *event, unsigned long milliseconds);
70 EXPORT int os_event_try(os_event_t *event);
72 EXPORT void os_event_reset(os_event_t *event);
73 
74 EXPORT int os_sem_init(os_sem_t **sem, int value);
75 EXPORT void os_sem_destroy(os_sem_t *sem);
76 EXPORT int os_sem_post(os_sem_t *sem);
77 EXPORT int os_sem_wait(os_sem_t *sem);
78 
79 EXPORT void os_set_thread_name(const char *name);
80 
81 #ifdef _MSC_VER
82 #define THREAD_LOCAL __declspec(thread)
83 #else
84 #define THREAD_LOCAL __thread
85 #endif
86 
87 
88 #ifdef __cplusplus
89 }
90 #endif
EXPORT int os_event_init(os_event_t **event, enum os_event_type type)
EXPORT int os_sem_post(os_sem_t *sem)
Definition: threading.h:58
EXPORT void os_set_thread_name(const char *name)
EXPORT void os_sem_destroy(os_sem_t *sem)
os_event_type
Definition: threading.h:56
EXPORT int os_event_wait(os_event_t *event)
EXPORT int os_sem_wait(os_sem_t *sem)
#define EXPORT
Definition: c99defs.h:49
EXPORT int os_event_timedwait(os_event_t *event, unsigned long milliseconds)
EXPORT int os_sem_init(os_sem_t **sem, int value)
Definition: threading.h:57
struct os_sem_data os_sem_t
Definition: threading.h:64
EXPORT int os_event_signal(os_event_t *event)
EXPORT int os_event_try(os_event_t *event)
EXPORT void os_event_reset(os_event_t *event)
EXPORT void os_event_destroy(os_event_t *event)
struct os_event_data os_event_t
Definition: threading.h:63