/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <cstdlib>
#include <folly/Portability.h>
#include <mutex>
-#include <pthread.h>
#include <type_traits>
#include <glog/logging.h>
*/
void init(IntType initialValue = 0) {
CHECK(!(initialValue & kLockBitMask_));
- lock_ = initialValue;
+ lock_ = UIntType(initialValue);
}
/*
*/
void setData(IntType w) {
CHECK(!(w & kLockBitMask_));
- lock_ = (lock_ & kLockBitMask_) | w;
+ lock_ = UIntType((lock_ & kLockBitMask_) | w);
}
/*
switch (sizeof(IntType)) {
case 2:
// There is no _interlockedbittestandset16 for some reason :(
- ret = _InterlockedOr16((volatile short*)&lock, 1 << Bit) & (1 << Bit);
+ ret = _InterlockedOr16(
+ (volatile short*)&lock_, (short)kLockBitMask_) & kLockBitMask_;
break;
case 4:
ret = _interlockedbittestandset((volatile long*)&lock_, Bit);
switch (sizeof(IntType)) {
case 2:
// There is no _interlockedbittestandreset16 for some reason :(
- _InterlockedAnd16((volatile short*)&lock, ~(1 << Bit));
+ _InterlockedAnd16((volatile short*)&lock_, (short)~kLockBitMask_);
break;
case 4:
_interlockedbittestandreset((volatile long*)&lock_, Bit);