~ubuntu-branches/ubuntu/lucid/gnustep-base/lucid

« back to all changes in this revision

Viewing changes to Source/NSThread.m

  • Committer: Bazaar Package Importer
  • Author(s): Hubert Chathi
  • Date: 2009-04-11 13:30:33 UTC
  • mfrom: (1.2.8 upstream) (7.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090411133033-g6qrsuo8mep7h0eo
Tags: 1.19.0-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
   Boston, MA 02111 USA.
29
29
 
30
30
   <title>NSThread class reference</title>
31
 
   $Date: 2008-06-12 11:44:00 +0100 (Thu, 12 Jun 2008) $ $Revision: 26630 $
 
31
   $Date: 2008-09-23 09:10:59 +0100 (Tue, 23 Sep 2008) $ $Revision: 26864 $
32
32
*/
33
33
 
34
34
#include "config.h"
51
51
#ifdef NeXT_RUNTIME
52
52
#include "thr-mach.h"
53
53
#endif
 
54
#ifdef HAVE_SYS_FILE_H
 
55
#include <sys/file.h>
 
56
#endif
 
57
#ifdef HAVE_SYS_FCNTL_H
 
58
#include <sys/fcntl.h>
 
59
#endif
54
60
 
55
61
#include <errno.h>
56
62
 
 
63
#ifdef  __POSIX_SOURCE
 
64
#define NBLK_OPT     O_NONBLOCK
 
65
#else
 
66
#define NBLK_OPT     FNDELAY
 
67
#endif
 
68
 
57
69
#include "Foundation/NSDebug.h"
58
70
#include "Foundation/NSException.h"
59
71
#include "Foundation/NSThread.h"
611
623
 
612
624
- (void) dealloc
613
625
{
 
626
  if (self == defaultThread)
 
627
    {
 
628
      [self retain];
 
629
      [NSException raise: NSInternalInconsistencyException
 
630
                  format: @"Deallocating the default thread is not allowed!"];
 
631
    }
614
632
  if (_active == YES)
615
633
    {
616
634
      [NSException raise: NSInternalInconsistencyException
652
670
        }
653
671
    }
654
672
  DESTROY(_gcontext);
655
 
  if (self == defaultThread)
656
 
    {
657
 
      defaultThread = nil;
658
 
    }
659
673
  NSDeallocateObject(self);
660
674
  GSNOSUPERDEALLOC;
661
675
}
862
876
{
863
877
  [lock lock];
864
878
  [performers addObject: performer];
865
 
  [lock unlock];
866
879
#if defined(__MINGW32__)
867
880
  if (SetEvent(event) == 0)
868
881
    {
874
887
      NSLog(@"Write to pipe failed - %@", [NSError _last]);
875
888
    }
876
889
#endif
 
890
  [lock unlock];
877
891
}
878
892
 
879
893
- (void) dealloc
898
912
 
899
913
  if (pipe(fd) == 0)
900
914
    {
 
915
      int       e;
 
916
 
901
917
      inputFd = fd[0];
902
918
      outputFd = fd[1];
 
919
      if ((e = fcntl(inputFd, F_GETFL, 0)) >= 0)
 
920
        {
 
921
          e |= NBLK_OPT;
 
922
          if (fcntl(inputFd, F_SETFL, e) < 0)
 
923
            {
 
924
              [NSException raise: NSInternalInconsistencyException
 
925
                format: @"Failed to set non block flag for perform in thread"];
 
926
            }
 
927
        }
 
928
      else
 
929
        {
 
930
          [NSException raise: NSInternalInconsistencyException
 
931
            format: @"Failed to get non block flag for perform in thread"];
 
932
        }
903
933
    }
904
934
  else
905
935
    {
918
948
  [lock lock];
919
949
  [performers makeObjectsPerformSelector: @selector(invalidate)];
920
950
  [performers removeAllObjects];
921
 
  [lock unlock];
922
951
#ifdef __MINGW32__
923
952
  if (event != INVALID_HANDLE_VALUE)
924
953
    {
936
965
      outputFd = -1;
937
966
    }
938
967
#endif
 
968
  [lock unlock];
939
969
}
940
970
 
941
971
- (void) fire
944
974
  unsigned int  i;
945
975
  unsigned int  c;
946
976
 
 
977
  [lock lock];
947
978
#if defined(__MINGW32__)
948
979
  if (event != INVALID_HANDLE_VALUE)
949
980
    {
962
993
    }
963
994
#endif
964
995
 
965
 
  [lock lock];
966
996
  toDo = [NSArray arrayWithArray: performers];
967
997
  [performers removeAllObjects];
968
998
  [lock unlock];
989
1019
  if (aThread == nil)
990
1020
    {
991
1021
      aThread = GSCurrentThread();
992
 
      if (((NSThread_ivars*)aThread)->_runLoopInfo == nil)
993
 
        {
994
 
          ((NSThread_ivars*)aThread)->_runLoopInfo = [GSRunLoopThreadInfo new];
995
 
        }
 
1022
    }
 
1023
  if (((NSThread_ivars*)aThread)->_runLoopInfo == nil)
 
1024
    {
 
1025
      ((NSThread_ivars*)aThread)->_runLoopInfo = [GSRunLoopThreadInfo new];
996
1026
    }
997
1027
  info = ((NSThread_ivars*)aThread)->_runLoopInfo;
998
1028
  return info;
1092
1122
                       waitUntilDone: (BOOL)aFlag
1093
1123
                               modes: (NSArray*)anArray
1094
1124
{
 
1125
  /* It's possible that this method could be called before the NSThread
 
1126
   * class is initialised, so we check and make sure it's initiailised
 
1127
   * if necessary.
 
1128
   */
 
1129
  if (defaultThread == nil)
 
1130
    {
 
1131
      [NSThread currentThread];
 
1132
    }
1095
1133
  [self performSelector: aSelector
1096
1134
               onThread: defaultThread
1097
1135
             withObject: anObject