cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

mutex.h
Go to the documentation of this file.
1 /*
2  Copyright 2020 Northern.tech AS
3 
4  This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the
8  Free Software Foundation; version 3.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 
19  To the extent this program is licensed as part of the Enterprise
20  versions of CFEngine, the applicable Commercial Open Source License
21  (COSL) may apply to this file if you as a licensee so wish it. See
22  included file COSL.txt.
23 */
24 
25 #ifndef CFENGINE_MUTEX_H
26 #define CFENGINE_MUTEX_H
27 
28 #include <platform.h>
29 
30 #define THREAD_BLOCK_INDEFINITELY -1
31 
32 #define ThreadLock(m) __ThreadLock(m, __func__, __FILE__, __LINE__)
33 #define ThreadUnlock(m) __ThreadUnlock(m, __func__, __FILE__, __LINE__)
34 #define ThreadWait(m, n, t) __ThreadWait(m, n, t, __func__, __FILE__, __LINE__)
35 
36 void __ThreadLock(pthread_mutex_t *mutex,
37  const char *funcname, const char *filename, int lineno);
38 void __ThreadUnlock(pthread_mutex_t *mutex,
39  const char *funcname, const char *filename, int lineno);
40 
41 /**
42  @brief Function to wait for `timeout` seconds or until signalled.
43  @note Can use THREAD_BLOCK_INDEFINITELY to block until a signal is received.
44  @param [in] cond Thread condition to wait for.
45  @param [in] mutex Mutex lock to acquire once condition is met.
46  @param [in] timeout Seconds to wait for, can be THREAD_BLOCK_INDEFINITELY
47  @return 0 on success, -1 if timed out, exits if locking fails
48  */
49 int __ThreadWait(pthread_cond_t *cond, pthread_mutex_t *mutex, int timeout,
50  const char *funcname, const char *filename, int lineno);
51 
52 #endif
void __ThreadUnlock(pthread_mutex_t *mutex, const char *funcname, const char *filename, int lineno)
Definition: mutex.c:51
void __ThreadLock(pthread_mutex_t *mutex, const char *funcname, const char *filename, int lineno)
Definition: mutex.c:31
int __ThreadWait(pthread_cond_t *cond, pthread_mutex_t *mutex, int timeout, const char *funcname, const char *filename, int lineno)
Function to wait for timeout seconds or until signalled.
Definition: mutex.c:70