2008-01-20 18:36:23 +00:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2008-02-19 06:07:53 +00:00
|
|
|
* Copyright 1999-2006 Brian Paul
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Copyright 2008 VMware, Inc.
|
2008-01-20 18:36:23 +00:00
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
2008-02-19 06:07:53 +00:00
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
2008-01-20 18:36:23 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
2008-02-19 06:07:53 +00:00
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
2013-04-21 21:46:48 +01:00
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
2008-01-20 18:36:23 +00:00
|
|
|
**************************************************************************/
|
|
|
|
|
2008-08-26 23:35:12 +01:00
|
|
|
|
2008-02-19 06:07:53 +00:00
|
|
|
/**
|
2008-09-19 02:40:42 +01:00
|
|
|
* @file
|
|
|
|
*
|
2009-12-11 21:00:25 +00:00
|
|
|
* Thread, mutex, condition variable, barrier, semaphore and
|
|
|
|
* thread-specific data functions.
|
2008-02-19 06:07:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-02-02 15:18:01 +00:00
|
|
|
#ifndef OS_THREAD_H_
|
|
|
|
#define OS_THREAD_H_
|
2008-02-19 06:07:53 +00:00
|
|
|
|
|
|
|
|
2008-08-26 23:35:12 +01:00
|
|
|
#include "pipe/p_compiler.h"
|
2009-06-15 18:57:45 +01:00
|
|
|
#include "util/u_debug.h" /* for assert */
|
2017-03-08 22:57:58 +00:00
|
|
|
#include "util/u_thread.h"
|
2008-02-19 06:07:53 +00:00
|
|
|
|
2008-09-05 15:47:06 +01:00
|
|
|
|
2016-07-21 18:51:36 +01:00
|
|
|
#define pipe_mutex_assert_locked(mutex) \
|
|
|
|
__pipe_mutex_assert_locked(&(mutex))
|
|
|
|
|
|
|
|
static inline void
|
2017-03-05 01:32:01 +00:00
|
|
|
__pipe_mutex_assert_locked(mtx_t *mutex)
|
2016-07-21 18:51:36 +01:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* NOTE: this would not work for recursive mutexes, but
|
2017-03-05 01:32:01 +00:00
|
|
|
* mtx_t doesn't support those
|
2016-07-21 18:51:36 +01:00
|
|
|
*/
|
|
|
|
int ret = mtx_trylock(mutex);
|
|
|
|
assert(ret == thrd_busy);
|
|
|
|
if (ret == thrd_success)
|
|
|
|
mtx_unlock(mutex);
|
2017-11-16 15:09:55 +00:00
|
|
|
#else
|
|
|
|
(void)mutex;
|
2016-07-21 18:51:36 +01:00
|
|
|
#endif
|
|
|
|
}
|
2009-12-11 21:07:01 +00:00
|
|
|
|
2010-02-11 02:12:10 +00:00
|
|
|
|
2009-12-08 00:58:46 +00:00
|
|
|
/*
|
|
|
|
* Semaphores
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2017-03-05 01:32:01 +00:00
|
|
|
mtx_t mutex;
|
2017-03-05 23:41:39 +00:00
|
|
|
cnd_t cond;
|
2009-12-08 00:58:46 +00:00
|
|
|
int counter;
|
|
|
|
} pipe_semaphore;
|
|
|
|
|
|
|
|
|
2015-07-21 00:58:43 +01:00
|
|
|
static inline void
|
2009-12-08 00:58:46 +00:00
|
|
|
pipe_semaphore_init(pipe_semaphore *sema, int init_val)
|
|
|
|
{
|
2017-03-05 01:00:15 +00:00
|
|
|
(void) mtx_init(&sema->mutex, mtx_plain);
|
2017-03-04 23:41:29 +00:00
|
|
|
cnd_init(&sema->cond);
|
2009-12-08 00:58:46 +00:00
|
|
|
sema->counter = init_val;
|
|
|
|
}
|
|
|
|
|
2015-07-21 00:58:43 +01:00
|
|
|
static inline void
|
2009-12-08 00:58:46 +00:00
|
|
|
pipe_semaphore_destroy(pipe_semaphore *sema)
|
|
|
|
{
|
2017-03-05 01:32:04 +00:00
|
|
|
mtx_destroy(&sema->mutex);
|
2017-03-04 23:41:30 +00:00
|
|
|
cnd_destroy(&sema->cond);
|
2009-12-08 00:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Signal/increment semaphore counter */
|
2015-07-21 00:58:43 +01:00
|
|
|
static inline void
|
2009-12-08 00:58:46 +00:00
|
|
|
pipe_semaphore_signal(pipe_semaphore *sema)
|
|
|
|
{
|
2017-03-05 01:12:30 +00:00
|
|
|
mtx_lock(&sema->mutex);
|
2009-12-08 00:58:46 +00:00
|
|
|
sema->counter++;
|
2017-03-04 23:41:32 +00:00
|
|
|
cnd_signal(&sema->cond);
|
2017-03-05 01:32:06 +00:00
|
|
|
mtx_unlock(&sema->mutex);
|
2009-12-08 00:58:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Wait for semaphore counter to be greater than zero */
|
2015-07-21 00:58:43 +01:00
|
|
|
static inline void
|
2009-12-08 00:58:46 +00:00
|
|
|
pipe_semaphore_wait(pipe_semaphore *sema)
|
|
|
|
{
|
2017-03-05 01:12:30 +00:00
|
|
|
mtx_lock(&sema->mutex);
|
2009-12-08 00:58:46 +00:00
|
|
|
while (sema->counter <= 0) {
|
2017-03-04 23:41:31 +00:00
|
|
|
cnd_wait(&sema->cond, &sema->mutex);
|
2009-12-08 00:58:46 +00:00
|
|
|
}
|
|
|
|
sema->counter--;
|
2017-03-05 01:32:06 +00:00
|
|
|
mtx_unlock(&sema->mutex);
|
2009-12-08 00:58:46 +00:00
|
|
|
}
|
|
|
|
|
2010-02-02 15:18:01 +00:00
|
|
|
#endif /* OS_THREAD_H_ */
|