spb/forge Public MIT
Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.
C++ 61.2%
C 23%
Python 7.6%
TeX 7.2%
CMake 1.1%
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Foundation/NSLock.hpp4//5// Copyright 2020-2024 Apple Inc.6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11// http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------202122#pragma once2324//-------------------------------------------------------------------------------------------------------------------------------------------------------------2526#include "NSDefines.hpp"27#include "NSObject.hpp"28#include "NSPrivate.hpp"29#include "NSTypes.hpp"30#include "NSDate.hpp"3132//-------------------------------------------------------------------------------------------------------------------------------------------------------------3334namespace NS35{3637template <class _Class, class _Base = class Object>38class Locking : public _Base39{40public:41 void lock();42 void unlock();43};4445class Condition : public Locking<Condition>46{47public:48 static Condition* alloc();4950 Condition* init();5152 void wait();53 bool waitUntilDate(Date* pLimit);54 void signal();55 void broadcast();56};5758} // NS5960//-------------------------------------------------------------------------------------------------------------------------------------------------------------6162template<class _Class, class _Base /* = NS::Object */>63_NS_INLINE void NS::Locking<_Class, _Base>::lock()64{65 NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(lock));66}6768//-------------------------------------------------------------------------------------------------------------------------------------------------------------6970template<class _Class, class _Base /* = NS::Object */>71_NS_INLINE void NS::Locking<_Class, _Base>::unlock()72{73 NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(unlock));74}7576//-------------------------------------------------------------------------------------------------------------------------------------------------------------7778_NS_INLINE NS::Condition* NS::Condition::alloc()79{80 return NS::Object::alloc<NS::Condition>(_NS_PRIVATE_CLS(NSCondition));81}8283//-------------------------------------------------------------------------------------------------------------------------------------------------------------8485_NS_INLINE NS::Condition* NS::Condition::init()86{87 return NS::Object::init<NS::Condition>();88}8990//-------------------------------------------------------------------------------------------------------------------------------------------------------------9192_NS_INLINE void NS::Condition::wait()93{94 NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(wait));95}9697//-------------------------------------------------------------------------------------------------------------------------------------------------------------9899_NS_INLINE bool NS::Condition::waitUntilDate(NS::Date* pLimit)100{101 return NS::Object::sendMessage<bool>(this, _NS_PRIVATE_SEL(waitUntilDate_), pLimit);102}103104//-------------------------------------------------------------------------------------------------------------------------------------------------------------105106_NS_INLINE void NS::Condition::signal()107{108 NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(signal));109}110111//-------------------------------------------------------------------------------------------------------------------------------------------------------------112113_NS_INLINE void NS::Condition::broadcast()114{115 NS::Object::sendMessage<void>(this, _NS_PRIVATE_SEL(broadcast));116}117118//-------------------------------------------------------------------------------------------------------------------------------------------------------------