diff options
author | Rüdiger Timm <rt@openoffice.org> | 2006-05-02 11:08:47 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2006-05-02 11:08:47 +0000 |
commit | 2d5120737b820fdde3a547cc92e8b4ddbec07964 (patch) | |
tree | c7ce30c64a0cb7ec821630d268fb3cdd66fcbb0f /sal/inc/internal | |
parent | dca1c17b960e40c824fd396242acbee1eb2e97f5 (diff) |
INTEGRATION: CWS mhu12 (1.1.2); FILE ADDED
2006/04/11 16:52:01 mhu 1.1.2.1: #125511# #i23172# #i57754# module sal internal header for 'sal_once_type' (see also pthread_once_t).
Diffstat (limited to 'sal/inc/internal')
-rw-r--r-- | sal/inc/internal/once.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/sal/inc/internal/once.h b/sal/inc/internal/once.h new file mode 100644 index 000000000000..97a2ad7bc6cc --- /dev/null +++ b/sal/inc/internal/once.h @@ -0,0 +1,85 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: once.h,v $ + * + * $Revision: 1.2 $ + * + * last change: $Author: rt $ $Date: 2006-05-02 12:08:47 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_SAL_INTERNAL_ONCE_H +#define INCLUDED_SAL_INTERNAL_ONCE_H + +/** sal_once_type + * (platform dependent) + */ + +#if defined(SAL_UNX) + +#include <pthread.h> + +typedef pthread_once_t sal_once_type; + +#define SAL_ONCE_INIT PTHREAD_ONCE_INIT +#define SAL_ONCE(once, init) pthread_once((once), (init)) + +#elif defined(SAL_W32) + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +typedef struct sal_once_st sal_once_type; +struct sal_once_st +{ + LONG volatile m_done; + LONG volatile m_lock; +}; + +#define SAL_ONCE_INIT { 0, 0 } +#define SAL_ONCE(once, init) \ +{ \ + sal_once_type * control = (once); \ + if (!(control->m_done)) \ + { \ + while (InterlockedExchange(&(control->m_lock), 1) == 1) Sleep(0); \ + if (!(control->m_done)) \ + { \ + void (*init_routine)(void) = (init); \ + (*init_routine)(); \ + control->m_done = 1; \ + } \ + InterlockedExchange(&(control->m_lock), 0); \ + } \ +} + +#else +#error Unknown platform +#endif /* SAL_UNX | SAL_W32 */ + +#endif /* INCLUDED_SAL_INTERNAL_ONCE_H */ |