From 54b6cfa9a9e5b861a9930af873580d6dc20f773c Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Tue, 21 Oct 2008 07:00:00 -0700 Subject: Initial Contribution --- include/private/media/AudioTrackShared.h | 64 +++ include/private/opengles/gl_context.h | 624 +++++++++++++++++++++++++++++ include/private/ui/LayerState.h | 75 ++++ include/private/ui/SharedState.h | 168 ++++++++ include/private/ui/SurfaceFlingerSynchro.h | 76 ++++ include/private/utils/Static.h | 58 +++ include/private/utils/binder_module.h | 148 +++++++ include/private/utils/futex_synchro.h | 60 +++ 8 files changed, 1273 insertions(+) create mode 100644 include/private/media/AudioTrackShared.h create mode 100644 include/private/opengles/gl_context.h create mode 100644 include/private/ui/LayerState.h create mode 100644 include/private/ui/SharedState.h create mode 100644 include/private/ui/SurfaceFlingerSynchro.h create mode 100644 include/private/utils/Static.h create mode 100644 include/private/utils/binder_module.h create mode 100644 include/private/utils/futex_synchro.h (limited to 'include/private') diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h new file mode 100644 index 0000000..1878f3c --- /dev/null +++ b/include/private/media/AudioTrackShared.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_AUDIO_TRACK_SHARED_H +#define ANDROID_AUDIO_TRACK_SHARED_H + +#include +#include + +#include + +namespace android { + +// ---------------------------------------------------------------------------- + +#define MAX_SAMPLE_RATE 65535 +#define THREAD_PRIORITY_AUDIO_CLIENT (ANDROID_PRIORITY_AUDIO) + +struct audio_track_cblk_t +{ + enum { + SEQUENCE_MASK = 0xFFFFFF00, + BUFFER_MASK = 0x000000FF + }; + + Mutex lock; + Condition cv; + volatile uint32_t user; + volatile uint32_t server; + volatile union { + uint16_t volume[2]; + uint32_t volumeLR; + }; + uint16_t sampleRate; + uint16_t reserved; + + void* buffers; + size_t size; + + audio_track_cblk_t(); + uint32_t stepUser(int bufferCount); + bool stepServer(int bufferCount); + void* buffer(int id) const; +}; + + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_AUDIO_TRACK_SHARED_H diff --git a/include/private/opengles/gl_context.h b/include/private/opengles/gl_context.h new file mode 100644 index 0000000..67d50fd --- /dev/null +++ b/include/private/opengles/gl_context.h @@ -0,0 +1,624 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_OPENGLES_CONTEXT_H +#define ANDROID_OPENGLES_CONTEXT_H + +#include +#include +#include +#include +#ifdef HAVE_ANDROID_OS +#include +#endif + +#include + +#include + +namespace android { + +const unsigned int OGLES_NUM_COMPRESSED_TEXTURE_FORMATS = 10; + +class EGLTextureObject; +class EGLSurfaceManager; +class EGLBufferObjectManager; + +namespace gl { + +struct ogles_context_t; +struct matrixx_t; +struct transform_t; +struct buffer_t; + +ogles_context_t* getGlContext(); + +template +static inline void swap(T& a, T& b) { + T t(a); a = b; b = t; +} +template +inline T max(T a, T b) { + return a +inline T max(T a, T b, T c) { + return max(a, max(b, c)); +} +template +inline T min(T a, T b) { + return a +inline T min(T a, T b, T c) { + return min(a, min(b, c)); +} +template +inline T min(T a, T b, T c, T d) { + return min(min(a,b), min(c,d)); +} + +// ---------------------------------------------------------------------------- +// vertices +// ---------------------------------------------------------------------------- + +struct vec3_t { + union { + struct { GLfixed x, y, z; }; + struct { GLfixed r, g, b; }; + struct { GLfixed S, T, R; }; + GLfixed v[3]; + }; +}; + +struct vec4_t { + union { + struct { GLfixed x, y, z, w; }; + struct { GLfixed r, g, b, a; }; + struct { GLfixed S, T, R, Q; }; + GLfixed v[4]; + }; +}; + +struct vertex_t { + enum { + // these constant matter for our clipping + CLIP_L = 0x0001, // clipping flags + CLIP_R = 0x0002, + CLIP_B = 0x0004, + CLIP_T = 0x0008, + CLIP_N = 0x0010, + CLIP_F = 0x0020, + + EYE = 0x0040, + RESERVED = 0x0080, + + USER_CLIP_0 = 0x0100, // user clipping flags + USER_CLIP_1 = 0x0200, + USER_CLIP_2 = 0x0400, + USER_CLIP_3 = 0x0800, + USER_CLIP_4 = 0x1000, + USER_CLIP_5 = 0x2000, + + LIT = 0x4000, // lighting has been applied + TT = 0x8000, // texture coords transformed + + FRUSTUM_CLIP_ALL= 0x003F, + USER_CLIP_ALL = 0x3F00, + CLIP_ALL = 0x3F3F, + }; + + // the fields below are arranged to minimize d-cache usage + // we group together, by cache-line, the fields most likely to be used + + union { + vec4_t obj; + vec4_t eye; + }; + vec4_t clip; + + uint32_t flags; + size_t index; // cache tag, and vertex index + GLfixed fog; + uint8_t locked; + uint8_t mru; + uint8_t reserved[2]; + vec4_t window; + + vec4_t color; + vec4_t texture[GGL_TEXTURE_UNIT_COUNT]; + uint32_t reserved1[4]; + + inline void clear() { + flags = index = locked = mru = 0; + } +}; + +struct point_size_t { + GGLcoord size; + GLboolean smooth; +}; + +struct line_width_t { + GGLcoord width; + GLboolean smooth; +}; + +struct polygon_offset_t { + GLfixed factor; + GLfixed units; + GLboolean enable; +}; + +// ---------------------------------------------------------------------------- +// arrays +// ---------------------------------------------------------------------------- + +struct array_t { + typedef void (*fetcher_t)(ogles_context_t*, GLfixed*, const GLvoid*); + fetcher_t fetch; + GLvoid const* physical_pointer; + GLint size; + GLsizei stride; + GLvoid const* pointer; + buffer_t const* bo; + uint16_t type; + GLboolean enable; + GLboolean pad; + GLsizei bounds; + void init(GLint, GLenum, GLsizei, const GLvoid *, const buffer_t*, GLsizei); + inline void resolve(); + inline const GLubyte* element(GLint i) const { + return (const GLubyte*)physical_pointer + i * stride; + } +}; + +struct array_machine_t { + array_t vertex; + array_t normal; + array_t color; + array_t texture[GGL_TEXTURE_UNIT_COUNT]; + uint8_t activeTexture; + uint8_t tmu; + uint16_t cull; + uint32_t flags; + GLenum indicesType; + buffer_t const* array_buffer; + buffer_t const* element_array_buffer; + + void (*compileElements)(ogles_context_t*, vertex_t*, GLint, GLsizei); + void (*compileElement)(ogles_context_t*, vertex_t*, GLint); + + void (*mvp_transform)(transform_t const*, vec4_t*, vec4_t const*); + void (*mv_transform)(transform_t const*, vec4_t*, vec4_t const*); + void (*tex_transform[2])(transform_t const*, vec4_t*, vec4_t const*); + void (*perspective)(ogles_context_t*c, vertex_t* v); + void (*clipVertex)(ogles_context_t* c, vertex_t* nv, + GGLfixed t, const vertex_t* s, const vertex_t* p); + void (*clipEye)(ogles_context_t* c, vertex_t* nv, + GGLfixed t, const vertex_t* s, const vertex_t* p); +}; + +struct vertex_cache_t { + enum { + // must be at least 4 + // 3 vertice for triangles + // or 2 + 2 for indexed triangles w/ cache contention + VERTEX_BUFFER_SIZE = 8, + // must be a power of two and at least 3 + VERTEX_CACHE_SIZE = 64, // 8 KB + + INDEX_BITS = 16, + INDEX_MASK = ((1LU<(pthread_getspecific(gGLKey)); + } +#endif + + +struct prims_t { + typedef ogles_context_t* GL; + void (*renderPoint)(GL, vertex_t*); + void (*renderLine)(GL, vertex_t*, vertex_t*); + void (*renderTriangle)(GL, vertex_t*, vertex_t*, vertex_t*); +}; + +struct ogles_context_t { + context_t rasterizer; + array_machine_t arrays __attribute__((aligned(32))); + texture_state_t textures; + transform_state_t transforms; + vertex_cache_t vc; + prims_t prims; + culling_t cull; + lighting_t lighting; + user_clip_planes_t clipPlanes; + compute_iterators_t lerp; __attribute__((aligned(32))); + vertex_t current; + vec4_t currentColorClamped; + vec3_t currentNormal; + viewport_t viewport; + point_size_t point; + line_width_t line; + polygon_offset_t polygonOffset; + fog_t fog; + uint32_t perspective : 1; + uint32_t transformTextures : 1; + EGLSurfaceManager* surfaceManager; + EGLBufferObjectManager* bufferObjectManager; + GLenum error; + + static inline ogles_context_t* get() { + return getGlThreadSpecific(); + } + +}; + +}; // namespace gl +}; // namespace android + +#endif // ANDROID_OPENGLES_CONTEXT_H + diff --git a/include/private/ui/LayerState.h b/include/private/ui/LayerState.h new file mode 100644 index 0000000..b6fcd80 --- /dev/null +++ b/include/private/ui/LayerState.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_COMPOSER_LAYER_STATE_H +#define ANDROID_COMPOSER_LAYER_STATE_H + +#include +#include + +#include + +#include +#include + +#include + +namespace android { + +class Parcel; + +struct layer_state_t { + + layer_state_t() + : surface(0), what(0), + x(0), y(0), z(0), w(0), h(0), + alpha(0), tint(0), flags(0), mask(0), + reserved(0) + { + matrix.dsdx = matrix.dtdy = 1.0f; + matrix.dsdy = matrix.dtdx = 0.0f; + } + + status_t write(Parcel& output) const; + status_t read(const Parcel& input); + + struct matrix22_t { + float dsdx; + float dtdx; + float dsdy; + float dtdy; + }; + SurfaceID surface; + uint32_t what; + int32_t x; + int32_t y; + uint32_t z; + uint32_t w; + uint32_t h; + float alpha; + uint32_t tint; + uint8_t flags; + uint8_t mask; + uint8_t reserved; + matrix22_t matrix; + // non POD must be last. see write/read + Region transparentRegion; +}; + +}; // namespace android + +#endif // ANDROID_COMPOSER_LAYER_STATE_H + diff --git a/include/private/ui/SharedState.h b/include/private/ui/SharedState.h new file mode 100644 index 0000000..546d0ad --- /dev/null +++ b/include/private/ui/SharedState.h @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_UI_SHARED_STATE_H +#define ANDROID_UI_SHARED_STATE_H + +#include +#include + +#include + +namespace android { + +/* + * These structures are shared between the composer process and its clients + */ + +// --------------------------------------------------------------------------- + +struct surface_info_t { // 4 longs, 16 bytes + enum { + eBufferDirty = 0x01 + }; + uint16_t w; + uint16_t h; + uint16_t stride; + uint16_t bpr; + uint16_t reserved; + uint8_t format; + uint8_t flags; + ssize_t bits_offset; +}; + +// --------------------------------------------------------------------------- + +const uint32_t NUM_LAYERS_MAX = 31; + +enum { // layer_cblk_t swapState + eIndex = 0x00000001, + eFlipRequested = 0x00000002, + + eResizeBuffer0 = 0x00000004, + eResizeBuffer1 = 0x00000008, + eResizeRequested = eResizeBuffer0 | eResizeBuffer1, + + eBusy = 0x00000010, + eLocked = 0x00000020, + eNextFlipPending = 0x00000040, + eInvalidSurface = 0x00000080 +}; + +enum { // layer_cblk_t flags + eLayerNotPosted = 0x00000001, + eNoCopyBack = 0x00000002, + eReserved = 0x0000007C, + eBufferIndexShift = 7, + eBufferIndex = 1<>1)); + } + static inline int frontBuffer(uint32_t state) { + return 1 - backBuffer(state); + } +}; + +// --------------------------------------------------------------------------- + +struct per_client_cblk_t // 4KB max +{ + Mutex lock; + Condition cv; + layer_cblk_t layers[NUM_LAYERS_MAX] __attribute__((aligned(32))); + + enum { + BLOCKING = 0x00000001, + INSPECT = 0x00000002 + }; + + per_client_cblk_t(); + + // these functions are used by the clients + status_t validate(size_t i) const; + int32_t lock_layer(size_t i, uint32_t flags); + uint32_t unlock_layer_and_post(size_t i); + void unlock_layer(size_t i); +}; +// --------------------------------------------------------------------------- + +const uint32_t NUM_DISPLAY_MAX = 4; + +struct display_cblk_t +{ + uint16_t w; + uint16_t h; + uint8_t format; + uint8_t orientation; + uint8_t reserved[2]; + float fps; + float density; + float xdpi; + float ydpi; + uint32_t pad[2]; +}; + +struct surface_flinger_cblk_t // 4KB max +{ + surface_flinger_cblk_t(); + + uint8_t connected; + uint8_t reserved[3]; + uint32_t pad[7]; + + display_cblk_t displays[NUM_DISPLAY_MAX]; +}; + +// --------------------------------------------------------------------------- + +template struct CTA; +template<> struct CTA { }; + +// compile-time assertions. just to avoid catastrophes. +inline void compile_time_asserts() { + CTA sizeof__layer_cblk_t__eq_128; + (void)sizeof__layer_cblk_t__eq_128; // we don't want a warning + CTA sizeof__per_client_cblk_t__le_4096; + (void)sizeof__per_client_cblk_t__le_4096; // we don't want a warning + CTA sizeof__surface_flinger_cblk_t__le_4096; + (void)sizeof__surface_flinger_cblk_t__le_4096; // we don't want a warning +} + +}; // namespace android + +#endif // ANDROID_UI_SHARED_STATE_H + diff --git a/include/private/ui/SurfaceFlingerSynchro.h b/include/private/ui/SurfaceFlingerSynchro.h new file mode 100644 index 0000000..ff91b61 --- /dev/null +++ b/include/private/ui/SurfaceFlingerSynchro.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_SURFACE_FLINGER_SYNCHRO_H +#define ANDROID_SURFACE_FLINGER_SYNCHRO_H + +#include +#include +#include +#include +#include + +namespace android { + +class SurfaceFlinger; + +class SurfaceFlingerSynchro +{ +public: + + // client constructor + SurfaceFlingerSynchro(const sp& flinger); + ~SurfaceFlingerSynchro(); + + // signal surfaceflinger for some work + status_t signal(); + +private: + class Barrier { + public: + Barrier(); + ~Barrier(); + void open(); + void close(); + void waitAndClose(); + status_t waitAndClose(nsecs_t timeout); + private: + enum { OPENED, CLOSED }; + mutable Mutex lock; + mutable Condition cv; + volatile int state; + }; + + friend class SurfaceFlinger; + + // server constructor + SurfaceFlingerSynchro(); + + void open(); + + // wait until there is some work to do + status_t wait(); + status_t wait(nsecs_t timeout); + + sp mSurfaceComposer; + Barrier mBarrier; +}; + +}; // namespace android + +#endif // ANDROID_SURFACE_FLINGER_SYNCHRO_H + diff --git a/include/private/utils/Static.h b/include/private/utils/Static.h new file mode 100644 index 0000000..f1439b7 --- /dev/null +++ b/include/private/utils/Static.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// All static variables go here, to control initialization and +// destruction order in the library. + +#include +#include + +#ifndef LIBUTILS_NATIVE +#include +#include +#include +#include +#include +#endif + +namespace android { +// For TextStream.cpp +extern Vector gTextBuffers; + +// For String8.cpp +extern void initialize_string8(); +extern void terminate_string8(); + +// For String16.cpp +extern void initialize_string16(); +extern void terminate_string16(); + + + +#ifndef LIBUTILS_NATIVE + +// For ProcessState.cpp +extern Mutex gProcessMutex; +extern sp gProcess; + +// For ServiceManager.cpp +extern Mutex gDefaultServiceManagerLock; +extern sp gDefaultServiceManager; +extern sp gPermissionController; + +#endif + +} // namespace android diff --git a/include/private/utils/binder_module.h b/include/private/utils/binder_module.h new file mode 100644 index 0000000..fdf327e --- /dev/null +++ b/include/private/utils/binder_module.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _BINDER_MODULE_H_ +#define _BINDER_MODULE_H_ + +#ifdef __cplusplus +namespace android { +#endif + +#if defined(HAVE_ANDROID_OS) + +/* obtain structures and constants from the kernel header */ + +#include +#include + +#else + +/* Some parts of the simulator need fake versions of this + * stuff in order to compile. Really this should go away + * entirely... + */ + +#define BINDER_CURRENT_PROTOCOL_VERSION 7 + +#define BINDER_TYPE_BINDER 1 +#define BINDER_TYPE_WEAK_BINDER 2 +#define BINDER_TYPE_HANDLE 3 +#define BINDER_TYPE_WEAK_HANDLE 4 +#define BINDER_TYPE_FD 5 + +struct flat_binder_object { + unsigned long type; + unsigned long flags; + union { + void *binder; + signed long handle; + }; + void *cookie; +}; + +struct binder_write_read { + signed long write_size; + signed long write_consumed; + unsigned long write_buffer; + signed long read_size; + signed long read_consumed; + unsigned long read_buffer; +}; + +struct binder_transaction_data { + union { + size_t handle; + void *ptr; + } target; + void *cookie; + unsigned int code; + + unsigned int flags; + pid_t sender_pid; + uid_t sender_euid; + size_t data_size; + size_t offsets_size; + + union { + struct { + const void *buffer; + const void *offsets; + } ptr; + uint8_t buf[8]; + } data; +}; + +enum transaction_flags { + TF_ONE_WAY = 0x01, + TF_ROOT_OBJECT = 0x04, + TF_STATUS_CODE = 0x08, + TF_ACCEPT_FDS = 0x10, +}; + + +enum { + FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff, + FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100, +}; + +enum BinderDriverReturnProtocol { + BR_ERROR, + BR_OK, + BR_TRANSACTION, + BR_REPLY, + BR_ACQUIRE_RESULT, + BR_DEAD_REPLY, + BR_TRANSACTION_COMPLETE, + BR_INCREFS, + BR_ACQUIRE, + BR_RELEASE, + BR_DECREFS, + BR_ATTEMPT_ACQUIRE, + BR_NOOP, + BR_SPAWN_LOOPER, + BR_FINISHED, + BR_DEAD_BINDER, + BR_CLEAR_DEATH_NOTIFICATION_DONE, + BR_FAILED_REPLY, +}; + +enum BinderDriverCommandProtocol { + BC_TRANSACTION, + BC_REPLY, + BC_ACQUIRE_RESULT, + BC_FREE_BUFFER, + BC_INCREFS, + BC_ACQUIRE, + BC_RELEASE, + BC_DECREFS, + BC_INCREFS_DONE, + BC_ACQUIRE_DONE, + BC_ATTEMPT_ACQUIRE, + BC_REGISTER_LOOPER, + BC_ENTER_LOOPER, + BC_EXIT_LOOPER, + BC_REQUEST_DEATH_NOTIFICATION, + BC_CLEAR_DEATH_NOTIFICATION, + BC_DEAD_BINDER_DONE, +}; + +#endif + +#ifdef __cplusplus +} // namespace android +#endif + +#endif // _BINDER_MODULE_H_ diff --git a/include/private/utils/futex_synchro.h b/include/private/utils/futex_synchro.h new file mode 100644 index 0000000..ac2ab19 --- /dev/null +++ b/include/private/utils/futex_synchro.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FUTEX_SYNCHRO_H +#define _FUTEX_SYNCHRO_H + +#ifndef HAVE_FUTEX +#error "HAVE_FUTEX not defined" +#endif + +#define FUTEX_WAIT_INFINITE (0) + +typedef struct futex_mutex_t futex_mutex_t; + +struct futex_mutex_t +{ + volatile int value; +}; + +typedef struct futex_cond_t futex_cond_t; + +struct futex_cond_t +{ + volatile int value; +}; + + +#if __cplusplus +extern "C" { +#endif + +void futex_mutex_init(futex_mutex_t *m); +int futex_mutex_lock(futex_mutex_t *m, unsigned msec); +void futex_mutex_unlock(futex_mutex_t *m); +int futex_mutex_trylock(futex_mutex_t *m); + +void futex_cond_init(futex_cond_t *c); +int futex_cond_wait(futex_cond_t *c, futex_mutex_t *m, unsigned msec); +void futex_cond_signal(futex_cond_t *c); +void futex_cond_broadcast(futex_cond_t *c); + +#if __cplusplus +} // extern "C" +#endif + +#endif // _FUTEX_SYNCHRO_H + -- cgit v1.1