• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

GSafeFlags Class Reference

A thread safe class representing a set of flags. More...

#include <GThreads.h>

Inheritance diagram for GSafeFlags:

Inheritance graph
[legend]

List of all members.


Public Member Functions

 operator long (void) const
GSafeFlags & operator= (long flags)
bool test_and_modify (long set_mask, long clr_mask, long set_mask1, long clr_mask1)
void wait_and_modify (long set_mask, long clr_mask, long set_mask1, long clr_mask1)
GThreads.h
Files #"GThreads.h"# and #"GThreads.cpp"# implement common entry points for multithreading on multiple platforms.

Each execution thread is represented by an instance of class {GThread}. Synchronization is provided by class {GMonitor} which implements a monitor (C.A.R Hoare, Communications of the ACM, 17(10), 1974).

The value of compiler symbol THREADMODEL# selects an appropriate implementation for these classes. The current implementation supports the following values: {description} [-DTHREADMODEL=NOTHREADS] Dummy implementation. This is a good choice when the multithreading features are not required, because it minimizes the portability problems. This is currently the default when compiling under Unix. [-DTHREADMODEL=WINTHREADS] Windows implementation. This is the default when compiling under Windows. [-DTHREADMODEL=MACTHREADS] Macintosh implementation, which is based on the MacOS cooperative model. The current implementation does not yet fully support synchronization. This is the default when compiling under MacOS. [-DTHREADMODEL=POSIXTHREADS] Posix implementation. This implementation also supports DCE threads. The behavior of the code is subject to the quality of the system implementation of Posix threads. [-DTHREADMODEL=COTHREADS] Custom cooperative threads. These custom threads do not redefine system calls. Before executing a potentially blocking system function, each thread must explicitly check whether it is going to block and yield control explicitly if this is the case. This code must be compiled with a patched version of egcs-1.1.1 {http://egcs.cygnus.com}. The patch addresses exception thread-safety and is provided in #"@Tools/libgcc2.c.diff"#. Once you get the right compiler, this implementation is remarkably compact and portable. A variety of processors are supported, including mips, intel, sparc, hppa, and alpha. [-DTHREADMODEL=JRITHREADS] Java implementation hooks. Multi-threading within a Netscape plugin can be tricky. A simple idea however consists of implementing the threading primitives in Java and to access them using JRI. The classes just contain a JRIGlobalRef. This is not a real implementation since everything (Java code, native functions, stubs, exception thread safety) must be addressed by the plugin source code. Performance may be a serious issue. {description}

{ Portability}: The simultaneous use of threads and exceptions caused a lot of portability headaches under Unix. We eventually decided to implement the COTHREADS cooperative threads (because preemptive threads have more problems) and to patch EGCS in order to make exception handling COTHREAD-safe.

Portable threads

Author:
L\'eon Bottou <leonb@research.att.com> -- initial implementation.\ Praveen Guduru <praveen@sanskrit.lz.att.com> -- mac implementation.
From: Leon Bottou, 1/31/2002 Almost unchanged by Lizardtech. GSafeFlags should go because it not as safe as it claims.

Version:
$Id: GThreads.h,v 1.10 2003/11/07 22:08:21 leonb Exp $#


 GSafeFlags (long flags=0)
void modify (long set_mask, long clr_mask)
GSafeFlags & operator&= (long mask)
GSafeFlags & operator|= (long mask)
void wait_for_flags (long set_mask, long clr_mask=0) const

Detailed Description

A thread safe class representing a set of flags.

The flags are protected by {GMonitor}, which is attempted to be locked whenever somebody accesses the flags. One can modify the class contents using one of two functions: {test_and_modify}() and {wait_and_modify}(). Both of them provide atomic operation of testing (first) and modification (second). The flags remain locked between the moment of testing and modification, which guarantees, that their state cannot be changed in between of these operations.

Definition at line 505 of file GThreads.h.


Constructor & Destructor Documentation

GSafeFlags::GSafeFlags ( long  flags = 0  )  [inline]

Constructs GSafeFlags# object.

Definition at line 552 of file GThreads.h.


Member Function Documentation

void GSafeFlags::modify ( long  set_mask,
long  clr_mask 
) [inline]

Modifies the flags by setting all bits mentioned in set_mask# and clearing all bits mentioned in clr_mask#.

If the flags have actually been modified, a broadcast will be sent.

Definition at line 564 of file GThreads.h.

GSafeFlags::operator long ( void   )  const

Returns the value of the flags.

Definition at line 1830 of file GThreads.cpp.

GSafeFlags & GSafeFlags::operator&= ( long  mask  )  [inline]

Modifies the flags by ANDing them with the provided mask.

A broadcast will be sent after the modification is done.

Definition at line 577 of file GThreads.h.

GSafeFlags & GSafeFlags::operator= ( long  flags  ) 

Assignment operator.

Will also wake up threads waiting for the flags to change.

Definition at line 1818 of file GThreads.cpp.

GSafeFlags & GSafeFlags::operator|= ( long  mask  )  [inline]

Modifies the flags by ORing them with the provided mask.

A broadcast will be sent after the modification is done.

Definition at line 570 of file GThreads.h.

bool GSafeFlags::test_and_modify ( long  set_mask,
long  clr_mask,
long  set_mask1,
long  clr_mask1 
)

If all bits mentioned in set_mask# are set in the flags and all bits mentioned in clr_mask# are cleared in the flags, it sets all bits from set_mask1# in the flags, clears all flags from clr_mask1# in the flags and returns TRUE#.

Otherwise returns FALSE#.

Definition at line 1840 of file GThreads.cpp.

void GSafeFlags::wait_and_modify ( long  set_mask,
long  clr_mask,
long  set_mask1,
long  clr_mask1 
)

Waits until all bits mentioned in set_mask# are set in the flags and all bits mentioned in clr_flags# are cleared in the flags.

After that it sets bits from set_mask1# and clears bits from clr_mask1# in the flags.

Definition at line 1863 of file GThreads.cpp.

void GSafeFlags::wait_for_flags ( long  set_mask,
long  clr_mask = 0 
) const [inline]

Waits until all bits set in set_mask# are set in the flags and all bits mentioned in clr_mask# are cleared in the flags.

Definition at line 558 of file GThreads.h.


The documentation for this class was generated from the following files:
  • GThreads.h
  • GThreads.cpp

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal