github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/runners/worker/crossplatform_unistd.h (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one
     3   * or more contributor license agreements.  See the NOTICE file
     4   * distributed with this work for additional information
     5   * regarding copyright ownership.  The ASF licenses this file
     6   * to you under the Apache License, Version 2.0 (the
     7   * "License"); you may not use this file except in compliance
     8   * with the License.  You may obtain a copy of the License at
     9   *
    10   *     http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  #ifndef BEAM_CROSSPLATFORM_UNISTD_H
    20  #define BEAM_CROSSPLATFORM_UNISTD_H
    21  
    22  #ifdef _WIN32
    23  #include <windows.h>
    24  
    25  /**
    26   * Alternative to POSIX usleep that may be run on Windows platform.
    27   */
    28  void usleep(__int64 usec) {
    29      HANDLE timer;
    30      LARGE_INTEGER timerDueTime;
    31  
    32      // Timer is measuring in 100 of nanoseconds, negative means relative
    33      timerDueTime.QuadPart = -(10 * usec);
    34  
    35      timer = CreateWaitableTimer(NULL, TRUE, NULL);
    36      SetWaitableTimer(timer, &timerDueTime, 0, NULL, NULL, 0);
    37      WaitForSingleObject(timer, INFINITE);
    38      CloseHandle(timer);
    39  }
    40  
    41  #else
    42  #include "unistd.h"
    43  #endif
    44  
    45  #endif //BEAM_CROSSPLATFORM_UNISTD_H