threading.h 1.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright (c) 2014 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef PYSTON_CORE_THREADING_H
#define PYSTON_CORE_THREADING_H

namespace pyston {
namespace threading {

Kevin Modzelewski's avatar
Kevin Modzelewski committed
21 22 23 24 25 26 27 28 29 30 31 32
#define THREADING_USE_GIL 1
#define THREADING_USE_GRWL 0
#define THREADING_SAFE_DATASTRUCTURES THREADING_USE_GRWL

void acquireGLRead();
void releaseGLRead();
void acquireGLWrite();
void releaseGLWrite();
// Note: promoteGL is free to drop the lock and then reacquire
void promoteGL();
void demoteGL();

33 34 35


#if THREADING_USE_GIL
Kevin Modzelewski's avatar
Kevin Modzelewski committed
36 37 38 39 40 41 42
inline void acquireGLRead() {
    acquireGLWrite();
}
inline void releaseGLRead() {
    releaseGLWrite();
}
inline void promoteGL() {
43
}
Kevin Modzelewski's avatar
Kevin Modzelewski committed
44
inline void demoteGL() {
45 46 47
}
#endif

Kevin Modzelewski's avatar
Kevin Modzelewski committed
48 49 50 51 52
#define MAKE_REGION(name, start, end) \
class name {\
public:\
    name() { start(); }\
    ~name() { end(); }\
53 54
};

Kevin Modzelewski's avatar
Kevin Modzelewski committed
55 56 57 58 59
MAKE_REGION(GLReadRegion, acquireGLRead, releaseGLRead);
MAKE_REGION(GLPromoteRegion, promoteGL, demoteGL);
MAKE_REGION(GLReadReleaseRegion, releaseGLRead, acquireGLRead);
MAKE_REGION(GLWriteReleaseRegion, releaseGLWrite, acquireGLWrite);
#undef MAKE_REGION
60 61 62 63 64

} // namespace threading
} // namespace pyston

#endif