File: pthread_handler.h

package info (click to toggle)
gensio 2.8.6-1~bpo12%2B2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 8,536 kB
  • sloc: ansic: 89,872; python: 5,085; sh: 4,929; cpp: 3,543; makefile: 1,468
file content (46 lines) | stat: -rw-r--r-- 1,563 bytes parent folder | download | duplicates (2)
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
/*
 *  gensio - A library for abstracting stream I/O
 *  Copyright (C) 2020  Corey Minyard <minyard@acm.org>
 *
 *  SPDX-License-Identifier: LGPL-2.1-only
 */

/*
 * This allows a lot of pthread calls to be dummied out if pthreads is
 * disabled.
 */
#ifdef _WIN32
#include <windows.h>
#define lock_type SRWLOCK
#define LOCK_INIT(l) InitializeSRWLock(l)
#define LOCK_DESTROY(l) do {} while(0)
#define LOCK(l) AcquireSRWLockExclusive(l)
#define UNLOCK(l) ReleaseSRWLockExclusive(l)
#define LOCK_INITIALIZER SRWLOCK_INIT
#define lock_thread_type DWORD
#define LOCK_GET_THREAD_ID GetCurrentThreadId()
#define LOCK_THREAD_ID_EQUAL(a,b) ((a) == (b))
#elif defined(USE_PTHREADS)
#include <pthread.h>
#include <assert.h>
#define lock_type pthread_mutex_t
#define LOCK_INIT(l) assert(pthread_mutex_init(l, NULL) == 0)
#define LOCK_DESTROY(l) assert(pthread_mutex_destroy(l)== 0)
#define LOCK(l) assert(pthread_mutex_lock(l) == 0)
#define UNLOCK(l) assert(pthread_mutex_unlock(l) == 0)
#define LOCK_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define lock_thread_type pthread_t
#define LOCK_GET_THREAD_ID pthread_self()
#define LOCK_THREAD_ID_EQUAL(a,b) pthread_equal(a,b)
#else
#include <assert.h>
#define lock_type int
#define LOCK_INIT(l) do { *l = 0; } while(0)
#define LOCK_DESTROY(l) do { assert(*l == 0); } while(0)
#define LOCK(l) do { assert(*l == 0); *l = 1; } while(0)
#define UNLOCK(l) do { assert(*l == 1); *l = 0; } while(0)
#define LOCK_INITIALIZER 0
#define lock_thread_type int
#define LOCK_GET_THREAD_ID 0
#define LOCK_THREAD_ID_EQUAL(a,b) ((a) == (b))
#endif