Send a crash report when a hung process is detected.
[chromium-blink-merge.git] / native_client_sdk / src / libraries / third_party / pthreads-win32 / pthread_cond_init.c
blobf28fd67b432eae52af182d6270165a954dfea56f
1 /*
2 * pthread_cond_init.c
4 * Description:
5 * This translation unit implements condition variables and their primitives.
8 * --------------------------------------------------------------------------
10 * Pthreads-win32 - POSIX Threads Library for Win32
11 * Copyright(C) 1998 John E. Bossom
12 * Copyright(C) 1999,2005 Pthreads-win32 contributors
14 * Contact Email: rpj@callisto.canberra.edu.au
16 * The current list of contributors is contained
17 * in the file CONTRIBUTORS included with the source
18 * code distribution. The list can also be seen at the
19 * following World Wide Web location:
20 * http://sources.redhat.com/pthreads-win32/contributors.html
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License as published by the Free Software Foundation; either
25 * version 2 of the License, or (at your option) any later version.
27 * This library is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 * Lesser General Public License for more details.
32 * You should have received a copy of the GNU Lesser General Public
33 * License along with this library in the file COPYING.LIB;
34 * if not, write to the Free Software Foundation, Inc.,
35 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
38 #include "pthread.h"
39 #include "implement.h"
42 int
43 pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr)
45 * ------------------------------------------------------
46 * DOCPUBLIC
47 * This function initializes a condition variable.
49 * PARAMETERS
50 * cond
51 * pointer to an instance of pthread_cond_t
53 * attr
54 * specifies optional creation attributes.
57 * DESCRIPTION
58 * This function initializes a condition variable.
60 * RESULTS
61 * 0 successfully created condition variable,
62 * EINVAL 'attr' is invalid,
63 * EAGAIN insufficient resources (other than
64 * memory,
65 * ENOMEM insufficient memory,
66 * EBUSY 'cond' is already initialized,
68 * ------------------------------------------------------
71 int result;
72 pthread_cond_t cv = NULL;
74 if (cond == NULL)
76 return EINVAL;
79 if ((attr != NULL && *attr != NULL) &&
80 ((*attr)->pshared == PTHREAD_PROCESS_SHARED))
83 * Creating condition variable that can be shared between
84 * processes.
86 result = ENOSYS;
87 goto DONE;
90 cv = (pthread_cond_t) calloc (1, sizeof (*cv));
92 if (cv == NULL)
94 result = ENOMEM;
95 goto DONE;
98 cv->nWaitersBlocked = 0;
99 cv->nWaitersToUnblock = 0;
100 cv->nWaitersGone = 0;
102 if (sem_init (&(cv->semBlockLock), 0, 1) != 0)
104 result = errno;
105 goto FAIL0;
108 if (sem_init (&(cv->semBlockQueue), 0, 0) != 0)
110 result = errno;
111 goto FAIL1;
114 if ((result = pthread_mutex_init (&(cv->mtxUnblockLock), 0)) != 0)
116 goto FAIL2;
119 result = 0;
121 goto DONE;
124 * -------------
125 * Failed...
126 * -------------
128 FAIL2:
129 (void) sem_destroy (&(cv->semBlockQueue));
131 FAIL1:
132 (void) sem_destroy (&(cv->semBlockLock));
134 FAIL0:
135 (void) free (cv);
136 cv = NULL;
138 DONE:
139 if (0 == result)
141 ptw32_mcs_local_node_t node;
143 ptw32_mcs_lock_acquire(&ptw32_cond_list_lock, &node);
145 cv->next = NULL;
146 cv->prev = ptw32_cond_list_tail;
148 if (ptw32_cond_list_tail != NULL)
150 ptw32_cond_list_tail->next = cv;
153 ptw32_cond_list_tail = cv;
155 if (ptw32_cond_list_head == NULL)
157 ptw32_cond_list_head = cv;
160 ptw32_mcs_lock_release(&node);
163 *cond = cv;
165 return result;
167 } /* pthread_cond_init */