Statistics
| Branch: | Revision:

ddr4s / fw / wiringPi / wiringPi / piThread.c @ 32:cadb9025f1e0

History | View | Annotate | Download (1.76 KB)

1
/*
2
 * piThread.c:
3
 *        Provide a simplified interface to pthreads
4
 *
5
 *        Copyright (c) 2012 Gordon Henderson
6
 ***********************************************************************
7
 * This file is part of wiringPi:
8
 *        https://projects.drogon.net/raspberry-pi/wiringpi/
9
 *
10
 *    wiringPi is free software: you can redistribute it and/or modify
11
 *    it under the terms of the GNU Lesser General Public License as
12
 *    published by the Free Software Foundation, either version 3 of the
13
 *    License, or (at your option) any later version.
14
 *
15
 *    wiringPi is distributed in the hope that it will be useful,
16
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *    GNU Lesser General Public License for more details.
19
 *
20
 *    You should have received a copy of the GNU Lesser General Public
21
 *    License along with wiringPi.
22
 *    If not, see <http://www.gnu.org/licenses/>.
23
 ***********************************************************************
24
 */
25

    
26
#include <pthread.h>
27
#include "wiringPi.h"
28

    
29
static pthread_mutex_t piMutexes [4] ;
30

    
31

    
32

    
33
/*
34
 * piThreadCreate:
35
 *        Create and start a thread
36
 *********************************************************************************
37
 */
38

    
39
int piThreadCreate (void *(*fn)(void *))
40
{
41
  pthread_t myThread ;
42

    
43
  return pthread_create (&myThread, NULL, fn, NULL) ;
44
}
45

    
46
/*
47
 * piLock: piUnlock:
48
 *        Activate/Deactivate a mutex.
49
 *        We're keeping things simple here and only tracking 4 mutexes which
50
 *        is more than enough for out entry-level pthread programming
51
 *********************************************************************************
52
 */
53

    
54
void piLock (int key)
55
{
56
  pthread_mutex_lock (&piMutexes [key]) ;
57
}
58

    
59
void piUnlock (int key)
60
{
61
  pthread_mutex_unlock (&piMutexes [key]) ;
62
}
63