Commit 277ec183 by alokp@chromium.org

Added support for building glsl translator on posix platforms.

Review URL: http://codereview.appspot.com/958043 git-svn-id: https://angleproject.googlecode.com/svn/trunk@184 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d2cf25db
......@@ -3,8 +3,6 @@
# found in the LICENSE file.
{
'variables': {
},
'targets': [
{
'target_name': 'translator_common',
......@@ -37,7 +35,6 @@
'compiler/localintermediate.h',
'compiler/MMap.h',
'compiler/osinclude.h',
'compiler/ossource.cpp',
'compiler/parseConst.cpp',
'compiler/ParseHelper.cpp',
'compiler/ParseHelper.h',
......@@ -75,6 +72,13 @@
'compiler/Gen_glslang_tab.cpp',
'compiler/glslang_tab.h',
],
'conditions': [
['OS=="win"', {
'sources': ['compiler/ossource_win.cpp'],
}, { # else: posix
'sources': ['compiler/ossource_posix.cpp'],
}],
],
'actions': [
{
'action_name': 'flex_glslang',
......
......@@ -12,30 +12,51 @@
// declares any windows specific functions.
//
#if !(defined(_WIN32) || defined(_WIN64))
#error Trying to include a windows specific file in a non windows build.
#if defined(_WIN32) || defined(_WIN64)
#define ANGLE_OS_WIN
#elif defined(__APPLE__) || defined(__linux__) || \
defined(__FreeBSD__) || defined(__OpenBSD__) || \
defined(__sun)
#define ANGLE_OS_POSIX
#else
#error Unsupported platform.
#endif
#if defined(ANGLE_OS_WIN)
#define STRICT
#define VC_EXTRALEAN 1
#include <windows.h>
#include <assert.h>
#elif defined(ANGLE_OS_POSIX)
#include <pthread.h>
#include <semaphore.h>
#include <errno.h>
#endif // ANGLE_OS_WIN
#include <assert.h>
//
// Thread Local Storage Operations
//
#if defined(ANGLE_OS_WIN)
typedef DWORD OS_TLSIndex;
#define OS_INVALID_TLS_INDEX (TLS_OUT_OF_INDEXES)
#elif defined(ANGLE_OS_POSIX)
typedef unsigned int OS_TLSIndex;
#define OS_INVALID_TLS_INDEX 0xFFFFFFFF
#endif // ANGLE_OS_WIN
OS_TLSIndex OS_AllocTLSIndex();
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);
bool OS_FreeTLSIndex(OS_TLSIndex nIndex);
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue);
bool OS_FreeTLSIndex(OS_TLSIndex nIndex);
inline void* OS_GetTLSValue(OS_TLSIndex nIndex)
{
assert(nIndex != OS_INVALID_TLS_INDEX);
return TlsGetValue(nIndex);
assert(nIndex != OS_INVALID_TLS_INDEX);
#if defined(ANGLE_OS_WIN)
return TlsGetValue(nIndex);
#elif defined(ANGLE_OS_POSIX)
return pthread_getspecific(nIndex);
#endif // ANGLE_OS_WIN
}
#endif // __OSINCLUDE_H
//
// Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
//
// This file contains the posix specific functions
//
#include "compiler/osinclude.h"
#if !defined(ANGLE_OS_POSIX)
#error Trying to build a posix specific file in a non-posix build.
#endif
//
// Thread cleanup
//
//
// Wrapper for Linux call to DetachThread.
// This is required as pthread_cleanup_push() expects the cleanup routine
// to return void.
//
void DetachThreadLinux(void *)
{
DetachThread();
}
//
// Registers cleanup handler, sets cancel type and state, and excecutes
// the thread specific cleanup handler. When OpenGL applications are run with
// the driver code, Linux OS does the thread cleanup.
//
void OS_CleanupThreadData(void)
{
int old_cancel_state, old_cancel_type;
void *cleanupArg = NULL;
//
// Set thread cancel state and push cleanup handler.
//
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancel_state);
pthread_cleanup_push(DetachThreadLinux, (void *) cleanupArg);
//
// Put the thread in deferred cancellation mode.
//
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &old_cancel_type);
//
// Pop cleanup handler and execute it prior to unregistering
// the cleanup handler.
//
pthread_cleanup_pop(1);
//
// Restore the thread's previous cancellation mode.
//
pthread_setcanceltype(old_cancel_state, NULL);
}
//
// Thread Local Storage Operations
//
OS_TLSIndex OS_AllocTLSIndex()
{
pthread_key_t pPoolIndex;
//
// Create global pool key.
//
if ((pthread_key_create(&pPoolIndex, NULL)) != 0) {
assert(0 && "OS_AllocTLSIndex(): Unable to allocate Thread Local Storage");
return false;
}
else {
return pPoolIndex;
}
}
bool OS_SetTLSValue(OS_TLSIndex nIndex, void *lpvValue)
{
if (nIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
return false;
}
if (pthread_setspecific(nIndex, lpvValue) == 0)
return true;
else
return false;
}
bool OS_FreeTLSIndex(OS_TLSIndex nIndex)
{
if (nIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "OS_SetTLSValue(): Invalid TLS Index");
return false;
}
//
// Delete the global pool key.
//
if (pthread_key_delete(nIndex) == 0)
return true;
else
return false;
}
......@@ -9,7 +9,7 @@
// This file contains contains the window's specific functions
//
#if !(defined(_WIN32) || defined(_WIN64))
#if !defined(ANGLE_OS_WIN)
#error Trying to build a windows specific file in a non windows build.
#endif
......
......@@ -228,7 +228,7 @@
>
</File>
<File
RelativePath=".\ossource.cpp"
RelativePath=".\ossource_win.cpp"
>
</File>
<File
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment