/[classpath]/classpath/native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
ViewVC logotype

Diff of /classpath/native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12.2.4 by gnu_andrew, Tue Aug 2 20:12:40 2005 UTC revision 1.12.2.5 by gnu_andrew, Sun Aug 7 18:34:12 2005 UTC
# Line 512  Java_gnu_java_nio_channels_FileChannelIm Line 512  Java_gnu_java_nio_channels_FileChannelIm
512  {  {
513  #ifdef HAVE_MMAP  #ifdef HAVE_MMAP
514    jclass MappedByteBufferImpl_class;    jclass MappedByteBufferImpl_class;
   jclass RawData_class;  
515    jmethodID MappedByteBufferImpl_init = NULL;    jmethodID MappedByteBufferImpl_init = NULL;
516    jmethodID RawData_init = NULL;    jobject Pointer_instance;
   jobject RawData_instance;  
517    volatile jobject buffer;    volatile jobject buffer;
518    long pagesize;    long pagesize;
519    int prot, flags;    int prot, flags;
# Line 535  Java_gnu_java_nio_channels_FileChannelIm Line 533  Java_gnu_java_nio_channels_FileChannelIm
533    return NULL;    return NULL;
534  #endif /* HAVE_GETPAGESIZE/HAVE_SYSCONF */  #endif /* HAVE_GETPAGESIZE/HAVE_SYSCONF */
535    
 #if (SIZEOF_VOID_P == 4)  
   RawData_class = (*env)->FindClass (env, "gnu/classpath/RawData32");  
   if (RawData_class != NULL)  
     {  
       RawData_init = (*env)->GetMethodID (env, RawData_class,  
                                           "<init>", "(I)V");  
     }  
 #elif (SIZEOF_VOID_P == 8)  
   RawData_class = (*env)->FindClass (env, "gnu/classpath/RawData64");  
   if (RawData_class != NULL)  
     {  
       RawData_init = (*env)->GetMethodID (env, RawData_class,  
                                           "<init>", "(J)V");  
     }  
 #else  
   JCL_ThrowException (env, IO_EXCEPTION,  
                       "pointer size not supported");  
   return NULL;  
 #endif /* SIZEOF_VOID_P */  
   
536    if ((*env)->ExceptionOccurred (env))    if ((*env)->ExceptionOccurred (env))
537      {      {
538        return NULL;        return NULL;
539      }      }
   if (RawData_init == NULL)  
     {  
       JCL_ThrowException (env, "java/lang/InternalError",  
                           "could not get RawData constructor");  
       return NULL;  
     }  
540    
541    prot = PROT_READ;    prot = PROT_READ;
542    if (mode == '+')    if (mode == '+')
# Line 583  Java_gnu_java_nio_channels_FileChannelIm Line 555  Java_gnu_java_nio_channels_FileChannelIm
555       down to a multiple of the page size. */       down to a multiple of the page size. */
556    address = (void *) ((char *) p + (position % pagesize));    address = (void *) ((char *) p + (position % pagesize));
557    
558  #if (SIZEOF_VOID_P == 4)    Pointer_instance = JCL_NewRawDataObject(env, address);
   RawData_instance = (*env)->NewObject (env, RawData_class,  
                                         RawData_init, (jint) address);  
 #elif (SIZEOF_VOID_P == 8)  
   RawData_instance = (*env)->NewObject (env, RawData_class,  
                                         RawData_init, (jlong) address);  
 #endif /* SIZEOF_VOID_P */  
559    
560    MappedByteBufferImpl_class = (*env)->FindClass (env,    MappedByteBufferImpl_class = (*env)->FindClass (env,
561                                                    "java/nio/MappedByteBufferImpl");                                                    "java/nio/MappedByteBufferImpl");
# Line 597  Java_gnu_java_nio_channels_FileChannelIm Line 563  Java_gnu_java_nio_channels_FileChannelIm
563      {      {
564        MappedByteBufferImpl_init =        MappedByteBufferImpl_init =
565          (*env)->GetMethodID (env, MappedByteBufferImpl_class,          (*env)->GetMethodID (env, MappedByteBufferImpl_class,
566                               "<init>", "(Lgnu/classpath/RawData;IZ)V");                               "<init>", "(Lgnu/classpath/Pointer;IZ)V");
567      }      }
568    
569    if ((*env)->ExceptionOccurred (env))    if ((*env)->ExceptionOccurred (env))
# Line 614  Java_gnu_java_nio_channels_FileChannelIm Line 580  Java_gnu_java_nio_channels_FileChannelIm
580      }      }
581    
582    buffer = (*env)->NewObject (env, MappedByteBufferImpl_class,    buffer = (*env)->NewObject (env, MappedByteBufferImpl_class,
583                                MappedByteBufferImpl_init, RawData_instance,                                MappedByteBufferImpl_init, Pointer_instance,
584                                (jint) size, mode == 'r');                                (jint) size, mode == 'r');
585    return buffer;    return buffer;
586  #else  #else
# Line 851  Java_gnu_java_nio_channels_FileChannelIm Line 817  Java_gnu_java_nio_channels_FileChannelIm
817    flock.l_type = shared ? F_RDLCK : F_WRLCK;    flock.l_type = shared ? F_RDLCK : F_WRLCK;
818    flock.l_whence = SEEK_SET;    flock.l_whence = SEEK_SET;
819    flock.l_start = (off_t) position;    flock.l_start = (off_t) position;
820    flock.l_len = (off_t) size;    /* Long.MAX_VALUE means lock everything possible starting at pos. */
821      if (size == 9223372036854775807LL)
822        flock.l_len = 0;
823      else
824        flock.l_len = (off_t) size;
825    
826    ret = fcntl (fd, cmd, &flock);    ret = fcntl (fd, cmd, &flock);
827      /* fprintf(stderr, "fd %d, wait %d, shared %d, ret %d, position %lld, size %lld, l_start %ld, l_len %ld\n", fd, wait, shared,ret, position, size, (long) flock.l_start, (long) flock.l_len); */
828    if (ret)    if (ret)
829      {      {
830        /* Linux man pages for fcntl state that errno might be either        /* Linux man pages for fcntl state that errno might be either
831           EACCES or EAGAIN if we try F_SETLK, and another process has           EACCES or EAGAIN if we try F_SETLK, and another process has
832           an overlapping lock. */           an overlapping lock. We should not get an unexpected errno. */
833        if (errno != EACCES && errno != EAGAIN)        if (errno != EACCES && errno != EAGAIN)
834          {          {
835            JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));            JCL_ThrowException (env, "java/lang/InternalError",
836                                  strerror (errno));
837          }          }
838        return JNI_FALSE;        return JNI_FALSE;
839      }      }
# Line 892  Java_gnu_java_nio_channels_FileChannelIm Line 864  Java_gnu_java_nio_channels_FileChannelIm
864    flock.l_type = F_UNLCK;    flock.l_type = F_UNLCK;
865    flock.l_whence = SEEK_SET;    flock.l_whence = SEEK_SET;
866    flock.l_start = (off_t) position;    flock.l_start = (off_t) position;
867    flock.l_len = (off_t) length;    /* Long.MAX_VALUE means unlock everything possible starting at pos. */
868      if (length == 9223372036854775807LL)
869        flock.l_len = 0;
870      else
871        flock.l_len = (off_t) length;
872    
873    ret = fcntl (fd, F_SETLK, &flock);    ret = fcntl (fd, F_SETLK, &flock);
874    if (ret)    if (ret)
875      {      {
876        JCL_ThrowException (env, IO_EXCEPTION, strerror (errno));        JCL_ThrowException (env, "java/lang/InternalError",
877                              strerror (errno));
878      }      }
879  #else  #else
880    (void) obj;    (void) obj;

Legend:
Removed from v.1.12.2.4  
changed lines
  Added in v.1.12.2.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26