Blame view

RIOT/sys/posix/pthread/pthread_mutex.c 1.4 KB
a752c7ab   elopes   add first test an...
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
  /*
   * Copyright (C) 2013 Freie Universität Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup pthread
   * @{
   * @file
   * @brief   Mutual exclusion.
   * @author  Christian Mehlis <mehlis@inf.fu-berlin.de>
   * @author  René Kijewski <kijewski@inf.fu-berlin.de>
   * @}
   */
  
  #include <string.h>
  #include <stddef.h>
  
  #include "pthread.h"
  
  int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
  {
      (void) mutexattr;
  
      if (!mutex) {
          return -1;
      }
  
      mutex_init(mutex);
      return 0;
  }
  
  int pthread_mutex_destroy(pthread_mutex_t *mutex)
  {
      (void) mutex;
      return 0;
  }
  
  int pthread_mutex_trylock(pthread_mutex_t *mutex)
  {
      if (!mutex) {
          return -1;
      }
  
      /* mutex_trylock() returns 1 on success, and 0 otherwise. */
      /* We want the reverse. */
      return 1 - mutex_trylock(mutex);
  }
  
  int pthread_mutex_lock(pthread_mutex_t *mutex)
  {
      if (!mutex) {
          return -1;
      }
  
      mutex_lock(mutex);
      return 0;
  }
  
  int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime)
  {
      (void) mutex;
      (void) abstime;
      return -1; /* currently not supported */
  }
  
  int pthread_mutex_unlock(pthread_mutex_t *mutex)
  {
      if (!mutex) {
          return -1;
      }
  
      mutex_unlock(mutex);
      return 0;
  }